~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_controllers.py

  • Committer: Matt Nordhoff
  • Date: 2009-05-17 13:03:04 UTC
  • mto: This revision was merged to the branch mainline in revision 351.
  • Revision ID: mnordhoff@mattnordhoff.com-20090517130304-z1ryqw3pmqjvsbzi
Support "bzr serve"'s --directory argument.

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('', {}, []),
 
57
            dict)
 
58
 
 
59
 
 
60
class TestAnnotateUI(BasicTests):
 
61
 
 
62
    def make_annotate_ui_for_file_history(self, file_id, rev_ids_texts):
 
63
        tree = self.make_branch_and_tree('.')
 
64
        open('filename', 'w').write('')
 
65
        tree.add(['filename'], [file_id])
 
66
        for rev_id, text in rev_ids_texts:
 
67
            open('filename', 'w').write(text)
 
68
            tree.commit(rev_id=rev_id, message='.')
 
69
        tree.branch.lock_read()
 
70
        self.addCleanup(tree.branch.unlock)
 
71
        branch_app = BranchWSGIApp(tree.branch)
 
72
        return AnnotateUI(branch_app, branch_app.get_history)
 
73
 
 
74
    def test_annotate_file(self):
 
75
        history = [('rev1', 'old\nold\n'), ('rev2', 'new\nold\n')]
 
76
        ann_ui = self.make_annotate_ui_for_file_history('file_id', history)
 
77
        annotated = list(ann_ui.annotate_file('file_id', 'rev2'))
 
78
        self.assertEqual(2, len(annotated))
 
79
        self.assertEqual('2', annotated[0].change.revno)
 
80
        self.assertEqual('1', annotated[1].change.revno)