Skip to content

Commit 5ffe792

Browse files
committed
simplify
1 parent 4707173 commit 5ffe792

File tree

3 files changed

+17
-31
lines changed

3 files changed

+17
-31
lines changed

mig/wsgi-bin/migwsgi.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,10 @@ def application(environ, start_response):
213213
def _set_os_environ(value):
214214
os.environ = value
215215

216-
return _application(environ, start_response, _set_environ=_set_os_environ, _wrap_wsgi_errors=wrap_wsgi_errors)
216+
return _application(None, environ, start_response, _set_environ=_set_os_environ, _wrap_wsgi_errors=wrap_wsgi_errors)
217217

218-
def _application(environ, start_response, _set_environ, _format_output=format_output, _retrieve_handler=_import_backend, _wrap_wsgi_errors=True, _config_file=None, _skip_log=False):
218+
219+
def _application(configuration, environ, start_response, _set_environ, _format_output=format_output, _retrieve_handler=_import_backend, _wrap_wsgi_errors=True, _config_file=None, _skip_log=False):
219220

220221
# NOTE: pass app environ including apache and query args on to sub handlers
221222
# through the usual 'os.environ' channel expected in functionality
@@ -266,7 +267,9 @@ def _application(environ, start_response, _set_environ, _format_output=format_ou
266267
if sys.version_info[0] < 3:
267268
sys.stdout = sys.stderr
268269

269-
configuration = get_configuration_object(_config_file, _skip_log)
270+
if configuration is None:
271+
configuration = get_configuration_object(_config_file, _skip_log)
272+
270273
_logger = configuration.logger
271274

272275
# NOTE: replace default wsgi errors to apache error log with our own logs

tests/support/wsgisupp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
"""Test support library for WSGI."""
2929

3030

31-
def create_wsgi_environ(config_file, wsgi_variables):
31+
def create_wsgi_environ(configuration, wsgi_variables):
3232
environ = {}
3333
environ['wsgi.input'] = ()
34-
environ['MIG_CONF'] = config_file
34+
environ['MIG_CONF'] = configuration.config_file
3535
environ['HTTP_HOST'] = wsgi_variables.get('http_host')
3636
environ['PATH_INFO'] = wsgi_variables.get('path_info')
3737
environ['SCRIPT_URI'] = ''.join(('http://', environ['HTTP_HOST'], environ['PATH_INFO']))

tests/test_mig_wsgi-bin_migwsgi.py

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,12 @@ def _import_migwsgi():
6161
migwsgi = _import_migwsgi()
6262

6363

64-
def _assert_local_config():
65-
try:
66-
link_stat = os.lstat(_TEST_CONF_SYMLINK)
67-
assert stat.S_ISLNK(link_stat.st_mode)
68-
configdir_stat = os.stat(_TEST_CONF_DIR)
69-
assert stat.S_ISDIR(configdir_stat.st_mode)
70-
config = ConfigParser()
71-
config.read([_TEST_CONF_FILE])
72-
return config
73-
except Exception as exc:
74-
raise AssertionError('local configuration invalid or missing: %s' % (str(exc),))
75-
76-
77-
def _assert_local_config_global_values(config):
78-
config_global_values = dict(config.items('GLOBAL'))
79-
80-
for path in ('mig_path', 'certs_path', 'state_path'):
81-
path_value = config_global_values.get(path)
64+
def _assert_local_config_global_values(configuration):
65+
for config_key in ('mig_path', 'certs_path', 'state_path'):
66+
path_value = getattr(configuration, config_key)
8267
if not is_path_within(path_value, start=_LOCAL_MIG_BASE):
8368
raise AssertionError('local config contains bad path: %s=%s' % (path, path_value))
8469

85-
return config_global_values
86-
8770

8871
def _is_return_value(return_value):
8972
defined_return_values = returnvalues.__dict__.values()
@@ -197,12 +180,14 @@ def was_called(fake):
197180
self.assertTrue(was_called(self.instrumented_format_output), "no output generated")
198181
self.assertTrue(was_called(self.instrumented_retrieve_handler), "no output generated")
199182

183+
def _provide_configuration(self):
184+
return 'testconfig'
185+
200186
def before_each(self):
201-
config = _assert_local_config()
202-
config_global_values = _assert_local_config_global_values(config)
187+
_assert_local_config_global_values(self.configuration)
203188

204189
# generic WSGI setup
205-
self.fake_wsgi_environ = create_wsgi_environ(_TEST_CONF_FILE, wsgi_variables=dict(
190+
self.fake_wsgi_environ = create_wsgi_environ(self.configuration, wsgi_variables=dict(
206191
http_host='localhost',
207192
path_info='/',
208193
))
@@ -212,11 +197,9 @@ def before_each(self):
212197
self.instrumented_format_output = create_instrumented_format_output()
213198
self.instrumented_retrieve_handler = create_instrumented_retrieve_handler()
214199

215-
self.application_args = (self.fake_wsgi_environ, self.fake_start_response,)
200+
self.application_args = (self.configuration, self.fake_wsgi_environ, self.fake_start_response,)
216201
self.application_kwargs = dict(
217202
_wrap_wsgi_errors=noop,
218-
_config_file=_TEST_CONF_FILE,
219-
_skip_log=True,
220203
_format_output=self.instrumented_format_output,
221204
_retrieve_handler=self.instrumented_retrieve_handler,
222205
_set_environ=noop,

0 commit comments

Comments
 (0)