1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
import cgi
import os
import tempfile
import shutil
import logging
import bzrlib.bzrdir
import bzrlib.osutils
from configobj import ConfigObj
from loggerhead.apps.branch import BranchWSGIApp
from paste.fixture import TestApp
def test_config_root():
from loggerhead.apps.config import Root
config = ConfigObj()
app = TestApp(Root(config))
res = app.get('/')
res.mustcontain('loggerhead branches')
class BasicTests(object):
# setup_method and teardown_method are so i can run the tests with
# py.test and take advantage of the error reporting.
def setup_method(self, meth):
self.setUp()
def teardown_method(self, meth):
self.tearDown()
def setUp(self):
logging.basicConfig(level=logging.DEBUG)
self.bzrbranch = None
self.old_bzrhome = None
def createBranch(self):
self.old_bzrhome = bzrlib.osutils.set_or_unset_env('BZR_HOME', '')
self.bzrbranch = tempfile.mkdtemp()
self.branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
self.bzrbranch, force_new_tree=True)
self.tree = self.branch.bzrdir.open_workingtree()
config_template = """
[project]
[[branch]]
branch_name = 'branch'
folder = '%(branch)s'
"""
def setUpLoggerhead(self):
app = TestApp(BranchWSGIApp(self.branch, '').app)
return app
def tearDown(self):
if self.bzrbranch is not None:
shutil.rmtree(self.bzrbranch)
bzrlib.osutils.set_or_unset_env('BZR_HOME', self.old_bzrhome)
class TestWithSimpleTree(BasicTests):
def setUp(self):
BasicTests.setUp(self)
self.createBranch()
f = open(os.path.join(self.bzrbranch, 'myfilename'), 'w')
self.filecontents = ('some\nmultiline\ndata\n'
'with<htmlspecialchars\n')
try:
f.write(self.filecontents)
finally:
f.close()
self.tree.add('myfilename')
self.fileid = self.tree.path2id('myfilename')
self.msg = 'a very exciting commit message <'
self.revid = self.tree.commit(message=self.msg)
def test_changes(self):
app = self.setUpLoggerhead()
res = app.get('/changes')
res.mustcontain(cgi.escape(self.msg))
def test_changes_search(self):
app = self.setUpLoggerhead()
res = app.get('/changes', params={'q': 'foo'})
res.mustcontain('Sorry, no results found for your search.')
def test_annotate(self):
app = self.setUpLoggerhead()
res = app.get('/annotate', params={'file_id':self.fileid})
for line in self.filecontents.splitlines():
res.mustcontain(cgi.escape(line))
def test_inventory(self):
app = self.setUpLoggerhead()
res = app.get('/files')
res.mustcontain('myfilename')
def test_revision(self):
app = self.setUpLoggerhead()
res = app.get('/revision/1')
res.mustcontain('myfilename')
class TestEmptyBranch(BasicTests):
def setUp(self):
BasicTests.setUp(self)
self.createBranch()
def test_changes(self):
app = self.setUpLoggerhead()
res = app.get('/changes')
res.mustcontain('No revisions!')
|