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
|
import cgi
import os
import tempfile
import shutil
import logging
import bzrlib.bzrdir
import bzrlib.osutils
from bzrlib.tests import TestCaseWithTransport
from bzrlib.util.configobj.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(TestCaseWithTransport):
def setUp(self):
TestCaseWithTransport.setUp(self)
logging.basicConfig(level=logging.ERROR)
logging.getLogger('bzr').setLevel(logging.CRITICAL)
def createBranch(self):
self.tree = self.make_branch_and_tree('.')
def setUpLoggerhead(self):
app = TestApp(BranchWSGIApp(self.tree.branch, '').app)
return app
class TestWithSimpleTree(BasicTests):
def setUp(self):
BasicTests.setUp(self)
self.createBranch()
self.filecontents = ('some\nmultiline\ndata\n'
'with<htmlspecialchars\n')
self.build_tree_contents(
[('myfilename', self.filecontents)])
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!')
def test_inventory(self):
app = self.setUpLoggerhead()
res = app.get('/files')
res.mustcontain('No revisions!')
|