[test][fix] configuration in halfapi route argument
This commit is contained in:
parent
4991684ffe
commit
ff90e591aa
|
@ -1,5 +1,10 @@
|
|||
# HalfAPI
|
||||
|
||||
## 0.6.21
|
||||
|
||||
- Store only domain's config in halfapi['config']
|
||||
- Should run halfapi domain with config_file argument
|
||||
|
||||
## 0.6.20
|
||||
|
||||
- Fix arguments handling
|
||||
|
|
|
@ -35,7 +35,21 @@ class DomainMiddleware(BaseHTTPMiddleware):
|
|||
request.scope['domain'] = self.domain['name']
|
||||
if hasattr(request.app, 'config') \
|
||||
and isinstance(request.app.config, dict):
|
||||
request.scope['config'] = { **request.app.config }
|
||||
# Set the config scope to the domain's config
|
||||
request.scope['config'] = request.app.config.get(
|
||||
'domain', {}
|
||||
).get(
|
||||
self.domain['name'], {}
|
||||
).copy()
|
||||
|
||||
# TODO: Remove in 0.7.0
|
||||
config = request.scope['config'].copy()
|
||||
request.scope['config']['domain'] = {}
|
||||
request.scope['config']['domain'][self.domain['name']] = {}
|
||||
request.scope['config']['domain'][self.domain['name']]['config'] = config
|
||||
|
||||
|
||||
|
||||
else:
|
||||
logger.debug('%s', request.app)
|
||||
logger.debug('%s', getattr(request.app, 'config', None))
|
||||
|
|
|
@ -4,6 +4,7 @@ import subprocess
|
|||
import importlib
|
||||
import tempfile
|
||||
from unittest.mock import patch
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from click.testing import CliRunner
|
||||
|
@ -25,7 +26,20 @@ class TestCliProj():
|
|||
r = project_runner('domain')
|
||||
print(r.stdout)
|
||||
assert r.exit_code == 1
|
||||
r = project_runner('domain dummy_domain')
|
||||
_, tmp_conf = tempfile.mkstemp()
|
||||
with open(tmp_conf, 'w') as fh:
|
||||
fh.write(
|
||||
json.dumps({
|
||||
'domain': {
|
||||
'dummy_domain': {
|
||||
'name': 'dummy_domain',
|
||||
'enabled': True
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
r = project_runner(f'domain dummy_domain {tmp_conf}')
|
||||
print(r.stdout)
|
||||
assert r.exit_code == 0
|
||||
|
||||
|
|
|
@ -14,4 +14,17 @@ def get(halfapi):
|
|||
returns the configuration of the domain
|
||||
"""
|
||||
logger.error('%s', halfapi)
|
||||
return halfapi['config']['domain']['dummy_domain']['config']
|
||||
# TODO: Remove in 0.7.0
|
||||
try:
|
||||
assert 'test' in halfapi['config']['domain']['dummy_domain']['config']
|
||||
except AssertionError as exc:
|
||||
logger.error('No TEST in halfapi[config][domain][dummy_domain][config]')
|
||||
raise exc
|
||||
|
||||
try:
|
||||
assert 'test' in halfapi['config']
|
||||
except AssertionError as exc:
|
||||
logger.error('No TEST in halfapi[config]')
|
||||
raise exc
|
||||
|
||||
return halfapi['config']
|
||||
|
|
Loading…
Reference in New Issue