halfapi/tests/test_dummy_project_router.py

55 lines
1.8 KiB
Python
Raw Normal View History

[0.5.3] Squashed commit of the following: commit ac935db6d62656713183707707d083298c1f34b0 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Thu Jun 17 18:52:49 2021 +0200 [tests] remove dummy-domain from dependencies commit 4d50363c9b1502d1d8b7cbafc207e80cdbe247a4 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Thu Jun 17 18:52:18 2021 +0200 [tests] update tests for 0.5.3 commit 6181592692464d21de9807e1e890b4ac92efc387 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Thu Jun 17 18:17:51 2021 +0200 [lib.*] Refactor libs commit ed7485a8a16b60dde8acc0d2b9afca00a75fce3c Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Thu Jun 17 18:15:10 2021 +0200 [app] Use HalfAPI class to be able to use custom configuration à commit fa1ca6bf9df4ea17d7fa7dfdf3694c56746e9c7f Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Wed Jun 16 15:34:25 2021 +0200 [wip] tests dummy_domain commit 86e8dd3465e0bd0f3d49f28fd9e05a52874e969a Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Tue Jun 15 18:12:13 2021 +0200 [0.5.3] ajout de la config actuelle dans les arguments des routes commit aa7ec62c7a3b5a0ae0dc0cc79bd509eece44d5ff Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Tue Jun 15 11:16:23 2021 +0200 [lib.jwtMw] verify signature even if halfapi is in DEBUG mode commit e208728d7ec61b0de583c66c348f73ac7a884108 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Tue Jun 15 10:49:46 2021 +0200 [lib.acl] args_check doesn't check required/optional arguments if "args" is not specified in request, if the target function is not async commit aa4c309778e4c969fe1314da305e02112d4641b7 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Tue Jun 15 09:45:37 2021 +0200 [lib.domain] SUBROUTER can be a path parameter if including ":" commit 138420461d5c1ba0c7379dcda64e9a38aa5d768d Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Tue Jun 15 07:24:32 2021 +0200 [gitignore] *.swp commit 0c1e2849bad591d62f7399d820a044cf4e06de12 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Tue Jun 15 07:24:14 2021 +0200 [tests] test get route with dummy projects commit 7227e2d7f105516b67f3acac27b242fe01b59215 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Mon Jun 14 17:18:47 2021 +0200 [lib.domain] handle modules without ROUTES attribute commit 78c75cd60ead023e7a2d7fa2e5d1059fada0044f Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Mon Jun 14 16:34:58 2021 +0200 [tests] add dummy_project_router tests for path-based routers (without ROUTES variable)
2021-06-17 18:53:23 +02:00
import os
import sys
import importlib
import subprocess
import time
import pytest
from starlette.routing import Route
from starlette.testclient import TestClient
from halfapi.lib.domain import gen_router_routes
def test_get_config_route(dummy_project, application_domain, routers):
c = TestClient(application_domain)
r = c.get('/dummy_domain/config')
assert 'test' in r.json()
[0.5.3] Squashed commit of the following: commit ac935db6d62656713183707707d083298c1f34b0 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Thu Jun 17 18:52:49 2021 +0200 [tests] remove dummy-domain from dependencies commit 4d50363c9b1502d1d8b7cbafc207e80cdbe247a4 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Thu Jun 17 18:52:18 2021 +0200 [tests] update tests for 0.5.3 commit 6181592692464d21de9807e1e890b4ac92efc387 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Thu Jun 17 18:17:51 2021 +0200 [lib.*] Refactor libs commit ed7485a8a16b60dde8acc0d2b9afca00a75fce3c Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Thu Jun 17 18:15:10 2021 +0200 [app] Use HalfAPI class to be able to use custom configuration à commit fa1ca6bf9df4ea17d7fa7dfdf3694c56746e9c7f Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Wed Jun 16 15:34:25 2021 +0200 [wip] tests dummy_domain commit 86e8dd3465e0bd0f3d49f28fd9e05a52874e969a Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Tue Jun 15 18:12:13 2021 +0200 [0.5.3] ajout de la config actuelle dans les arguments des routes commit aa7ec62c7a3b5a0ae0dc0cc79bd509eece44d5ff Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Tue Jun 15 11:16:23 2021 +0200 [lib.jwtMw] verify signature even if halfapi is in DEBUG mode commit e208728d7ec61b0de583c66c348f73ac7a884108 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Tue Jun 15 10:49:46 2021 +0200 [lib.acl] args_check doesn't check required/optional arguments if "args" is not specified in request, if the target function is not async commit aa4c309778e4c969fe1314da305e02112d4641b7 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Tue Jun 15 09:45:37 2021 +0200 [lib.domain] SUBROUTER can be a path parameter if including ":" commit 138420461d5c1ba0c7379dcda64e9a38aa5d768d Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Tue Jun 15 07:24:32 2021 +0200 [gitignore] *.swp commit 0c1e2849bad591d62f7399d820a044cf4e06de12 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Tue Jun 15 07:24:14 2021 +0200 [tests] test get route with dummy projects commit 7227e2d7f105516b67f3acac27b242fe01b59215 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Mon Jun 14 17:18:47 2021 +0200 [lib.domain] handle modules without ROUTES attribute commit 78c75cd60ead023e7a2d7fa2e5d1059fada0044f Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Mon Jun 14 16:34:58 2021 +0200 [tests] add dummy_project_router tests for path-based routers (without ROUTES variable)
2021-06-17 18:53:23 +02:00
def test_get_route(dummy_project, application_domain, routers):
c = TestClient(application_domain)
path = verb = params = None
for path, verb, _, params in gen_router_routes(routers, []):
if len(params):
route_path = '/dummy_domain/{}'.format(path)
try:
if verb.lower() == 'get':
r = c.get(route_path)
elif verb.lower() == 'post':
r = c.post(route_path)
elif verb.lower() == 'patch':
r = c.patch(route_path)
elif verb.lower() == 'put':
r = c.put(route_path)
elif verb.lower() == 'delete':
r = c.delete(route_path)
else:
raise Exception(verb)
try:
assert r.status_code in [200, 501]
except AssertionError as exc:
print('{} [{}] {}'.format(str(r.status_code), verb, route_path))
except NotImplementedError:
pass
if not path:
raise Exception('No route generated')
2021-06-25 12:20:25 +02:00
def test_delete_route(dummy_project, application_domain, routers):
c = TestClient(application_domain)
from uuid import uuid4
arg = str(uuid4())
r = c.delete(f'/dummy_domain/abc/alphabet/{arg}')
assert r.status_code == 200
assert r.json() == arg