~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_controllers.py

  • Committer: razamatan
  • Date: 2011-02-17 19:51:25 UTC
  • mto: This revision was merged to the branch mainline in revision 431.
  • Revision ID: razamatan@retral.net-20110217195125-hy625rem0zwx6mnw
explicit favicons

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from cStringIO import StringIO
 
2
import logging
 
3
 
 
4
from paste.httpexceptions import HTTPServerError
 
5
 
 
6
from bzrlib import errors
 
7
 
1
8
from loggerhead.apps.branch import BranchWSGIApp
2
9
from loggerhead.controllers.annotate_ui import AnnotateUI
3
10
from loggerhead.controllers.inventory_ui import InventoryUI
15
22
        tree.commit('')
16
23
        tree.branch.lock_read()
17
24
        self.addCleanup(tree.branch.unlock)
18
 
        branch_app = BranchWSGIApp(tree.branch)
 
25
        branch_app = BranchWSGIApp(tree.branch, '')
 
26
        branch_app.log.setLevel(logging.CRITICAL)
 
27
        # These are usually set in BranchWSGIApp.app(), which is set from env
 
28
        # settings set by BranchesFromTransportRoot, so we fake it.
 
29
        branch_app._static_url_base = '/'
 
30
        branch_app._url_base = '/'
19
31
        return tree.branch, InventoryUI(branch_app, branch_app.get_history)
20
32
 
 
33
    def consume_app(self, app, extra_environ=None):
 
34
        env = {'SCRIPT_NAME': '/files', 'PATH_INFO': ''}
 
35
        if extra_environ is not None:
 
36
            env.update(extra_environ)
 
37
        body = StringIO()
 
38
        start = []
 
39
        def start_response(status, headers, exc_info=None):
 
40
            start.append((status, headers, exc_info))
 
41
            return body.write
 
42
        extra_content = list(app(env, start_response))
 
43
        body.writelines(extra_content)
 
44
        return start[0], body.getvalue()
 
45
 
21
46
    def test_get_filelist(self):
22
47
        bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
23
48
            ['filename'])
24
49
        inv = bzrbranch.repository.get_inventory(bzrbranch.last_revision())
25
50
        self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename')))
26
51
 
 
52
    def test_smoke(self):
 
53
        bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
 
54
            ['filename'])
 
55
        start, content = self.consume_app(inv_ui)
 
56
        self.assertEqual(('200 OK', [('Content-Type', 'text/html')], None),
 
57
                         start)
 
58
        self.assertContainsRe(content, 'filename')
 
59
 
 
60
    def test_no_content_for_HEAD(self):
 
61
        bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
 
62
            ['filename'])
 
63
        start, content = self.consume_app(inv_ui,
 
64
                            extra_environ={'REQUEST_METHOD': 'HEAD'})
 
65
        self.assertEqual(('200 OK', [('Content-Type', 'text/html')], None),
 
66
                         start)
 
67
        self.assertEqual('', content)
 
68
 
27
69
 
28
70
class TestRevisionUI(BasicTests):
29
71
 
61
103
 
62
104
    def make_annotate_ui_for_file_history(self, file_id, rev_ids_texts):
63
105
        tree = self.make_branch_and_tree('.')
64
 
        open('filename', 'w').write('')
 
106
        self.build_tree_contents([('filename', '')])
65
107
        tree.add(['filename'], [file_id])
66
108
        for rev_id, text in rev_ids_texts:
67
 
            open('filename', 'w').write(text)
 
109
            self.build_tree_contents([('filename', text)])
68
110
            tree.commit(rev_id=rev_id, message='.')
69
111
        tree.branch.lock_read()
70
112
        self.addCleanup(tree.branch.unlock)
71
 
        branch_app = BranchWSGIApp(tree.branch)
 
113
        branch_app = BranchWSGIApp(tree.branch, friendly_name='test_name')
72
114
        return AnnotateUI(branch_app, branch_app.get_history)
73
115
 
74
116
    def test_annotate_file(self):
75
117
        history = [('rev1', 'old\nold\n'), ('rev2', 'new\nold\n')]
76
118
        ann_ui = self.make_annotate_ui_for_file_history('file_id', history)
77
 
        annotated = list(ann_ui.annotate_file('file_id', 'rev2'))
 
119
        # A lot of this state is set up by __call__, but we'll do it directly
 
120
        # here.
 
121
        ann_ui.args = ['rev2']
 
122
        annotate_info = ann_ui.get_values('filename',
 
123
            kwargs={'file_id': 'file_id'}, headers={})
 
124
        annotated = list(annotate_info['annotated'])
78
125
        self.assertEqual(2, len(annotated))
79
126
        self.assertEqual('2', annotated[0].change.revno)
80
127
        self.assertEqual('1', annotated[1].change.revno)