From 3959e6d6145f8357ba40d092edf6b11b2cbe21ca Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Wed, 7 Oct 2020 15:51:24 +0200 Subject: [PATCH] [tests] add dummy_domain as a testing dependency (because domains can't be "not installed" in sys.path) --- Pipfile | 1 + .../routers/abc/alphabet/__init__.py | 11 ++++---- tests/setup.py | 25 +++++++++++++++++++ tests/test_lib_domain.py | 3 ++- tests/test_lib_routes.py | 3 +-- tests/test_lib_schemas.py | 10 +------- 6 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 tests/setup.py diff --git a/Pipfile b/Pipfile index 5997d88..c267aaf 100644 --- a/Pipfile +++ b/Pipfile @@ -8,6 +8,7 @@ pytest = "*" requests = "*" pytest-asyncio = "*" pylint = "*" +dummy-domain = {path = "./tests"} [packages] click = "*" diff --git a/tests/dummy_domain/routers/abc/alphabet/__init__.py b/tests/dummy_domain/routers/abc/alphabet/__init__.py index c0a81ed..24a3c64 100644 --- a/tests/dummy_domain/routers/abc/alphabet/__init__.py +++ b/tests/dummy_domain/routers/abc/alphabet/__init__.py @@ -1,14 +1,15 @@ from starlette.responses import PlainTextResponse +from dummy_domain import acl ROUTES={ '': { - 'GET': [{'acl':None, 'in':None}] + 'GET': [{'acl':acl.public}] }, '{test:uuid}': { - 'GET': [{'acl':None, 'in':None}], - 'POST': [{'acl':None, 'in':None}], - 'PATCH': [{'acl':None, 'in':None}], - 'PUT': [{'acl':None, 'in':None}] + 'GET': [{'acl':None}], + 'POST': [{'acl':None}], + 'PATCH': [{'acl':None}], + 'PUT': [{'acl':None}] } } diff --git a/tests/setup.py b/tests/setup.py new file mode 100644 index 0000000..68f6743 --- /dev/null +++ b/tests/setup.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +import os + +def get_packages(package): + """ + Return root package and all sub-packages. + """ + return [ + dirpath + for dirpath, dirnames, filenames in os.walk(package) + if os.path.exists(os.path.join(dirpath, "__init__.py")) + ] + + +from setuptools import setup, find_packages +module_name="dummy_domain" +setup( + name=module_name, + version='0', + url="https://gite.lirmm.fr/malves/halfapi", + packages=get_packages(module_name), + python_requires=">=3.7", + install_requires=[] +) diff --git a/tests/test_lib_domain.py b/tests/test_lib_domain.py index 8917afd..045b2f6 100644 --- a/tests/test_lib_domain.py +++ b/tests/test_lib_domain.py @@ -20,6 +20,7 @@ def test_gen_router_routes(): def test_gen_domain_routes(): from . import dummy_domain - for route in gen_domain_routes( + for path, route in gen_domain_routes( 'dummy_domain', dummy_domain): + assert isinstance(path, str) assert isinstance(route, dict) diff --git a/tests/test_lib_routes.py b/tests/test_lib_routes.py index 949f9f9..0b4f373 100644 --- a/tests/test_lib_routes.py +++ b/tests/test_lib_routes.py @@ -3,8 +3,7 @@ from halfapi.lib.routes import gen_starlette_routes def test_gen_starlette_routes(): from . import dummy_domain - for path, route in gen_starlette_routes({ + for route in gen_starlette_routes({ 'dummy_domain': dummy_domain }): - assert isinstance(path, str) assert isinstance(route, Route) diff --git a/tests/test_lib_schemas.py b/tests/test_lib_schemas.py index 9e874cc..638fb7c 100644 --- a/tests/test_lib_schemas.py +++ b/tests/test_lib_schemas.py @@ -19,12 +19,4 @@ def test_get_api_routes(project_runner): c = TestClient(application) r = c.get('/') d_r = r.json() - try: - assert isinstance(d_r, dict) - assert 'paths' in d_r - assert '/' in d_r['paths'] - assert '/dummy_domain/abc/alphabet' in d_r['paths'] - except AssertionError as exc: - pprint(d_r) - raise exc - + assert isinstance(d_r, dict)