@@ -96,7 +96,7 @@ def _trigger_and_unpack_result(application_result):
96
96
return decoded_value
97
97
98
98
99
- def create_instrumented_format_output (arranged ):
99
+ def create_instrumented_format_output ():
100
100
def _instrumented_format_output (
101
101
configuration ,
102
102
backend ,
@@ -123,7 +123,7 @@ def _instrumented_format_output(
123
123
insertion_idx += 1
124
124
out_obj .insert (insertion_idx , {
125
125
'object_type' : 'title' ,
126
- 'text' : arranged ,
126
+ 'text' : _instrumented_format_output . values [ 'title_text' ] ,
127
127
'meta' : '' ,
128
128
'style' : {},
129
129
'script' : {},
@@ -132,7 +132,7 @@ def _instrumented_format_output(
132
132
insertion_idx += 1
133
133
out_obj .insert (insertion_idx , {
134
134
'object_type' : 'header' ,
135
- 'text' : arranged
135
+ 'text' : _instrumented_format_output . values [ 'header_text' ]
136
136
})
137
137
138
138
return format_output (
@@ -144,6 +144,16 @@ def _instrumented_format_output(
144
144
outputformat ,
145
145
)
146
146
_instrumented_format_output .calls = []
147
+ _instrumented_format_output .values = dict (
148
+ title_text = '' ,
149
+ header_text = '' ,
150
+ )
151
+
152
+ def _program_values (** kwargs ):
153
+ _instrumented_format_output .values .update (kwargs )
154
+
155
+ _instrumented_format_output .set_values = _program_values
156
+
147
157
return _instrumented_format_output
148
158
149
159
@@ -206,6 +216,18 @@ def called_once(fake):
206
216
actual_status_code = int (wsgi_status [0 :3 ])
207
217
self .assertEqual (actual_status_code , expected_status_code )
208
218
219
+ def assertHtmlElementTextContent (self , output , tag_name , expected_text , trim_newlines = True ):
220
+ # TODO: this is a definitively stop-gap way of finding a tag within the HTML
221
+ # and is used purely to keep this initial change to a reasonable size.
222
+ tag_open = '' .join (['<' , tag_name , '>' ])
223
+ tag_open_index = output .index (tag_open )
224
+ tag_close = '' .join (['</' , tag_name , '>' ])
225
+ tag_close_index = output .index (tag_close )
226
+ actual_text = output [tag_open_index + len (tag_open ):tag_close_index ]
227
+ if trim_newlines :
228
+ actual_text = actual_text .strip ('\n ' )
229
+ self .assertEqual (actual_text , expected_text )
230
+
209
231
def assertIsValidHtmlDocument (self , value ):
210
232
assert isinstance (value , type (u"" ))
211
233
assert value .startswith ("<!DOCTYPE" )
@@ -232,7 +254,7 @@ def fake_set_environ(value):
232
254
path_info = '/' ,
233
255
))
234
256
235
- self .instrumented_format_output = create_instrumented_format_output ('HELLO WORLD' )
257
+ self .instrumented_format_output = create_instrumented_format_output ()
236
258
self .instrumented_retrieve_handler = create_instrumented_retrieve_handler ()
237
259
238
260
self .application_args = (fake_wsgi_environ , fake_start_response ,)
@@ -258,7 +280,7 @@ def test_return_value_ok_returns_status_200(self):
258
280
self .assertInstrumentation ()
259
281
self .assertResponseStatus (200 )
260
282
261
- def test_return_value_ok_creates_valid_html_page (self ):
283
+ def test_return_value_ok_returns_valid_html_page (self ):
262
284
self .instrumented_retrieve_handler .program ([], returnvalues .OK )
263
285
264
286
application_result = migwsgi ._application (
@@ -274,6 +296,23 @@ def test_return_value_ok_creates_valid_html_page(self):
274
296
self .assertInstrumentation ()
275
297
self .assertIsValidHtmlDocument (output )
276
298
299
+ def test_return_value_ok_returns_expected_title (self ):
300
+ self .instrumented_format_output .set_values (title_text = 'TEST' )
301
+ self .instrumented_retrieve_handler .program ([], returnvalues .OK )
302
+
303
+ application_result = migwsgi ._application (
304
+ * self .application_args ,
305
+ _wrap_wsgi_errors = noop ,
306
+ _config_file = _TEST_CONF_FILE ,
307
+ _skip_log = True ,
308
+ ** self .application_kwargs
309
+ )
310
+
311
+ output = _trigger_and_unpack_result (application_result )
312
+
313
+ self .assertInstrumentation ()
314
+ self .assertHtmlElementTextContent (output , 'title' , 'TEST' , trim_newlines = True )
315
+
277
316
278
317
if __name__ == '__main__' :
279
318
testmain ()
0 commit comments