[test][fix] configuration in halfapi route argument

This commit is contained in:
Maxime Alves LIRMM@home 2022-08-05 09:37:17 +02:00
parent 4991684ffe
commit ff90e591aa
4 changed files with 49 additions and 3 deletions

View File

@ -1,5 +1,10 @@
# HalfAPI # HalfAPI
## 0.6.21
- Store only domain's config in halfapi['config']
- Should run halfapi domain with config_file argument
## 0.6.20 ## 0.6.20
- Fix arguments handling - Fix arguments handling

View File

@ -35,7 +35,21 @@ class DomainMiddleware(BaseHTTPMiddleware):
request.scope['domain'] = self.domain['name'] request.scope['domain'] = self.domain['name']
if hasattr(request.app, 'config') \ if hasattr(request.app, 'config') \
and isinstance(request.app.config, dict): 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: else:
logger.debug('%s', request.app) logger.debug('%s', request.app)
logger.debug('%s', getattr(request.app, 'config', None)) logger.debug('%s', getattr(request.app, 'config', None))

View File

@ -4,6 +4,7 @@ import subprocess
import importlib import importlib
import tempfile import tempfile
from unittest.mock import patch from unittest.mock import patch
import json
import pytest import pytest
from click.testing import CliRunner from click.testing import CliRunner
@ -25,7 +26,20 @@ class TestCliProj():
r = project_runner('domain') r = project_runner('domain')
print(r.stdout) print(r.stdout)
assert r.exit_code == 1 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) print(r.stdout)
assert r.exit_code == 0 assert r.exit_code == 0

View File

@ -14,4 +14,17 @@ def get(halfapi):
returns the configuration of the domain returns the configuration of the domain
""" """
logger.error('%s', halfapi) 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']