1
from configobj import ConfigObj
10
from turbogears import testutil
14
from loggerhead.controllers import Root
20
testutil.create_request('/')
21
assert 'loggerhead branches' in cherrypy.response.body[0]
24
class BasicTests(object):
27
# there are so i can run it with py.test and take advantage of the
29
def setup_method(self, meth):
32
def teardown_method(self, meth):
36
#logging.basicConfig(level=logging.DEBUG)
38
self.old_bzrhome = None
40
def createBranch(self):
41
self.old_bzrhome = bzrlib.osutils.set_or_unset_env('BZR_HOME', '')
42
self.bzrbranch = tempfile.mkdtemp()
43
self.branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
44
self.bzrbranch, force_new_tree=True)
45
self.tree = self.branch.bzrdir.open_workingtree()
50
branch_name = 'branch'
54
def setUpLoggerhead(self):
55
ini = self.config_template%dict(branch=self.bzrbranch)
57
config = ConfigObj(ini.splitlines())
58
cherrypy.root = Root(config)
61
if self.bzrbranch is not None:
62
shutil.rmtree(self.bzrbranch)
63
bzrlib.osutils.set_or_unset_env('BZR_HOME', self.old_bzrhome)
65
class TestWithSimpleTree(BasicTests):
68
BasicTests.setUp(self)
71
f = open(os.path.join(self.bzrbranch, 'myfilename'), 'w')
72
self.filecontents = ('some\nmultiline\ndata\n'
73
'with<htmlspecialchars\n')
75
f.write(self.filecontents)
78
self.tree.add('myfilename')
79
self.fileid = self.tree.path2id('myfilename')
80
self.msg = 'a very exciting commit message <'
81
self.revid = self.tree.commit(message=self.msg)
83
self.setUpLoggerhead()
86
testutil.create_request('/')
87
link = '<a href="/project/branch">branch</a>'
88
assert link in cherrypy.response.body[0]
90
def test_changes(self):
91
testutil.create_request('/project/branch/changes')
92
assert cgi.escape(self.msg) in cherrypy.response.body[0]
94
def test_changes_search(self):
95
testutil.create_request('/project/branch/changes?q=foo')
96
assert 'Sorry, no results found for your search.' in cherrypy.response.body[0]
98
def test_annotate(self):
99
testutil.create_request('/project/branch/annotate?'
100
+ 'file_id='+self.fileid)
101
for line in self.filecontents.splitlines():
102
assert cgi.escape(line) in cherrypy.response.body[0]
104
def test_inventory(self):
105
testutil.create_request('/project/branch/files')
106
assert 'myfilename' in cherrypy.response.body[0]
108
def test_revision(self):
109
testutil.create_request('/project/branch/revision/' + self.revid)
110
assert 'myfilename' in cherrypy.response.body[0]
112
class TestWithSimpleTreeAndCache(TestWithSimpleTree):
113
config_template = """
117
branch_name = 'branch'
118
folder = '%(branch)s'
119
cachepath = '%(branch)s/cache'
122
class TestEmptyBranch(BasicTests):
125
BasicTests.setUp(self)
127
self.setUpLoggerhead()
129
def test_index(self):
130
testutil.create_request('/')
131
link = '<a href="/project/branch">branch</a>'
132
assert link in cherrypy.response.body[0]
134
def test_changes(self):
135
testutil.create_request('/project/branch/changes')
136
assert 'No revisions!' in cherrypy.response.body[0]
138
class TestEmptyBranchWithCache(TestEmptyBranch):
139
config_template = """
143
branch_name = 'branch'
144
folder = '%(branch)s'
145
cachepath = '%(branch)s/cache'