Breaking : migrate your tests that use the TestDomain.client method following the instructions here https://github.com/Kludex/bump-testclient Squashed commit of the following: commit0417f27b3f
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 11:08:44 2023 +0100 [deps] starlette 0.23 commit552f00a65b
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:59:42 2023 +0100 [deps] starlette 0.22 commitaefe448717
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:55:45 2023 +0100 [tests][fix] compares the json interpreted value instead of the string commit01333a200c
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:55:20 2023 +0100 [testing] changes from requests to httpx for Starlette TestClient (breaks) commitf3784fab7f
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:54:10 2023 +0100 [deps][breaking] starlette 0.21 commit717d3f8bd6
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:26:31 2023 +0100 [responses] use a wrapper function for exception handling (fix starlette 0.20) commitd0876e45da
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:25:21 2023 +0100 [deps][breaking] starlette 0.20 commit6504191c53
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:12:51 2023 +0100 [deps] starlette 0.19 commit7b639a8dc2
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:11:14 2023 +0100 [deps] starlette 0.18 commit20bd9077a4
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:07:48 2023 +0100 pipenv update
77 lines
2.5 KiB
Python
77 lines
2.5 KiB
Python
import pytest
|
|
from halfapi.testing.test_domain import TestDomain
|
|
from pprint import pprint
|
|
|
|
class TestDummyDomain(TestDomain):
|
|
from .dummy_domain import domain
|
|
__name__ = domain.get('name')
|
|
__routers__ = domain.get('routers')
|
|
|
|
DOMAIN = __name__
|
|
CONFIG = {'test': True}
|
|
|
|
def test_domain(self):
|
|
self.check_domain()
|
|
|
|
def test_routes(self):
|
|
self.check_routes()
|
|
|
|
def test_html_route(self):
|
|
res = self.client.request('get', '/ret_type')
|
|
assert res.status_code == 200
|
|
assert isinstance(res.content.decode(), str)
|
|
assert res.headers['content-type'].split(';')[0] == 'text/html'
|
|
|
|
res = self.client.request('get', '/ret_type/h24')
|
|
assert res.status_code == 200
|
|
assert isinstance(res.content.decode(), str)
|
|
assert res.headers['content-type'].split(';')[0] == 'text/html'
|
|
|
|
res = self.client.request('get', '/ret_type/h24/config')
|
|
assert res.status_code == 200
|
|
assert isinstance(res.content.decode(), str)
|
|
assert res.headers['content-type'].split(';')[0] == 'text/html'
|
|
|
|
res = self.client.request('post', '/ret_type/h24/config', data={
|
|
'trou': 'glet'
|
|
})
|
|
assert res.status_code == 200
|
|
assert isinstance(res.content.decode(), str)
|
|
assert res.headers['content-type'].split(';')[0] == 'text/html'
|
|
|
|
def test_arguments__get_routes(self):
|
|
res = self.client.request('post', '/arguments?foo=1&x=3')
|
|
|
|
assert res.status_code == 400
|
|
|
|
arg_dict = {'foo': '1', 'bar': '2', 'x': '3'}
|
|
res = self.client.request('get', '/arguments?foo=1&bar=2&x=3')
|
|
assert res.json() == arg_dict
|
|
|
|
res = self.client.request('get', '/arguments?foo=1&bar=2&x=3&y=4')
|
|
assert res.json() == arg_dict
|
|
|
|
def test_arguments_post_routes(self):
|
|
arg_dict = {}
|
|
res = self.client.request('post', '/arguments', data=arg_dict)
|
|
|
|
assert res.status_code == 400
|
|
|
|
arg_dict = {'foo': '1', 'bar': '3'}
|
|
res = self.client.request('post', '/arguments', data=arg_dict)
|
|
|
|
assert res.status_code == 400
|
|
|
|
arg_dict = {'foo': '1', 'baz': '3'}
|
|
res = self.client.request('post', '/arguments', data=arg_dict)
|
|
|
|
assert res.json() == arg_dict
|
|
|
|
arg_dict = {'foo': '1', 'baz': '3', 'truebidoo': '4'}
|
|
res = self.client.request('post', '/arguments', data=arg_dict)
|
|
|
|
assert res.json() == arg_dict
|
|
|
|
res = self.client.request('post', '/arguments', data={ **arg_dict, 'y': '4'})
|
|
assert res.json() == arg_dict
|