@@ -82,8 +82,25 @@ def _import_migwsgi():
82
82
migwsgi = _import_migwsgi ()
83
83
84
84
85
+ def _is_return_value (return_value ):
86
+ defined_return_values = returnvalues .__dict__ .values ()
87
+ return return_value in defined_return_values
88
+
89
+
90
+ def create_instrumented_retrieve_handler (output_objects = None , return_value = None ):
91
+ if not output_objects :
92
+ output_objects = []
93
+
94
+ assert isinstance (output_objects , list )
95
+ assert _is_return_value (return_value ), "return value must be present in returnvalues"
96
+
97
+ def _instrumented_retrieve_handler (* args ):
98
+ return [], return_value
99
+ return _instrumented_retrieve_handler
100
+
101
+
85
102
def create_instrumented_format_output (arranged ):
86
- def instrumented_format_output (
103
+ def _instrumented_format_output (
87
104
configuration ,
88
105
backend ,
89
106
ret_val ,
@@ -94,8 +111,7 @@ def instrumented_format_output(
94
111
# record the call args
95
112
call_args_out_obj = list (out_obj ) # capture the original before altering it
96
113
call_args = (configuration , backend , ret_val , ret_msg , call_args_out_obj , outputformat ,)
97
- instrumented_format_output .calls .append ({ 'args' : call_args })
98
-
114
+ _instrumented_format_output .calls .append ({ 'args' : call_args })
99
115
100
116
# FIXME: the following is a workaround for a bug that exists between the WSGI wrapper
101
117
# and the output formatter - specifically, the latter adds default header and
@@ -130,16 +146,16 @@ def instrumented_format_output(
130
146
out_obj ,
131
147
outputformat ,
132
148
)
133
- instrumented_format_output .calls = []
134
- return instrumented_format_output
149
+ _instrumented_format_output .calls = []
150
+ return _instrumented_format_output
135
151
136
152
137
- def create_wsgi_environ (config_file , wsgi_input = None , env_http_host = None , env_path_info = None ):
153
+ def create_wsgi_environ (config_file , wsgi_variables ):
138
154
environ = {}
139
155
environ ['wsgi.input' ] = ()
140
156
environ ['MIG_CONF' ] = config_file
141
- environ ['HTTP_HOST' ] = env_http_host
142
- environ ['PATH_INFO' ] = env_path_info
157
+ environ ['HTTP_HOST' ] = wsgi_variables . get ( 'http_host' )
158
+ environ ['PATH_INFO' ] = wsgi_variables . get ( 'path_info' )
143
159
environ ['SCRIPT_URI' ] = '' .join (('http://' , environ ['HTTP_HOST' ], environ ['PATH_INFO' ]))
144
160
return environ
145
161
@@ -160,9 +176,6 @@ def test_xxx(self):
160
176
config = _assert_local_config ()
161
177
config_global_values = _assert_local_config_global_values (config )
162
178
163
- def fake_handler (* args ):
164
- return [], returnvalues .OK
165
-
166
179
def fake_start_response (status , headers , exc = None ):
167
180
fake_start_response .calls .append ((status , headers , exc ))
168
181
fake_start_response .calls = []
@@ -171,18 +184,18 @@ def fake_set_environ(value):
171
184
fake_set_environ .value = value
172
185
fake_set_environ .value = None
173
186
174
- wsgi_environ = create_wsgi_environ (
175
- _TEST_CONF_FILE ,
176
- env_http_host = 'localhost' ,
177
- env_path_info = '/'
178
- )
187
+ wsgi_environ = create_wsgi_environ (_TEST_CONF_FILE , wsgi_variables = dict (
188
+ http_host = 'localhost' ,
189
+ path_info = '/' ,
190
+ ))
179
191
180
192
instrumented_format_output = create_instrumented_format_output ('HELLO WORLD' )
193
+ instrumented_retrieve_handler = create_instrumented_retrieve_handler (None , returnvalues .OK )
181
194
182
195
yielder = migwsgi ._application (wsgi_environ , fake_start_response ,
183
196
_format_output = instrumented_format_output ,
197
+ _retrieve_handler = instrumented_retrieve_handler ,
184
198
_set_environ = fake_set_environ ,
185
- _retrieve_handler = lambda _ : fake_handler ,
186
199
_wrap_wsgi_errors = noop ,
187
200
_config_file = _TEST_CONF_FILE ,
188
201
_skip_log = True ,
0 commit comments