~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_controllers.py

  • Committer: Michael Hudson
  • Date: 2009-03-16 23:01:40 UTC
  • Revision ID: michael.hudson@canonical.com-20090316230140-ydm0xm0jghg6v5dq
it seems that double url-encoding the revid we put in the +revlog url is
necessary to avoid assorted bits of cleverness in random toolchains.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from loggerhead.apps.branch import BranchWSGIApp
 
2
from loggerhead.controllers.annotate_ui import AnnotateUI
 
3
from loggerhead.controllers.inventory_ui import InventoryUI
 
4
from loggerhead.controllers.revision_ui import RevisionUI
 
5
from loggerhead.tests.test_simple import BasicTests
 
6
from loggerhead import util
 
7
 
 
8
 
 
9
class TestInventoryUI(BasicTests):
 
10
 
 
11
    def make_bzrbranch_and_inventory_ui_for_tree_shape(self, shape):
 
12
        tree = self.make_branch_and_tree('.')
 
13
        self.build_tree(shape)
 
14
        tree.smart_add([])
 
15
        tree.commit('')
 
16
        tree.branch.lock_read()
 
17
        self.addCleanup(tree.branch.unlock)
 
18
        branch_app = BranchWSGIApp(tree.branch)
 
19
        return tree.branch, InventoryUI(branch_app, branch_app.get_history)
 
20
 
 
21
    def test_get_filelist(self):
 
22
        bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
 
23
            ['filename'])
 
24
        inv = bzrbranch.repository.get_inventory(bzrbranch.last_revision())
 
25
        self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename')))
 
26
 
 
27
 
 
28
class TestRevisionUI(BasicTests):
 
29
 
 
30
    def make_bzrbranch_and_revision_ui_for_tree_shapes(self, shape1, shape2):
 
31
        tree = self.make_branch_and_tree('.')
 
32
        self.build_tree_contents(shape1)
 
33
        tree.smart_add([])
 
34
        tree.commit('')
 
35
        self.build_tree_contents(shape2)
 
36
        tree.smart_add([])
 
37
        tree.commit('')
 
38
        tree.branch.lock_read()
 
39
        self.addCleanup(tree.branch.unlock)
 
40
        branch_app = BranchWSGIApp(tree.branch)
 
41
        branch_app._environ = {
 
42
            'wsgi.url_scheme':'',
 
43
            'SERVER_NAME':'',
 
44
            'SERVER_PORT':'80',
 
45
            }
 
46
        branch_app._url_base = ''
 
47
        branch_app.friendly_name = ''
 
48
        return tree.branch, RevisionUI(branch_app, branch_app.get_history)
 
49
 
 
50
    def test_get_values(self):
 
51
        branch, rev_ui = self.make_bzrbranch_and_revision_ui_for_tree_shapes(
 
52
            [], [])
 
53
        rev_ui.args = ['2']
 
54
        util.set_context({})
 
55
        self.assertIsInstance(
 
56
            rev_ui.get_values('2', {}, []),
 
57
            dict)
 
58
 
 
59
    def test_get_changes_with_diff(self):
 
60
        branch, rev_ui = self.make_bzrbranch_and_revision_ui_for_tree_shapes(
 
61
            [('file', 'oldcontents'), ('file2', 'oldcontents')],
 
62
            [('file', 'newcontents'), ('file2', 'oldcontents')])
 
63
        change = rev_ui._history.get_changes([branch.last_revision()])[0]
 
64
        changes, diffs = rev_ui.get_changes_with_diff(change, None, None)
 
65
        self.assertEqual(1, len(diffs))
 
66
 
 
67
    def test_get_changes_with_diff_specific_path(self):
 
68
        branch, rev_ui = self.make_bzrbranch_and_revision_ui_for_tree_shapes(
 
69
            [('file', 'oldcontents'), ('file2', 'oldcontents')],
 
70
            [('file', 'newcontents'), ('file2', 'newcontents')])
 
71
        change = rev_ui._history.get_changes([branch.last_revision()])[0]
 
72
        changes, diffs = rev_ui.get_changes_with_diff(change, None, 'file')
 
73
        self.assertEqual(1, len(diffs))
 
74
 
 
75
class TestAnnotateUI(BasicTests):
 
76
 
 
77
    def make_annotate_ui_for_file_history(self, file_id, rev_ids_texts):
 
78
        tree = self.make_branch_and_tree('.')
 
79
        open('filename', 'w').write('')
 
80
        tree.add(['filename'], [file_id])
 
81
        for rev_id, text in rev_ids_texts:
 
82
            open('filename', 'w').write(text)
 
83
            tree.commit(rev_id=rev_id, message='.')
 
84
        tree.branch.lock_read()
 
85
        self.addCleanup(tree.branch.unlock)
 
86
        branch_app = BranchWSGIApp(tree.branch)
 
87
        return AnnotateUI(branch_app, branch_app.get_history)
 
88
 
 
89
    def test_annotate_file(self):
 
90
        history = [('rev1', 'old\nold\n'), ('rev2', 'new\nold\n')]
 
91
        ann_ui = self.make_annotate_ui_for_file_history('file_id', history)
 
92
        annotated = list(ann_ui.annotate_file('file_id', 'rev2'))
 
93
        self.assertEqual(2, len(annotated))
 
94
        self.assertEqual('2', annotated[0].change.revno)
 
95
        self.assertEqual('1', annotated[1].change.revno)