Squashed commit of the following: commit 7fe3e22f5e4108b5eb149abf8d608334debc49ca Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Thu Sep 2 16:59:52 2021 +0200 [0.5.9] release commit c36c0fcc982388a5acf2f9f937fa8ab54a18f3de Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Thu Sep 2 16:53:13 2021 +0200 [conf] fix #19 et ajout du test (test_dummy_project_router/test_get_config) configuration du domaine accessible depuis : l'attribut config de l'argument "halfapi" pour les fonctions request.scope['config'] pour les fonctions async commit cc235eee8c6f8f5d3606dda0f88156697eac296e Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Thu Sep 2 14:59:17 2021 +0200 [tests] don't import click two times commit fa418478c76205bb407e536737d8e389b4bf391c Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Thu Sep 2 14:57:06 2021 +0200 [clean] remove unused variables, remove [] as default value in fct, raise from exc
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
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()
|
|
|
|
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')
|
|
|
|
|
|
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
|