Skip to content

Commit c09fc99

Browse files
committed
wsgibinsupp: specific assertion for html output
1 parent db80a5a commit c09fc99

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

tests/support/wsgibinsupp.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,18 @@ def _instrumented_format_output(
7979
'text': _instrumented_format_output.values['header_text']
8080
})
8181

82-
return format_output(
82+
output = format_output(
8383
configuration,
8484
backend,
8585
ret_val,
8686
ret_msg,
8787
out_obj,
8888
outputformat,
8989
)
90+
_instrumented_format_output.returned = output
91+
return output
9092
_instrumented_format_output.calls = []
93+
_instrumented_format_output.returned = None
9194
_instrumented_format_output.values = dict(
9295
title_text='',
9396
header_text='',
@@ -129,19 +132,37 @@ def __init__(self):
129132
self.format_output = create_instrumented_format_output()
130133
self.retrieve_handler = create_instrumented_retrieve_handler()
131134

135+
def arranged(self):
136+
simulated_action = self.retrieve_handler.simulated
137+
if simulated_action is None:
138+
return 'nothing'
139+
140+
return_value = simulated_action.returning
141+
if isinstance(return_value, tuple) and isinstance(return_value[0], list):
142+
return 'html'
143+
144+
raise NotImplementedError()
145+
132146
def set_response(self, content, returnvalue):
133147
self.retrieve_handler.program(content, returnvalue)
134148

149+
def return_value(self):
150+
arranged_return_type = self.arranged()
151+
152+
if arranged_return_type == 'html':
153+
return self.format_output.returned
154+
155+
raise NotImplementedError()
156+
135157

136158
class WsgibinAssertMixin:
137159
def assertWsgibinInstrumentation(self, instrumentation=None):
138160
if instrumentation is None:
139161
instrumentation = getattr(self, 'wsgibin_instrumentation', None)
140162
assert isinstance(instrumentation, WsgibinInstrumentation)
141163

142-
simulated_action = instrumentation.retrieve_handler.simulated
143-
self.assertIsNotNone(simulated_action.returning,
144-
"no response programmed")
164+
self.assertNotEqual(instrumentation.arranged(),
165+
'nothing', "no response programmed")
145166

146167
def was_called(fake):
147168
assert hasattr(fake, 'calls')
@@ -151,3 +172,10 @@ def was_called(fake):
151172
instrumentation.format_output), "no output generated")
152173
self.assertTrue(was_called(
153174
instrumentation.retrieve_handler), "no output generated")
175+
176+
return instrumentation
177+
178+
def assertWsgibinHtml(self, instrumentation=None):
179+
instrumentation = self.assertWsgibinInstrumentation(instrumentation=instrumentation)
180+
self.assertEqual(instrumentation.arranged(), 'html', "wsgibinsupp: arranged output was not html")
181+
return instrumentation.return_value()

0 commit comments

Comments
 (0)