2022-08-18 20:19:36 +02:00
|
|
|
import pytest
|
2021-12-01 17:02:23 +01:00
|
|
|
from halfapi.testing.test_domain import TestDomain
|
|
|
|
from pprint import pprint
|
|
|
|
|
|
|
|
class TestDummyDomain(TestDomain):
|
2022-10-13 12:13:37 +02:00
|
|
|
from .dummy_domain import domain
|
|
|
|
__name__ = domain.get('name')
|
|
|
|
__routers__ = domain.get('routers')
|
2022-02-10 11:59:40 +01:00
|
|
|
|
2021-12-01 17:02:23 +01:00
|
|
|
DOMAIN = __name__
|
2022-08-08 20:01:48 +02:00
|
|
|
CONFIG = {'test': True}
|
2021-12-01 17:02:23 +01:00
|
|
|
|
|
|
|
def test_domain(self):
|
|
|
|
self.check_domain()
|
2021-12-04 09:56:14 +01:00
|
|
|
|
|
|
|
def test_routes(self):
|
|
|
|
self.check_routes()
|
2022-08-18 20:19:36 +02:00
|
|
|
|
|
|
|
def test_html_route(self):
|
2023-01-14 11:10:13 +01:00
|
|
|
res = self.client.request('get', '/ret_type')
|
2022-08-18 20:19:36 +02:00
|
|
|
assert res.status_code == 200
|
|
|
|
assert isinstance(res.content.decode(), str)
|
|
|
|
assert res.headers['content-type'].split(';')[0] == 'text/html'
|
2022-08-31 00:12:37 +02:00
|
|
|
|
2023-01-14 11:10:13 +01:00
|
|
|
res = self.client.request('get', '/ret_type/h24')
|
2022-08-31 00:12:37 +02:00
|
|
|
assert res.status_code == 200
|
|
|
|
assert isinstance(res.content.decode(), str)
|
|
|
|
assert res.headers['content-type'].split(';')[0] == 'text/html'
|
|
|
|
|
2023-01-14 11:10:13 +01:00
|
|
|
res = self.client.request('get', '/ret_type/h24/config')
|
2022-08-31 00:12:37 +02:00
|
|
|
assert res.status_code == 200
|
|
|
|
assert isinstance(res.content.decode(), str)
|
|
|
|
assert res.headers['content-type'].split(';')[0] == 'text/html'
|
|
|
|
|
2023-02-21 19:23:23 +01:00
|
|
|
res = self.client.request('post', '/ret_type/h24/config', json={
|
2022-08-31 00:12:37 +02:00
|
|
|
'trou': 'glet'
|
|
|
|
})
|
|
|
|
assert res.status_code == 200
|
|
|
|
assert isinstance(res.content.decode(), str)
|
|
|
|
assert res.headers['content-type'].split(';')[0] == 'text/html'
|
2022-09-05 10:12:47 +02:00
|
|
|
|
|
|
|
def test_arguments__get_routes(self):
|
2023-01-14 11:10:13 +01:00
|
|
|
res = self.client.request('post', '/arguments?foo=1&x=3')
|
2022-09-05 10:18:57 +02:00
|
|
|
|
|
|
|
assert res.status_code == 400
|
|
|
|
|
2022-09-05 10:12:47 +02:00
|
|
|
arg_dict = {'foo': '1', 'bar': '2', 'x': '3'}
|
2023-01-14 11:10:13 +01:00
|
|
|
res = self.client.request('get', '/arguments?foo=1&bar=2&x=3')
|
2022-09-05 10:12:47 +02:00
|
|
|
assert res.json() == arg_dict
|
|
|
|
|
2023-01-14 11:10:13 +01:00
|
|
|
res = self.client.request('get', '/arguments?foo=1&bar=2&x=3&y=4')
|
2022-09-05 10:12:47 +02:00
|
|
|
assert res.json() == arg_dict
|
|
|
|
|
|
|
|
def test_arguments_post_routes(self):
|
2022-09-05 10:18:57 +02:00
|
|
|
arg_dict = {}
|
2023-02-21 19:23:23 +01:00
|
|
|
res = self.client.request('post', '/arguments', json=arg_dict)
|
2022-09-05 10:18:57 +02:00
|
|
|
|
|
|
|
assert res.status_code == 400
|
|
|
|
|
|
|
|
arg_dict = {'foo': '1', 'bar': '3'}
|
2023-02-21 19:23:23 +01:00
|
|
|
res = self.client.request('post', '/arguments', json=arg_dict)
|
2022-09-05 10:18:57 +02:00
|
|
|
|
|
|
|
assert res.status_code == 400
|
|
|
|
|
|
|
|
arg_dict = {'foo': '1', 'baz': '3'}
|
2023-02-21 19:23:23 +01:00
|
|
|
res = self.client.request('post', '/arguments', json=arg_dict)
|
2022-09-05 10:18:57 +02:00
|
|
|
|
|
|
|
assert res.json() == arg_dict
|
|
|
|
|
|
|
|
arg_dict = {'foo': '1', 'baz': '3', 'truebidoo': '4'}
|
2023-02-21 19:23:23 +01:00
|
|
|
res = self.client.request('post', '/arguments', json=arg_dict)
|
2022-09-05 10:12:47 +02:00
|
|
|
|
|
|
|
assert res.json() == arg_dict
|
|
|
|
|
2023-02-21 19:23:23 +01:00
|
|
|
res = self.client.request('post', '/arguments', json={ **arg_dict, 'y': '4'})
|
2022-09-05 10:12:47 +02:00
|
|
|
assert res.json() == arg_dict
|
2023-02-21 19:23:23 +01:00
|
|
|
|
|
|
|
res = self.client.request('post', '/arguments', json={ **arg_dict, 'z': True})
|
|
|
|
assert res.json() == {**arg_dict, 'z': True}
|