9
from bzrlib.util.configobj import ConfigObj
11
from loggerhead.apps.branch import BranchWSGIApp
12
from paste.fixture import TestApp
15
def test_config_root():
16
from loggerhead.apps.config import Root
18
app = TestApp(Root(config))
20
res.mustcontain('loggerhead branches')
23
class BasicTests(object):
25
# setup_method and teardown_method are so i can run the tests with
26
# py.test and take advantage of the error reporting.
28
def setup_method(self, meth):
31
def teardown_method(self, meth):
35
logging.basicConfig(level=logging.DEBUG)
37
self.old_bzrhome = None
39
def createBranch(self):
40
self.old_bzrhome = bzrlib.osutils.set_or_unset_env('BZR_HOME', '')
41
self.bzrbranch = tempfile.mkdtemp()
42
self.branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
43
self.bzrbranch, force_new_tree=True)
44
self.tree = self.branch.bzrdir.open_workingtree()
49
branch_name = 'branch'
53
def setUpLoggerhead(self):
54
app = TestApp(BranchWSGIApp(self.branch, '').app)
58
if self.bzrbranch is not None:
59
shutil.rmtree(self.bzrbranch)
60
bzrlib.osutils.set_or_unset_env('BZR_HOME', self.old_bzrhome)
63
class TestWithSimpleTree(BasicTests):
66
BasicTests.setUp(self)
69
f = open(os.path.join(self.bzrbranch, 'myfilename'), 'w')
70
self.filecontents = ('some\nmultiline\ndata\n'
71
'with<htmlspecialchars\n')
73
f.write(self.filecontents)
76
self.tree.add('myfilename')
77
self.fileid = self.tree.path2id('myfilename')
78
self.msg = 'a very exciting commit message <'
79
self.revid = self.tree.commit(message=self.msg)
81
def test_changes(self):
82
app = self.setUpLoggerhead()
83
res = app.get('/changes')
84
res.mustcontain(cgi.escape(self.msg))
86
def test_changes_search(self):
87
app = self.setUpLoggerhead()
88
res = app.get('/changes', params={'q': 'foo'})
89
res.mustcontain('Sorry, no results found for your search.')
91
def test_annotate(self):
92
app = self.setUpLoggerhead()
93
res = app.get('/annotate', params={'file_id': self.fileid})
94
for line in self.filecontents.splitlines():
95
res.mustcontain(cgi.escape(line))
97
def test_inventory(self):
98
app = self.setUpLoggerhead()
99
res = app.get('/files')
100
res.mustcontain('myfilename')
102
def test_revision(self):
103
app = self.setUpLoggerhead()
104
res = app.get('/revision/1')
105
res.mustcontain('myfilename')
108
class TestEmptyBranch(BasicTests):
111
BasicTests.setUp(self)
114
def test_changes(self):
115
app = self.setUpLoggerhead()
116
res = app.get('/changes')
117
res.mustcontain('No revisions!')