10
from turbogears import testutil
14
from loggerhead.controllers import Root
10
from configobj import ConfigObj
12
from loggerhead.history import History
13
from loggerhead.apps.branch import BranchWSGIApp
14
from paste.fixture import TestApp
17
def test_config_root():
18
from loggerhead.apps.config import Root
17
19
config = ConfigObj()
20
testutil.create_request('/')
21
assert 'loggerhead branches' in cherrypy.response.body[0]
20
app = TestApp(Root(config))
22
res.mustcontain('loggerhead branches')
24
25
class BasicTests(object):
53
54
def setUpLoggerhead(self):
54
ini = self.config_template%dict(branch=self.bzrbranch)
56
config = ConfigObj(ini.splitlines())
57
cherrypy.root = Root(config)
55
app = TestApp(BranchWSGIApp(self.branch).app)
59
58
def tearDown(self):
60
59
if self.bzrbranch is not None:
61
60
shutil.rmtree(self.bzrbranch)
62
61
bzrlib.osutils.set_or_unset_env('BZR_HOME', self.old_bzrhome)
64
64
class TestWithSimpleTree(BasicTests):
79
79
self.msg = 'a very exciting commit message <'
80
80
self.revid = self.tree.commit(message=self.msg)
82
self.setUpLoggerhead()
85
testutil.create_request('/')
86
link = '<a href="/project/branch">branch</a>'
87
assert link in cherrypy.response.body[0].lower()
89
83
def test_changes(self):
90
testutil.create_request('/project/branch/changes')
91
assert cgi.escape(self.msg) in cherrypy.response.body[0]
84
app = self.setUpLoggerhead()
85
res = app.get('/changes')
86
res.mustcontain(cgi.escape(self.msg))
93
88
def test_changes_search(self):
94
testutil.create_request('/project/branch/changes?q=foo')
95
assert 'Sorry, no results found for your search.' in cherrypy.response.body[0]
89
app = self.setUpLoggerhead()
90
res = app.get('/changes', params={'q': 'foo'})
91
res.mustcontain('Sorry, no results found for your search.')
97
93
def test_annotate(self):
98
testutil.create_request('/project/branch/annotate?'
99
+ 'file_id='+self.fileid)
94
app = self.setUpLoggerhead()
95
res = app.get('/annotate', params={'file_id':self.fileid})
100
96
for line in self.filecontents.splitlines():
101
assert cgi.escape(line) in cherrypy.response.body[0]
97
res.mustcontain(cgi.escape(line))
103
99
def test_inventory(self):
104
testutil.create_request('/project/branch/files')
105
assert 'myfilename' in cherrypy.response.body[0]
100
app = self.setUpLoggerhead()
101
res = app.get('/files')
102
res.mustcontain('myfilename')
107
104
def test_revision(self):
108
testutil.create_request('/project/branch/revision/' + self.revid)
109
assert 'myfilename' in cherrypy.response.body[0]
105
app = self.setUpLoggerhead()
106
res = app.get('/revision/1')
107
res.mustcontain('myfilename')
111
class TestWithSimpleTreeAndCache(TestWithSimpleTree):
112
config_template = """
116
branch_name = 'branch'
117
folder = '%(branch)s'
118
cachepath = '%(branch)s/cache'
121
110
class TestEmptyBranch(BasicTests):
124
113
BasicTests.setUp(self)
125
114
self.createBranch()
126
self.setUpLoggerhead()
128
def test_index(self):
129
testutil.create_request('/')
130
link = '<a href="/project/branch">branch</a>'
131
assert link in cherrypy.response.body[0].lower()
133
116
def test_changes(self):
134
testutil.create_request('/project/branch/changes')
135
assert 'No revisions!' in cherrypy.response.body[0]
137
class TestEmptyBranchWithCache(TestEmptyBranch):
138
config_template = """
142
branch_name = 'branch'
143
folder = '%(branch)s'
144
cachepath = '%(branch)s/cache'
117
app = self.setUpLoggerhead()
118
res = app.get('/changes')
119
res.mustcontain('No revisions!')