2021-06-17 18:53:23 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import importlib
|
|
|
|
import subprocess
|
|
|
|
import time
|
|
|
|
import pytest
|
2023-01-14 11:10:13 +01:00
|
|
|
import json
|
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)
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', '/')
|
2021-12-06 08:29:21 +01:00
|
|
|
assert r.status_code == 200
|
|
|
|
pprint(r.json())
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', '/config')
|
2021-11-30 18:31:40 +01:00
|
|
|
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':
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', route_path)
|
2021-11-30 11:20:26 +01:00
|
|
|
elif verb.lower() == 'post':
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('post', route_path)
|
2021-11-30 11:20:26 +01:00
|
|
|
elif verb.lower() == 'patch':
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('patch', route_path)
|
2021-11-30 11:20:26 +01:00
|
|
|
elif verb.lower() == 'put':
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('put', route_path)
|
2021-11-30 11:20:26 +01:00
|
|
|
elif verb.lower() == 'delete':
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('delete', route_path)
|
2021-11-30 11:20:26 +01:00
|
|
|
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':
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', f'{route_path}')
|
2021-11-30 11:20:26 +01:00
|
|
|
|
|
|
|
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())
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('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'
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', path)
|
2021-11-30 11:20:26 +01:00
|
|
|
assert r.status_code == 400
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', path, params={'foo':True})
|
2021-11-30 11:20:26 +01:00
|
|
|
assert r.status_code == 400
|
|
|
|
arg = {'foo':True, 'bar':True}
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', path, params=arg)
|
2021-11-30 11:20:26 +01:00
|
|
|
assert r.status_code == 200
|
|
|
|
for key, val in arg.items():
|
2023-01-14 11:10:13 +01:00
|
|
|
assert json.loads(r.json()[key]) == val
|
2022-02-10 12:30:49 +01:00
|
|
|
path = '/async_router/arguments'
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', path)
|
2021-11-30 11:20:26 +01:00
|
|
|
assert r.status_code == 400
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', path, params={'foo':True})
|
2021-11-30 11:20:26 +01:00
|
|
|
assert r.status_code == 400
|
|
|
|
arg = {'foo':True, 'bar':True}
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', path, params=arg)
|
2021-11-30 11:20:26 +01:00
|
|
|
assert r.status_code == 200
|
|
|
|
for key, val in arg.items():
|
2023-01-14 11:10:13 +01:00
|
|
|
assert json.loads(r.json()[key]) == val
|
2021-11-30 11:20:26 +01:00
|
|
|
|