~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_controllers.py

  • Committer: Ian Clatworthy
  • Date: 2010-04-23 00:02:29 UTC
  • mfrom: (407.1.2 loggerhead)
  • Revision ID: ian.clatworthy@canonical.com-20100423000229-ysxj7lzkx6oklt35
Skip syntax highlighting on files over 512K

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
 
 
8
1
from loggerhead.apps.branch import BranchWSGIApp
9
2
from loggerhead.controllers.annotate_ui import AnnotateUI
10
3
from loggerhead.controllers.inventory_ui import InventoryUI
22
15
        tree.commit('')
23
16
        tree.branch.lock_read()
24
17
        self.addCleanup(tree.branch.unlock)
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 = '/'
 
18
        branch_app = BranchWSGIApp(tree.branch)
31
19
        return tree.branch, InventoryUI(branch_app, branch_app.get_history)
32
20
 
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
 
 
46
21
    def test_get_filelist(self):
47
22
        bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
48
23
            ['filename'])
49
24
        inv = bzrbranch.repository.get_inventory(bzrbranch.last_revision())
50
 
        self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename', 'head')))
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)
 
25
        self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename')))
68
26
 
69
27
 
70
28
class TestRevisionUI(BasicTests):
103
61
 
104
62
    def make_annotate_ui_for_file_history(self, file_id, rev_ids_texts):
105
63
        tree = self.make_branch_and_tree('.')
106
 
        self.build_tree_contents([('filename', '')])
 
64
        open('filename', 'w').write('')
107
65
        tree.add(['filename'], [file_id])
108
66
        for rev_id, text in rev_ids_texts:
109
 
            self.build_tree_contents([('filename', text)])
 
67
            open('filename', 'w').write(text)
110
68
            tree.commit(rev_id=rev_id, message='.')
111
69
        tree.branch.lock_read()
112
70
        self.addCleanup(tree.branch.unlock)
113
 
        branch_app = BranchWSGIApp(tree.branch, friendly_name='test_name')
 
71
        branch_app = BranchWSGIApp(tree.branch)
114
72
        return AnnotateUI(branch_app, branch_app.get_history)
115
73
 
116
74
    def test_annotate_file(self):
117
75
        history = [('rev1', 'old\nold\n'), ('rev2', 'new\nold\n')]
118
76
        ann_ui = self.make_annotate_ui_for_file_history('file_id', history)
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'])
 
77
        annotated = list(ann_ui.annotate_file('file_id', 'rev2'))
125
78
        self.assertEqual(2, len(annotated))
126
79
        self.assertEqual('2', annotated[0].change.revno)
127
80
        self.assertEqual('1', annotated[1].change.revno)