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
9
class TestInventoryUI(BasicTests):
11
def make_bzrbranch_and_inventory_ui_for_tree_shape(self, shape):
12
tree = self.make_branch_and_tree('.')
13
self.build_tree(shape)
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)
21
def test_get_filelist(self):
22
bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
24
inv = bzrbranch.repository.get_inventory(bzrbranch.last_revision())
25
self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename')))
28
class TestRevisionUI(BasicTests):
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)
35
self.build_tree_contents(shape2)
38
tree.branch.lock_read()
39
self.addCleanup(tree.branch.unlock)
40
branch_app = BranchWSGIApp(tree.branch)
41
branch_app._environ = {
46
branch_app._url_base = ''
47
branch_app.friendly_name = ''
48
return tree.branch, RevisionUI(branch_app, branch_app.get_history)
50
def test_get_values(self):
51
branch, rev_ui = self.make_bzrbranch_and_revision_ui_for_tree_shapes(
55
self.assertIsInstance(
56
rev_ui.get_values('', {}, []),
60
class TestAnnotateUI(BasicTests):
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)
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)