~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_simple.py

  • Committer: Jelmer Vernooij
  • Date: 2011-02-10 17:21:19 UTC
  • mfrom: (423.1.1 drop-pre-1.16)
  • Revision ID: jelmer@samba.org-20110210172119-6xa7yiq773p5fqcb
Merge dropping of workarounds for pre-1.16 versions of Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008, 2009, 2011 Canonical Ltd.
 
1
# Copyright (C) 2008, 2009 Canonical Ltd.
2
2
#
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
17
17
 
18
18
import cgi
19
19
import logging
20
 
import re
21
20
 
22
21
from bzrlib.tests import TestCaseWithTransport
23
 
try:
24
 
    from bzrlib.util.configobj.configobj import ConfigObj
25
 
except ImportError:
26
 
    from configobj import ConfigObj
 
22
from bzrlib.util.configobj.configobj import ConfigObj
27
23
from bzrlib import config
28
24
 
29
25
from loggerhead.apps.branch import BranchWSGIApp
30
 
from loggerhead.apps.http_head import HeadMiddleware
31
26
from paste.fixture import TestApp
32
 
from paste.httpexceptions import HTTPExceptionHandler, HTTPMovedPermanently
33
 
 
 
27
from paste.httpexceptions import HTTPExceptionHandler
 
28
 
 
29
 
 
30
 
 
31
def test_config_root():
 
32
    from loggerhead.apps.config import Root
 
33
    config = ConfigObj()
 
34
    app = TestApp(HTTPExceptionHandler(Root(config)))
 
35
    res = app.get('/')
 
36
    res.mustcontain('loggerhead branches')
34
37
 
35
38
 
36
39
class BasicTests(TestCaseWithTransport):
56
59
 
57
60
        self.filecontents = ('some\nmultiline\ndata\n'
58
61
                             'with<htmlspecialchars\n')
59
 
        filenames = ['myfilename', 'anotherfile<']
60
62
        self.build_tree_contents(
61
 
            (filename, self.filecontents) for filename in filenames)
62
 
        for filename in filenames:
63
 
            self.tree.add(filename, '%s-id' % filename)
 
63
            [('myfilename', self.filecontents)])
 
64
        self.tree.add('myfilename')
64
65
        self.fileid = self.tree.path2id('myfilename')
65
66
        self.msg = 'a very exciting commit message <'
66
67
        self.revid = self.tree.commit(message=self.msg)
70
71
        res = app.get('/changes')
71
72
        res.mustcontain(cgi.escape(self.msg))
72
73
 
73
 
    def test_changes_for_file(self):
74
 
        app = self.setUpLoggerhead()
75
 
        res = app.get('/changes?filter_file_id=myfilename-id')
76
 
        res.mustcontain(cgi.escape(self.msg))
77
 
 
78
74
    def test_changes_branch_from(self):
79
75
        app = self.setUpLoggerhead(served_url="lp:loggerhead")
80
76
        res = app.get('/changes')
92
88
    def test_annotate(self):
93
89
        app = self.setUpLoggerhead()
94
90
        res = app.get('/annotate', params={'file_id': self.fileid})
95
 
        # If pygments is installed, it inserts <span class="pyg" content into
96
 
        # the output, to trigger highlighting. And it specifically highlights
97
 
        # the &lt; that we are interested in seeing in the output.
98
 
        # Without pygments we have a simple: 'with&lt;htmlspecialchars'
99
 
        # With it, we have
100
 
        # '<span class='pyg-n'>with</span><span class='pyg-o'>&lt;</span>'
101
 
        # '<span class='pyg-n'>htmlspecialchars</span>
102
 
        # So we pre-filter the body, to make sure remove spans of that type.
103
 
        body_no_span = re.sub(r'<span class="pyg-.">', '', res.body)
104
 
        body_no_span = body_no_span.replace('</span>', '')
105
91
        for line in self.filecontents.splitlines():
106
 
            escaped = cgi.escape(line)
107
 
            self.assertTrue(escaped in body_no_span,
108
 
                            "did not find %r in %r" % (escaped, body_no_span))
 
92
            res.mustcontain(cgi.escape(line))
109
93
 
110
94
    def test_inventory(self):
111
95
        app = self.setUpLoggerhead()
133
117
    def test_revision(self):
134
118
        app = self.setUpLoggerhead()
135
119
        res = app.get('/revision/1')
136
 
        res.mustcontain(no=['anotherfile<'])
137
 
        res.mustcontain('anotherfile&lt;')
138
120
        res.mustcontain('myfilename')
139
121
 
140
122
 
175
157
        res = app.get('/changes', status=404)
176
158
 
177
159
 
178
 
class TestControllerRedirects(BasicTests):
179
 
    """
180
 
    Test that a file under /files redirects to /view,
181
 
    and a directory under /view redirects to /files.
182
 
    """
183
 
 
184
 
    def setUp(self):
185
 
        BasicTests.setUp(self)
186
 
        self.createBranch()
187
 
        self.build_tree(('file', 'folder/', 'folder/file'))
188
 
        self.tree.smart_add([])
189
 
        self.tree.commit('')
190
 
 
191
 
    def test_view_folder(self):
192
 
        app = TestApp(BranchWSGIApp(self.tree.branch, '').app)
193
 
 
194
 
        e = self.assertRaises(HTTPMovedPermanently, app.get, '/view/head:/folder')
195
 
        self.assertEqual(e.location(), '/files/head:/folder')
196
 
 
197
 
    def test_files_file(self):
198
 
        app = TestApp(BranchWSGIApp(self.tree.branch, '').app)
199
 
 
200
 
        e = self.assertRaises(HTTPMovedPermanently, app.get, '/files/head:/folder/file')
201
 
        self.assertEqual(e.location(), '/view/head:/folder/file')
202
 
        e = self.assertRaises(HTTPMovedPermanently, app.get, '/files/head:/file')
203
 
        self.assertEqual(e.location(), '/view/head:/file')
204
 
 
205
 
 
206
 
class TestHeadMiddleware(BasicTests):
207
 
 
208
 
    def setUp(self):
209
 
        BasicTests.setUp(self)
210
 
        self.createBranch()
211
 
        self.msg = 'trivial commit message'
212
 
        self.revid = self.tree.commit(message=self.msg)
213
 
 
214
 
    def setUpLoggerhead(self, **kw):
215
 
        branch_app = BranchWSGIApp(self.tree.branch, '', **kw).app
216
 
        return TestApp(HTTPExceptionHandler(HeadMiddleware(branch_app)))
217
 
 
218
 
    def test_get(self):
219
 
        app = self.setUpLoggerhead()
220
 
        res = app.get('/changes')
221
 
        res.mustcontain(self.msg)
222
 
        self.assertEqual('text/html', res.header('Content-Type'))
223
 
 
224
 
    def test_head(self):
225
 
        app = self.setUpLoggerhead()
226
 
        res = app.get('/changes', extra_environ={'REQUEST_METHOD': 'HEAD'})
227
 
        self.assertEqual('text/html', res.header('Content-Type'))
228
 
        self.assertEqualDiff('', res.body)
229
 
 
230
 
 
231
160
#class TestGlobalConfig(BasicTests):
232
161
#    """
233
162
#    Test that global config settings are respected