2021-06-17 18:53:23 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import importlib
|
|
|
|
import subprocess
|
|
|
|
import time
|
|
|
|
import pytest
|
2021-11-30 18:31:40 +01:00
|
|
|
from pprint import pprint
|
2021-06-17 18:53:23 +02:00
|
|
|
from starlette.routing import Route
|
|
|
|
from starlette.testclient import TestClient
|
|
|
|
|
2021-12-01 12:02:21 +01:00
|
|
|
def test_get_config_route(dummy_project, application_domain):
|
2021-09-02 17:01:36 +02:00
|
|
|
c = TestClient(application_domain)
|
2021-12-06 08:29:21 +01:00
|
|
|
r = c.get('/')
|
|
|
|
assert r.status_code == 200
|
|
|
|
pprint(r.json())
|
2021-11-30 18:31:40 +01:00
|
|
|
r = c.get('/config')
|
|
|
|
assert r.status_code == 200
|
|
|
|
pprint(r.json())
|
2021-09-02 17:01:36 +02:00
|
|
|
assert 'test' in r.json()
|
2021-11-30 18:31:40 +01:00
|
|
|
|
2021-12-01 12:02:21 +01:00
|
|
|
def test_get_route(dummy_project, application_domain):
|
2021-06-17 18:53:23 +02:00
|
|
|
c = TestClient(application_domain)
|
|
|
|
path = verb = params = None
|
2021-11-30 11:20:26 +01:00
|
|
|
dummy_domain_routes = [
|
|
|
|
('config','GET'),
|
|
|
|
('config','GET'),
|
2022-02-10 12:30:49 +01:00
|
|
|
('async_router/abc/pinnochio','GET'),
|
|
|
|
('async_router/config','GET'),
|
2021-11-30 11:20:26 +01:00
|
|
|
# ('abc/pinnochio','GET'),
|
|
|
|
# ('abc/alphabet','GET'),
|
|
|
|
]
|
|
|
|
|
2021-12-14 09:03:45 +01:00
|
|
|
for route_def in dummy_domain_routes:
|
2021-11-30 11:20:26 +01:00
|
|
|
path, verb = route_def[0], route_def[1]
|
2021-11-30 18:31:40 +01:00
|
|
|
route_path = '/{}'.format(path)
|
2021-11-30 11:20:26 +01:00
|
|
|
print(route_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)
|
2021-06-17 18:53:23 +02:00
|
|
|
try:
|
2021-11-30 11:20:26 +01:00
|
|
|
assert r.status_code in [200, 501]
|
|
|
|
except AssertionError as exc:
|
|
|
|
print('{} [{}] {}'.format(str(r.status_code), verb, route_path))
|
|
|
|
raise exc from exc
|
|
|
|
|
|
|
|
except NotImplementedError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
dummy_domain_path_routes = [
|
|
|
|
('abc/alphabet/{test}','GET'),
|
|
|
|
]
|
|
|
|
|
|
|
|
#for route_def in dummy_domain_path_routes:
|
|
|
|
for route_def in []:#dummy_domain_routes:
|
|
|
|
from uuid import uuid4
|
|
|
|
test_uuid = uuid4()
|
|
|
|
for route_def in dummy_domain_path_routes:
|
|
|
|
path, verb = route_def[0], route_def[1]
|
|
|
|
path = path.format(test=str(test_uuid))
|
2021-11-30 18:31:40 +01:00
|
|
|
route_path = f'/{path}'
|
2021-11-30 11:20:26 +01:00
|
|
|
if verb.lower() == 'get':
|
|
|
|
r = c.get(f'{route_path}')
|
|
|
|
|
|
|
|
assert r.status_code == 200
|
2021-06-25 12:20:25 +02:00
|
|
|
|
|
|
|
|
2021-12-01 12:02:21 +01:00
|
|
|
def test_delete_route(dummy_project, application_domain):
|
2021-06-25 12:20:25 +02:00
|
|
|
c = TestClient(application_domain)
|
|
|
|
from uuid import uuid4
|
|
|
|
arg = str(uuid4())
|
2021-11-30 18:31:40 +01:00
|
|
|
r = c.delete(f'/abc/alphabet/{arg}')
|
2021-06-25 12:20:25 +02:00
|
|
|
assert r.status_code == 200
|
2021-11-30 11:20:26 +01:00
|
|
|
assert isinstance(r.json(), str)
|
|
|
|
|
2021-12-01 12:02:21 +01:00
|
|
|
def test_arguments_route(dummy_project, application_domain):
|
2021-11-30 11:20:26 +01:00
|
|
|
c = TestClient(application_domain)
|
|
|
|
|
2021-11-30 18:31:40 +01:00
|
|
|
path = '/arguments'
|
2021-11-30 11:20:26 +01:00
|
|
|
r = c.get(path)
|
|
|
|
assert r.status_code == 400
|
|
|
|
r = c.get(path, params={'foo':True})
|
|
|
|
assert r.status_code == 400
|
|
|
|
arg = {'foo':True, 'bar':True}
|
|
|
|
r = c.get(path, params=arg)
|
|
|
|
assert r.status_code == 200
|
|
|
|
for key, val in arg.items():
|
|
|
|
assert r.json()[key] == str(val)
|
2022-02-10 12:30:49 +01:00
|
|
|
path = '/async_router/arguments'
|
2021-11-30 11:20:26 +01:00
|
|
|
r = c.get(path)
|
|
|
|
assert r.status_code == 400
|
|
|
|
r = c.get(path, params={'foo':True})
|
|
|
|
assert r.status_code == 400
|
|
|
|
arg = {'foo':True, 'bar':True}
|
|
|
|
r = c.get(path, params=arg)
|
|
|
|
assert r.status_code == 200
|
|
|
|
for key, val in arg.items():
|
|
|
|
assert r.json()[key] == str(val)
|
|
|
|
|