halfapi/tests/test_domain.py

80 lines
2.7 KiB
Python
Raw Normal View History

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__
2022-08-08 20:01:48 +02:00
CONFIG = {'test': True}
def test_domain(self):
self.check_domain()
def test_routes(self):
self.check_routes()
def test_html_route(self):
[deps] Migration from starlette v0.18 to v0.23 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: commit 0417f27b3f8de4334b2af3d9341288956cbc60fc Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 11:08:44 2023 +0100 [deps] starlette 0.23 commit 552f00a65b263e7255944088f7e9aec9e9943515 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:59:42 2023 +0100 [deps] starlette 0.22 commit aefe448717717d36b536c9142b6b4a888950b819 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 commit 01333a200c98f05539ab6b26985c4207b7b03442 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) commit f3784fab7f1e5449d72ce69b6223768d579ffa28 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:54:10 2023 +0100 [deps][breaking] starlette 0.21 commit 717d3f8bd64bc654b150ae7294a298745acbd4b3 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) commit d0876e45dae235a49d4c4ea5df9edba884648d60 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:25:21 2023 +0100 [deps][breaking] starlette 0.20 commit 6504191c535da38b6cf7d7c717606660b8327795 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:12:51 2023 +0100 [deps] starlette 0.19 commit 7b639a8dc2a504cd31d4c3a5ab37ce20c5e1b6c5 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:11:14 2023 +0100 [deps] starlette 0.18 commit 20bd9077a474f634b619bc721af03901e4757237 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:07:48 2023 +0100 pipenv update
2023-01-14 11:10:13 +01:00
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'
2022-08-31 00:12:37 +02:00
[deps] Migration from starlette v0.18 to v0.23 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: commit 0417f27b3f8de4334b2af3d9341288956cbc60fc Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 11:08:44 2023 +0100 [deps] starlette 0.23 commit 552f00a65b263e7255944088f7e9aec9e9943515 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:59:42 2023 +0100 [deps] starlette 0.22 commit aefe448717717d36b536c9142b6b4a888950b819 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 commit 01333a200c98f05539ab6b26985c4207b7b03442 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) commit f3784fab7f1e5449d72ce69b6223768d579ffa28 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:54:10 2023 +0100 [deps][breaking] starlette 0.21 commit 717d3f8bd64bc654b150ae7294a298745acbd4b3 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) commit d0876e45dae235a49d4c4ea5df9edba884648d60 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:25:21 2023 +0100 [deps][breaking] starlette 0.20 commit 6504191c535da38b6cf7d7c717606660b8327795 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:12:51 2023 +0100 [deps] starlette 0.19 commit 7b639a8dc2a504cd31d4c3a5ab37ce20c5e1b6c5 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:11:14 2023 +0100 [deps] starlette 0.18 commit 20bd9077a474f634b619bc721af03901e4757237 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:07:48 2023 +0100 pipenv update
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'
[deps] Migration from starlette v0.18 to v0.23 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: commit 0417f27b3f8de4334b2af3d9341288956cbc60fc Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 11:08:44 2023 +0100 [deps] starlette 0.23 commit 552f00a65b263e7255944088f7e9aec9e9943515 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:59:42 2023 +0100 [deps] starlette 0.22 commit aefe448717717d36b536c9142b6b4a888950b819 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 commit 01333a200c98f05539ab6b26985c4207b7b03442 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) commit f3784fab7f1e5449d72ce69b6223768d579ffa28 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:54:10 2023 +0100 [deps][breaking] starlette 0.21 commit 717d3f8bd64bc654b150ae7294a298745acbd4b3 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) commit d0876e45dae235a49d4c4ea5df9edba884648d60 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:25:21 2023 +0100 [deps][breaking] starlette 0.20 commit 6504191c535da38b6cf7d7c717606660b8327795 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:12:51 2023 +0100 [deps] starlette 0.19 commit 7b639a8dc2a504cd31d4c3a5ab37ce20c5e1b6c5 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:11:14 2023 +0100 [deps] starlette 0.18 commit 20bd9077a474f634b619bc721af03901e4757237 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:07:48 2023 +0100 pipenv update
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'
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'
def test_arguments__get_routes(self):
[deps] Migration from starlette v0.18 to v0.23 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: commit 0417f27b3f8de4334b2af3d9341288956cbc60fc Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 11:08:44 2023 +0100 [deps] starlette 0.23 commit 552f00a65b263e7255944088f7e9aec9e9943515 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:59:42 2023 +0100 [deps] starlette 0.22 commit aefe448717717d36b536c9142b6b4a888950b819 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 commit 01333a200c98f05539ab6b26985c4207b7b03442 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) commit f3784fab7f1e5449d72ce69b6223768d579ffa28 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:54:10 2023 +0100 [deps][breaking] starlette 0.21 commit 717d3f8bd64bc654b150ae7294a298745acbd4b3 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) commit d0876e45dae235a49d4c4ea5df9edba884648d60 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:25:21 2023 +0100 [deps][breaking] starlette 0.20 commit 6504191c535da38b6cf7d7c717606660b8327795 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:12:51 2023 +0100 [deps] starlette 0.19 commit 7b639a8dc2a504cd31d4c3a5ab37ce20c5e1b6c5 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:11:14 2023 +0100 [deps] starlette 0.18 commit 20bd9077a474f634b619bc721af03901e4757237 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:07:48 2023 +0100 pipenv update
2023-01-14 11:10:13 +01:00
res = self.client.request('post', '/arguments?foo=1&x=3')
assert res.status_code == 400
arg_dict = {'foo': '1', 'bar': '2', 'x': '3'}
[deps] Migration from starlette v0.18 to v0.23 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: commit 0417f27b3f8de4334b2af3d9341288956cbc60fc Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 11:08:44 2023 +0100 [deps] starlette 0.23 commit 552f00a65b263e7255944088f7e9aec9e9943515 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:59:42 2023 +0100 [deps] starlette 0.22 commit aefe448717717d36b536c9142b6b4a888950b819 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 commit 01333a200c98f05539ab6b26985c4207b7b03442 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) commit f3784fab7f1e5449d72ce69b6223768d579ffa28 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:54:10 2023 +0100 [deps][breaking] starlette 0.21 commit 717d3f8bd64bc654b150ae7294a298745acbd4b3 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) commit d0876e45dae235a49d4c4ea5df9edba884648d60 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:25:21 2023 +0100 [deps][breaking] starlette 0.20 commit 6504191c535da38b6cf7d7c717606660b8327795 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:12:51 2023 +0100 [deps] starlette 0.19 commit 7b639a8dc2a504cd31d4c3a5ab37ce20c5e1b6c5 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:11:14 2023 +0100 [deps] starlette 0.18 commit 20bd9077a474f634b619bc721af03901e4757237 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:07:48 2023 +0100 pipenv update
2023-01-14 11:10:13 +01:00
res = self.client.request('get', '/arguments?foo=1&bar=2&x=3')
assert res.json() == arg_dict
[deps] Migration from starlette v0.18 to v0.23 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: commit 0417f27b3f8de4334b2af3d9341288956cbc60fc Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 11:08:44 2023 +0100 [deps] starlette 0.23 commit 552f00a65b263e7255944088f7e9aec9e9943515 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:59:42 2023 +0100 [deps] starlette 0.22 commit aefe448717717d36b536c9142b6b4a888950b819 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 commit 01333a200c98f05539ab6b26985c4207b7b03442 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) commit f3784fab7f1e5449d72ce69b6223768d579ffa28 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:54:10 2023 +0100 [deps][breaking] starlette 0.21 commit 717d3f8bd64bc654b150ae7294a298745acbd4b3 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) commit d0876e45dae235a49d4c4ea5df9edba884648d60 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:25:21 2023 +0100 [deps][breaking] starlette 0.20 commit 6504191c535da38b6cf7d7c717606660b8327795 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:12:51 2023 +0100 [deps] starlette 0.19 commit 7b639a8dc2a504cd31d4c3a5ab37ce20c5e1b6c5 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:11:14 2023 +0100 [deps] starlette 0.18 commit 20bd9077a474f634b619bc721af03901e4757237 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Sat Jan 14 10:07:48 2023 +0100 pipenv update
2023-01-14 11:10:13 +01:00
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', json=arg_dict)
assert res.status_code == 400
arg_dict = {'foo': '1', 'bar': '3'}
res = self.client.request('post', '/arguments', json=arg_dict)
assert res.status_code == 400
arg_dict = {'foo': '1', 'baz': '3'}
res = self.client.request('post', '/arguments', json=arg_dict)
assert res.json() == arg_dict
arg_dict = {'foo': '1', 'baz': '3', 'truebidoo': '4'}
res = self.client.request('post', '/arguments', json=arg_dict)
assert res.json() == arg_dict
res = self.client.request('post', '/arguments', json={ **arg_dict, 'y': '4'})
assert res.json() == arg_dict
res = self.client.request('post', '/arguments', json={ **arg_dict, 'z': True})
assert res.json() == {**arg_dict, 'z': True}