From 5e88109b3ea52f9dc6d16e6316cffb2f8ca360d2 Mon Sep 17 00:00:00 2001 From: "Maxime Alves LIRMM@home" Date: Wed, 1 Dec 2021 12:14:27 +0100 Subject: [PATCH] manipuler le sys.path : BAAAD --- halfapi/cli/run.py | 2 -- halfapi/lib/domain.py | 1 - tests/conftest.py | 13 ++----------- tests/test_lib_schemas.py | 23 ----------------------- 4 files changed, 2 insertions(+), 37 deletions(-) diff --git a/halfapi/cli/run.py b/halfapi/cli/run.py index 8c7e3fa..6ebc0be 100644 --- a/halfapi/cli/run.py +++ b/halfapi/cli/run.py @@ -50,8 +50,6 @@ def run(host, port, reload, secret, production, loglevel, prefix, check, schema, click.echo(f'Launching application {PROJECT_NAME}') - sys.path.insert(0, os.getcwd()) - CONFIG.get('domain')['name'] = domain CONFIG.get('domain')['router'] = router diff --git a/halfapi/lib/domain.py b/halfapi/lib/domain.py index 7ad76a6..fc2969b 100644 --- a/halfapi/lib/domain.py +++ b/halfapi/lib/domain.py @@ -303,7 +303,6 @@ def d_domains(config) -> Dict[str, ModuleType]: domains = dict(config['domains'].items()) try: - sys.path.append('.') return { domain: importlib.import_module(''.join((domain, module))) for domain, module in domains.items() diff --git a/tests/conftest.py b/tests/conftest.py index 4d517b0..89ae249 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -258,7 +258,6 @@ def create_route(): @pytest.fixture def dummy_project(): - sys.path.insert(0, './tests') halfapi_config = tempfile.mktemp() halfapi_secret = tempfile.mktemp() domain = 'dummy_domain' @@ -281,18 +280,10 @@ def dummy_project(): with open(halfapi_secret, 'w') as f: f.write('turlututu') - return (halfapi_config, 'dummy_domain', 'routers') + return (halfapi_config, 'dummy_domain', 'dummy_domain.routers') @pytest.fixture -def routers(): - sys.path.insert(0, './tests') - - from .dummy_domain import routers - return routers - - -@pytest.fixture -def application_debug(routers): +def application_debug(project_runner): halfAPI = HalfAPI({ 'secret':'turlututu', 'production':False, diff --git a/tests/test_lib_schemas.py b/tests/test_lib_schemas.py index 0f7fe7c..4e89830 100644 --- a/tests/test_lib_schemas.py +++ b/tests/test_lib_schemas.py @@ -16,29 +16,6 @@ def test_schemas_dict_dom(): 'dummy_domain':routers}) assert isinstance(schema, dict) -def test_get_api_schema(project_runner, application_debug): - c = TestClient(application_debug) - r = c.get('/') - assert isinstance(c, TestClient) - d_r = r.json() - assert isinstance(d_r, dict) - pprint(d_r) - assert API_SCHEMA.validate(d_r) - - -""" -def test_get_api_dummy_domain_routes(application_domain, routers): - c = TestClient(application_domain) - r = c.get('/dummy_domain') - assert r.status_code == 200 - d_r = r.json() - assert isinstance(d_r, dict) - assert 'abc/alphabet' in d_r - assert 'GET' in d_r['abc/alphabet'] - assert len(d_r['abc/alphabet']['GET']) > 0 - assert 'acls' in d_r['abc/alphabet']['GET'] -""" - def test_schema_to_csv(): csv = schema_to_csv('dummy_domain.routers', False) assert isinstance(csv, str)