26
16
tree.branch.lock_read()
27
17
self.addCleanup(tree.branch.unlock)
28
branch_app = BranchWSGIApp(tree.branch, '')
29
branch_app.log.setLevel(logging.CRITICAL)
30
# These are usually set in BranchWSGIApp.app(), which is set from env
31
# settings set by BranchesFromTransportRoot, so we fake it.
32
branch_app._static_url_base = '/'
33
branch_app._url_base = '/'
18
branch_app = BranchWSGIApp(tree.branch)
34
19
return tree.branch, InventoryUI(branch_app, branch_app.get_history)
36
def consume_app(self, app, extra_environ=None):
37
env = {'SCRIPT_NAME': '/files', 'PATH_INFO': ''}
38
if extra_environ is not None:
39
env.update(extra_environ)
42
def start_response(status, headers, exc_info=None):
43
start.append((status, headers, exc_info))
45
extra_content = list(app(env, start_response))
46
body.writelines(extra_content)
47
return start[0], body.getvalue()
49
21
def test_get_filelist(self):
50
22
bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
52
24
inv = bzrbranch.repository.get_inventory(bzrbranch.last_revision())
53
25
self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename')))
56
bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
58
start, content = self.consume_app(inv_ui)
59
self.assertEqual(('200 OK', [('Content-Type', 'text/html')], None),
61
self.assertContainsRe(content, 'filename')
63
def test_no_content_for_HEAD(self):
64
bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
66
start, content = self.consume_app(inv_ui,
67
extra_environ={'REQUEST_METHOD': 'HEAD'})
68
self.assertEqual(('200 OK', [('Content-Type', 'text/html')], None),
70
self.assertEqual('', content)
73
28
class TestRevisionUI(BasicTests):
107
62
def make_annotate_ui_for_file_history(self, file_id, rev_ids_texts):
108
63
tree = self.make_branch_and_tree('.')
109
self.build_tree_contents([('filename', '')])
64
open('filename', 'w').write('')
110
65
tree.add(['filename'], [file_id])
111
66
for rev_id, text in rev_ids_texts:
112
self.build_tree_contents([('filename', text)])
67
open('filename', 'w').write(text)
113
68
tree.commit(rev_id=rev_id, message='.')
114
69
tree.branch.lock_read()
115
70
self.addCleanup(tree.branch.unlock)
116
branch_app = BranchWSGIApp(tree.branch, friendly_name='test_name')
71
branch_app = BranchWSGIApp(tree.branch)
117
72
return AnnotateUI(branch_app, branch_app.get_history)
119
74
def test_annotate_file(self):
120
75
history = [('rev1', 'old\nold\n'), ('rev2', 'new\nold\n')]
121
76
ann_ui = self.make_annotate_ui_for_file_history('file_id', history)
122
# A lot of this state is set up by __call__, but we'll do it directly
124
ann_ui.args = ['rev2']
125
annotate_info = ann_ui.get_values('filename',
126
kwargs={'file_id': 'file_id'}, headers={})
127
annotated = list(annotate_info['annotated'])
77
annotated = list(ann_ui.annotate_file('file_id', 'rev2'))
128
78
self.assertEqual(2, len(annotated))
129
79
self.assertEqual('2', annotated[0].change.revno)
130
80
self.assertEqual('1', annotated[1].change.revno)
132
class TestDownloadTarballUI(BasicTests):
134
def test_download_tarball(self):
135
app = self.setUpLoggerhead()
136
res = app.get('/tarball')
138
f = open(tmpname, 'w')
141
self.failIf(not is_tarfile(tmpname))