1
# Copyright (C) 2008, 2009 Canonical Ltd.
1
# Copyright (C) 2007, 2008, 2009, 2011 Canonical Ltd.
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
22
from bzrlib.tests import TestCaseWithTransport
22
from bzrlib.util.configobj.configobj import ConfigObj
24
from bzrlib.util.configobj.configobj import ConfigObj
26
from configobj import ConfigObj
23
27
from bzrlib import config
25
29
from loggerhead.apps.branch import BranchWSGIApp
30
from loggerhead.apps.http_head import HeadMiddleware
26
31
from paste.fixture import TestApp
27
from paste.httpexceptions import HTTPExceptionHandler
31
def test_config_root():
32
from loggerhead.apps.config import Root
34
app = TestApp(HTTPExceptionHandler(Root(config)))
36
res.mustcontain('loggerhead branches')
32
from paste.httpexceptions import HTTPExceptionHandler, HTTPMovedPermanently
39
36
class BasicTests(TestCaseWithTransport):
61
58
'with<htmlspecialchars\n')
62
59
self.build_tree_contents(
63
60
[('myfilename', self.filecontents)])
64
self.tree.add('myfilename')
61
self.tree.add('myfilename', 'myfile-id')
65
62
self.fileid = self.tree.path2id('myfilename')
66
63
self.msg = 'a very exciting commit message <'
67
64
self.revid = self.tree.commit(message=self.msg)
71
68
res = app.get('/changes')
72
69
res.mustcontain(cgi.escape(self.msg))
71
def test_changes_for_file(self):
72
app = self.setUpLoggerhead()
73
res = app.get('/changes?filter_file_id=myfile-id')
74
res.mustcontain(cgi.escape(self.msg))
74
76
def test_changes_branch_from(self):
75
77
app = self.setUpLoggerhead(served_url="lp:loggerhead")
76
78
res = app.get('/changes')
88
90
def test_annotate(self):
89
91
app = self.setUpLoggerhead()
90
92
res = app.get('/annotate', params={'file_id': self.fileid})
93
# If pygments is installed, it inserts <span class="pyg" content into
94
# the output, to trigger highlighting. And it specifically highlights
95
# the < that we are interested in seeing in the output.
96
# Without pygments we have a simple: 'with<htmlspecialchars'
98
# '<span class='pyg-n'>with</span><span class='pyg-o'><</span>'
99
# '<span class='pyg-n'>htmlspecialchars</span>
100
# So we pre-filter the body, to make sure remove spans of that type.
101
body_no_span = re.sub(r'<span class="pyg-.">', '', res.body)
102
body_no_span = body_no_span.replace('</span>', '')
91
103
for line in self.filecontents.splitlines():
92
res.mustcontain(cgi.escape(line))
104
escaped = cgi.escape(line)
105
self.assertTrue(escaped in body_no_span,
106
"did not find %r in %r" % (escaped, body_no_span))
94
108
def test_inventory(self):
95
109
app = self.setUpLoggerhead()
157
171
res = app.get('/changes', status=404)
174
class TestControllerRedirects(BasicTests):
176
Test that a file under /files redirects to /view,
177
and a directory under /view redirects to /files.
181
BasicTests.setUp(self)
183
self.build_tree(('file', 'folder/', 'folder/file'))
184
self.tree.smart_add([])
187
def test_view_folder(self):
188
app = TestApp(BranchWSGIApp(self.tree.branch, '').app)
190
e = self.assertRaises(HTTPMovedPermanently, app.get, '/view/head:/folder')
191
self.assertEqual(e.location(), '/files/head:/folder')
193
def test_files_file(self):
194
app = TestApp(BranchWSGIApp(self.tree.branch, '').app)
196
e = self.assertRaises(HTTPMovedPermanently, app.get, '/files/head:/folder/file')
197
self.assertEqual(e.location(), '/view/head:/folder/file')
198
e = self.assertRaises(HTTPMovedPermanently, app.get, '/files/head:/file')
199
self.assertEqual(e.location(), '/view/head:/file')
202
class TestHeadMiddleware(BasicTests):
205
BasicTests.setUp(self)
207
self.msg = 'trivial commit message'
208
self.revid = self.tree.commit(message=self.msg)
210
def setUpLoggerhead(self, **kw):
211
branch_app = BranchWSGIApp(self.tree.branch, '', **kw).app
212
return TestApp(HTTPExceptionHandler(HeadMiddleware(branch_app)))
215
app = self.setUpLoggerhead()
216
res = app.get('/changes')
217
res.mustcontain(self.msg)
218
self.assertEqual('text/html', res.header('Content-Type'))
221
app = self.setUpLoggerhead()
222
res = app.get('/changes', extra_environ={'REQUEST_METHOD': 'HEAD'})
223
self.assertEqual('text/html', res.header('Content-Type'))
224
self.assertEqualDiff('', res.body)
160
227
#class TestGlobalConfig(BasicTests):
162
229
# Test that global config settings are respected