10
9
from loggerhead.controllers.annotate_ui import AnnotateUI
11
10
from loggerhead.controllers.inventory_ui import InventoryUI
12
11
from loggerhead.controllers.revision_ui import RevisionUI
13
from loggerhead.controllers.revlog_ui import RevLogUI
14
12
from loggerhead.tests.test_simple import BasicTests
15
13
from loggerhead import util
18
def consume_app(app, env):
21
def start_response(status, headers, exc_info=None):
22
start.append((status, headers, exc_info))
24
extra_content = list(app(env, start_response))
25
body.writelines(extra_content)
26
return start[0], body.getvalue()
29
16
class TestInventoryUI(BasicTests):
31
18
def make_bzrbranch_and_inventory_ui_for_tree_shape(self, shape):
43
30
branch_app._url_base = '/'
44
31
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
46
def test_get_filelist(self):
47
47
bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
52
52
def test_smoke(self):
53
53
bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
55
start, content = consume_app(inv_ui,
56
{'SCRIPT_NAME': '/files', 'PATH_INFO': ''})
55
start, content = self.consume_app(inv_ui)
57
56
self.assertEqual(('200 OK', [('Content-Type', 'text/html')], None),
59
58
self.assertContainsRe(content, 'filename')
61
60
def test_no_content_for_HEAD(self):
62
61
bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
64
start, content = consume_app(inv_ui,
65
{'SCRIPT_NAME': '/files', 'PATH_INFO': '',
66
'REQUEST_METHOD': 'HEAD'})
63
start, content = self.consume_app(inv_ui,
64
extra_environ={'REQUEST_METHOD': 'HEAD'})
67
65
self.assertEqual(('200 OK', [('Content-Type', 'text/html')], None),
69
67
self.assertEqual('', content)
82
80
tree.branch.lock_read()
83
81
self.addCleanup(tree.branch.unlock)
84
branch_app = self.make_branch_app(tree.branch)
82
branch_app = BranchWSGIApp(tree.branch)
83
branch_app._environ = {
88
branch_app._url_base = ''
89
branch_app.friendly_name = ''
85
90
return tree.branch, RevisionUI(branch_app, branch_app.get_history)
87
92
def test_get_values(self):
116
121
ann_ui.args = ['rev2']
117
122
annotate_info = ann_ui.get_values('filename',
118
123
kwargs={'file_id': 'file_id'}, headers={})
119
annotated = annotate_info['annotated']
124
annotated = list(annotate_info['annotated'])
120
125
self.assertEqual(2, len(annotated))
121
self.assertEqual('2', annotated[1].change.revno)
122
self.assertEqual('1', annotated[2].change.revno)
125
class TestRevLogUI(BasicTests):
127
def make_branch_app_for_revlog_ui(self):
128
builder = self.make_branch_builder('branch')
129
builder.start_series()
130
builder.build_snapshot('rev-id', None, [
131
('add', ('', 'root-id', 'directory', '')),
132
('add', ('filename', 'f-id', 'file', 'content\n'))],
133
message="First commit.")
134
builder.finish_series()
135
branch = builder.get_branch()
136
self.addCleanup(branch.lock_read().unlock)
137
return self.make_branch_app(branch)
139
def test_get_values_smoke(self):
140
branch_app = self.make_branch_app_for_revlog_ui()
141
env = {'SCRIPT_NAME': '/',
142
'PATH_INFO': '/+revlog/rev-id'}
143
revlog_ui = branch_app.lookup_app(env)
144
revlog_ui.parse_args(env)
145
values = revlog_ui.get_values('', {}, {})
146
self.assertEqual(values['file_changes'].added[1].filename, 'filename')
147
self.assertEqual(values['entry'].comment, "First commit.")
150
def test_json_render_smoke(self):
151
branch_app = self.make_branch_app_for_revlog_ui()
152
env = {'SCRIPT_NAME': '', 'PATH_INFO': '/+json/+revlog/rev-id'}
153
revlog_ui = branch_app.lookup_app(env)
154
start, content = consume_app(revlog_ui, env)
155
self.assertEqual('200 OK', start[0])
156
self.assertEqual('application/json', dict(start[1])['Content-Type'])
157
self.assertEqual(None, start[2])
158
simplejson.loads(content)
126
self.assertEqual('2', annotated[0].change.revno)
127
self.assertEqual('1', annotated[1].change.revno)