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)
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)
39
def start_response(status, headers, exc_info=None):
40
start.append((status, headers, exc_info))
42
extra_content = list(app(env, start_response))
43
body.writelines(extra_content)
44
return start[0], body.getvalue()
46
21
def test_get_filelist(self):
47
22
bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
49
24
inv = bzrbranch.repository.get_inventory(bzrbranch.last_revision())
50
self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename', 'head')))
53
bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
55
start, content = self.consume_app(inv_ui)
56
self.assertEqual(('200 OK', [('Content-Type', 'text/html')], None),
58
self.assertContainsRe(content, 'filename')
60
def test_no_content_for_HEAD(self):
61
bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
63
start, content = self.consume_app(inv_ui,
64
extra_environ={'REQUEST_METHOD': 'HEAD'})
65
self.assertEqual(('200 OK', [('Content-Type', 'text/html')], None),
67
self.assertEqual('', content)
25
self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename')))
70
28
class TestRevisionUI(BasicTests):
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)
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
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)