Compare commits

...

5 Commits

Author SHA1 Message Date
Maxime Alves LIRMM 0417f27b3f [deps] starlette 0.23 2023-01-14 11:08:44 +01:00
Maxime Alves LIRMM 552f00a65b [deps] starlette 0.22 2023-01-14 10:59:42 +01:00
Maxime Alves LIRMM aefe448717 [tests][fix] compares the json interpreted value instead of the string 2023-01-14 10:55:45 +01:00
Maxime Alves LIRMM 01333a200c [testing] changes from requests to httpx for Starlette TestClient (breaks) 2023-01-14 10:55:20 +01:00
Maxime Alves LIRMM f3784fab7f [deps][breaking] starlette 0.21 2023-01-14 10:54:10 +01:00
10 changed files with 123 additions and 77 deletions

View File

@ -13,10 +13,11 @@ twine = "*"
pyflakes = "*"
vulture = "*"
virtualenv = "*"
httpx = "*"
[packages]
click = ">=7.1,<8"
starlette = ">=0.20,<0.21"
starlette = ">=0.23,<0.24"
uvicorn = ">=0.13,<1"
orjson = ">=3.4.7,<4"
pyjwt = ">=2.4.0,<2.5.0"

93
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "a2a5435583e5b41f8ad17fc5e0c4a4cd8fc8136cd991565c2e235f075f4473cd"
"sha256": "6d6f1c8ef59cdd627aad45dca178d112b02b529f11a2dcc3285f7ae0fea2de0d"
},
"pipfile-spec": 6,
"requires": {},
@ -203,11 +203,11 @@
},
"starlette": {
"hashes": [
"sha256:42fcf3122f998fefce3e2c5ad7e5edbf0f02cf685d646a83a08d404726af5084",
"sha256:c0414d5a56297d37f3db96a84034d61ce29889b9eaccf65eb98a0b39441fcaa3"
"sha256:8510e5b3d670326326c5c1d4cb657cc66832193fe5d5b7015a51c7b1e1b1bf42",
"sha256:ec69736c90be8dbfc6ec6800ba6feb79c8c44f9b1706c0b2bb27f936bcf362cc"
],
"index": "pypi",
"version": "==0.20.4"
"version": "==0.23.1"
},
"timing-asgi": {
"hashes": [
@ -235,6 +235,14 @@
}
},
"develop": {
"anyio": {
"hashes": [
"sha256:25ea0d673ae30af41a0c442f81cf3b38c7e79fdc7b60335a4c14e05eb0947421",
"sha256:fbbe32bd270d2a2ef3ed1c5d45041250284e31fc0a4df4a5a6071842051a51e3"
],
"markers": "python_full_version >= '3.6.2'",
"version": "==3.6.2"
},
"astroid": {
"hashes": [
"sha256:3bc7834720e1a24ca797fd785d77efb14f7a28ee8e635ef040b6e2d80ccb3303",
@ -256,7 +264,7 @@
"sha256:085f7f33c15bd408dd9b17a4ad77c577db66d76203e5984b1bd59baeee948b2a",
"sha256:0d03255c47eb9bd2f26aa9bb7f2107732e7e8fe195ca2f64709fcf3b0a4a085c"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==5.0.1"
},
"build": {
@ -494,7 +502,7 @@
"sha256:33995a6753c30b7f577febfc2c50411fec6aac7f7ffeb7c4cfe5991072dcf9e6",
"sha256:5e1de4d849fee02c63b040a4a3fd567f4ab104defd8a5511fbbc24a8a017efbc"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==0.19"
},
"exceptiongroup": {
@ -510,9 +518,33 @@
"sha256:7b319f24340b51f55a2bf7a12ac0755a9b03e718311dac567a0f4f7fabd2f5de",
"sha256:f58d535af89bb9ad5cd4df046f741f8553a418c01a7856bf0d173bbc9f6bd16d"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==3.9.0"
},
"h11": {
"hashes": [
"sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d",
"sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"
],
"markers": "python_version >= '3.7'",
"version": "==0.14.0"
},
"httpcore": {
"hashes": [
"sha256:c5d6f04e2fc530f39e0c077e6a30caa53f1451096120f1f38b954afd0b17c0cb",
"sha256:da1fb708784a938aa084bde4feb8317056c55037247c787bd7e19eb2c2949dc0"
],
"markers": "python_version >= '3.7'",
"version": "==0.16.3"
},
"httpx": {
"hashes": [
"sha256:9818458eb565bb54898ccb9b8b251a28785dd4a55afbc23d0eb410754fe7d0f9",
"sha256:a211fcce9b1254ea24f0cd6af9869b3d29aba40154e947d2a07bb499b3e310d6"
],
"index": "pypi",
"version": "==0.23.3"
},
"idna": {
"hashes": [
"sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4",
@ -526,7 +558,7 @@
"sha256:7efb448ec9a5e313a57655d35aa54cd3e01b7e1fbcf72dce1bf06119420f5bad",
"sha256:e354bedeb60efa6affdcc8ae121b73544a7aa74156d047311948f6d711cd378d"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==6.0.0"
},
"iniconfig": {
@ -534,7 +566,7 @@
"sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3",
"sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==2.0.0"
},
"isort": {
@ -542,7 +574,7 @@
"sha256:6db30c5ded9815d813932c04c2f85a360bcdd35fed496f4d8f35495ef0a261b6",
"sha256:c033fd0edb91000a7f09527fe5c75321878f98322a77ddcc81adbd83724afb7b"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==5.11.4"
},
"jaraco.classes": {
@ -550,7 +582,7 @@
"sha256:2353de3288bc6b82120752201c6b1c1a14b058267fa424ed5ce5984e3b922158",
"sha256:89559fa5c1d3c34eff6f631ad80bb21f378dbcbb35dd161fd2c6b93f5be2f98a"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==3.2.3"
},
"jeepney": {
@ -566,7 +598,7 @@
"sha256:771ed2a91909389ed6148631de678f82ddc73737d85a927f382a8a1b157898cd",
"sha256:ba2e15a9b35e21908d0aaf4e0a47acc52d6ae33444df0da2b49d41a46ef6d678"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==23.13.1"
},
"lazy-object-proxy": {
@ -608,7 +640,7 @@
"sha256:f2457189d8257dd41ae9b434ba33298aec198e30adf2dcdaaa3a28b9994f6adb",
"sha256:f699ac1c768270c9e384e4cbd268d6e67aebcfae6cd623b4d7c3bfde5a35db59"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==1.9.0"
},
"mccabe": {
@ -624,7 +656,7 @@
"sha256:250e83d7e81d0c87ca6bd942e6aeab8cc9daa6096d12c5308f3f92fa5e5c1f41",
"sha256:5a6257e40878ef0520b1803990e3e22303a41b5714006c32a3fd8304b26ea1ab"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==9.0.0"
},
"packaging": {
@ -648,7 +680,7 @@
"sha256:83c8f6d04389165de7c9b6f0c682439697887bca0aa2f1c87ef1826be3584490",
"sha256:e1fea1fe471b9ff8332e229df3cb7de4f53eeea4998d3b6bfff542115e998bd2"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==2.6.2"
},
"pluggy": {
@ -695,7 +727,7 @@
"sha256:283c11acd6b928d2f6a7c73fa0d01cb2bdc5f07c57a2eeb6e83d5e56b97976f8",
"sha256:f271b298b97f5955d53fb12b72c1fb1948c22c1a6b70b315c54cedaca0264ef5"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==1.0.0"
},
"pytest": {
@ -719,7 +751,7 @@
"sha256:cd653186dfc73055656f090f227f5cb22a046d7f71a841dfa305f55c9a513273",
"sha256:f67a16caedfa71eef48a31b39708637a6f4664c4394801a7b0d6432d13907343"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==37.3"
},
"requests": {
@ -739,19 +771,22 @@
"version": "==0.10.1"
},
"rfc3986": {
"hashes": [
"sha256:50b1502b60e289cb37883f3dfd34532b8873c7de9f49bb546641ce9cbd256ebd",
"sha256:97aacf9dbd4bfd829baad6e6309fa6573aaf1be3f6fa735c8ab05e46cecb261c"
"extras": [
"idna2008"
],
"markers": "python_full_version >= '3.7.0'",
"version": "==2.0.0"
"hashes": [
"sha256:270aaf10d87d0d4e095063c65bf3ddbc6ee3d0b226328ce21e036f946e421835",
"sha256:a86d6e1f5b1dc238b218b012df0aa79409667bb209e58da56d0b94704e712a97"
],
"markers": "python_version >= '3.7'",
"version": "==1.5.0"
},
"rich": {
"hashes": [
"sha256:25f83363f636995627a99f6e4abc52ed0970ebbd544960cc63cbb43aaac3d6f0",
"sha256:41fe1d05f433b0f4724cda8345219213d2bfa472ef56b2f64f415b5b94d51b04"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==13.0.1"
},
"secretstorage": {
@ -770,6 +805,14 @@
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==1.16.0"
},
"sniffio": {
"hashes": [
"sha256:e60305c5e5d314f5389259b7f22aaa33d8f7dee49763119234af3755c55b9101",
"sha256:eecefdce1e5bbfb7ad2eeaabf7c1eeb404d7757c379bd1f7e5cce9d8bf425384"
],
"markers": "python_version >= '3.7'",
"version": "==1.3.0"
},
"toml": {
"hashes": [
"sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b",
@ -807,7 +850,7 @@
"sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa",
"sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==4.4.0"
},
"urllib3": {
@ -916,7 +959,7 @@
"sha256:83a28fcb75844b5c0cdaf5aa4003c2d728c77e05f5aeabe8e95e56727005fbaa",
"sha256:a7a22e05929290a67401440b39690ae6563279bced5f314609d9d03798f56766"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==3.11.0"
}
}

View File

@ -120,7 +120,7 @@ class TestDomain(TestCase):
return result_d
def check_routes(self):
r = self.client.get('/')
r = self.client.request('get', '/')
assert r.status_code == 200
schemas = r.json()
assert isinstance(schemas, list)
@ -131,7 +131,7 @@ class TestDomain(TestCase):
assert 'paths' in schema
assert 'domain' in schema
r = self.client.get('/halfapi/acls')
r = self.client.request('get', '/halfapi/acls')
"""
assert r.status_code == 200
d_r = r.json()

View File

@ -44,7 +44,7 @@ setup(
python_requires=">=3.8",
install_requires=[
"PyJWT>=2.4.0,<2.5.0",
"starlette>=0.20,<0.21",
"starlette>=0.23,<0.24",
"click>=7.1,<8",
"uvicorn>=0.13,<1",
"orjson>=3.4.7,<4",
@ -68,9 +68,10 @@ setup(
extras_require={
"tests":[
"pytest>=7,<8",
"requests",
"pytest-asyncio",
"pylint"
"pylint",
"requests",
"httpx"
],
"pyexcel":[
"pyexcel",

View File

@ -17,7 +17,7 @@ def test_acl_Check(dummy_app, token_debug_false_builder):
dummy_app.add_route('/test_public', test_route_public)
test_client = TestClient(dummy_app)
resp = test_client.get('/test_public?check')
resp = test_client.request('get', '/test_public?check')
assert resp.status_code == 200
@HalfRoute.acl_decorator(params=[{'acl':acl.private}])
@ -28,10 +28,10 @@ def test_acl_Check(dummy_app, token_debug_false_builder):
dummy_app.add_route('/test_private', test_route_private)
test_client = TestClient(dummy_app)
resp = test_client.get('/test_private')
resp = test_client.request('get', '/test_private')
assert resp.status_code == 401
resp = test_client.get('/test_private?check')
resp = test_client.request('get', '/test_private?check')
assert resp.status_code == 200

View File

@ -15,7 +15,7 @@ def test_halfapi_whoami(application_debug):
# So we use a single function with fixture "application debug"
c = TestClient(application_debug)
r = c.get('/halfapi/whoami')
r = c.request('get', '/halfapi/whoami')
assert r.status_code == 200
def test_halfapi_log(application_debug):
@ -24,7 +24,7 @@ def test_halfapi_log(application_debug):
c = TestClient(application_debug)
r = c.get('/halfapi/log')
r = c.request('get', '/halfapi/log')
assert r.status_code == 200
def test_halfapi_error_400(application_debug):
@ -33,7 +33,7 @@ def test_halfapi_error_400(application_debug):
c = TestClient(application_debug)
r = c.get('/halfapi/error/400')
r = c.request('get', '/halfapi/error/400')
assert r.status_code == 400
def test_halfapi_error_404(application_debug):
@ -42,7 +42,7 @@ def test_halfapi_error_404(application_debug):
c = TestClient(application_debug)
r = c.get('/halfapi/error/404')
r = c.request('get', '/halfapi/error/404')
assert r.status_code == 404
def test_halfapi_error_500(application_debug):
@ -51,13 +51,13 @@ def test_halfapi_error_500(application_debug):
c = TestClient(application_debug)
r = c.get('/halfapi/error/500')
r = c.request('get', '/halfapi/error/500')
assert r.status_code == 500
def test_schema(application_debug):
c = TestClient(application_debug)
r = c.get('/')
r = c.request('get', '/')
schemas = r.json()
assert isinstance(schemas, list)
for schema in schemas:

View File

@ -17,22 +17,22 @@ class TestDummyDomain(TestDomain):
self.check_routes()
def test_html_route(self):
res = self.client.get('/ret_type')
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.get('/ret_type/h24')
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.get('/ret_type/h24/config')
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.post('/ret_type/h24/config', {
res = self.client.request('post', '/ret_type/h24/config', data={
'trou': 'glet'
})
assert res.status_code == 200
@ -40,37 +40,37 @@ class TestDummyDomain(TestDomain):
assert res.headers['content-type'].split(';')[0] == 'text/html'
def test_arguments__get_routes(self):
res = self.client.post('/arguments?foo=1&x=3')
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.get('/arguments?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.get('/arguments?foo=1&bar=2&x=3&y=4')
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.post('/arguments', 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.post('/arguments', arg_dict)
res = self.client.request('post', '/arguments', data=arg_dict)
assert res.status_code == 400
arg_dict = {'foo': '1', 'baz': '3'}
res = self.client.post('/arguments', arg_dict)
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.post('/arguments', arg_dict)
res = self.client.request('post', '/arguments', data=arg_dict)
assert res.json() == arg_dict
res = self.client.post('/arguments', { **arg_dict, 'y': '4'})
res = self.client.request('post', '/arguments', data={ **arg_dict, 'y': '4'})
assert res.json() == arg_dict

View File

@ -4,16 +4,17 @@ import importlib
import subprocess
import time
import pytest
import json
from pprint import pprint
from starlette.routing import Route
from starlette.testclient import TestClient
def test_get_config_route(dummy_project, application_domain):
c = TestClient(application_domain)
r = c.get('/')
r = c.request('get', '/')
assert r.status_code == 200
pprint(r.json())
r = c.get('/config')
r = c.request('get', '/config')
assert r.status_code == 200
pprint(r.json())
assert 'test' in r.json()
@ -36,15 +37,15 @@ def test_get_route(dummy_project, application_domain):
print(route_path)
try:
if verb.lower() == 'get':
r = c.get(route_path)
r = c.request('get', route_path)
elif verb.lower() == 'post':
r = c.post(route_path)
r = c.request('post', route_path)
elif verb.lower() == 'patch':
r = c.patch(route_path)
r = c.request('patch', route_path)
elif verb.lower() == 'put':
r = c.put(route_path)
r = c.request('put', route_path)
elif verb.lower() == 'delete':
r = c.delete(route_path)
r = c.request('delete', route_path)
else:
raise Exception(verb)
try:
@ -69,7 +70,7 @@ def test_get_route(dummy_project, application_domain):
path = path.format(test=str(test_uuid))
route_path = f'/{path}'
if verb.lower() == 'get':
r = c.get(f'{route_path}')
r = c.request('get', f'{route_path}')
assert r.status_code == 200
@ -78,7 +79,7 @@ def test_delete_route(dummy_project, application_domain):
c = TestClient(application_domain)
from uuid import uuid4
arg = str(uuid4())
r = c.delete(f'/abc/alphabet/{arg}')
r = c.request('delete', f'/abc/alphabet/{arg}')
assert r.status_code == 200
assert isinstance(r.json(), str)
@ -86,23 +87,23 @@ def test_arguments_route(dummy_project, application_domain):
c = TestClient(application_domain)
path = '/arguments'
r = c.get(path)
r = c.request('get', path)
assert r.status_code == 400
r = c.get(path, params={'foo':True})
r = c.request('get', path, params={'foo':True})
assert r.status_code == 400
arg = {'foo':True, 'bar':True}
r = c.get(path, params=arg)
r = c.request('get', path, params=arg)
assert r.status_code == 200
for key, val in arg.items():
assert r.json()[key] == str(val)
assert json.loads(r.json()[key]) == val
path = '/async_router/arguments'
r = c.get(path)
r = c.request('get', path)
assert r.status_code == 400
r = c.get(path, params={'foo':True})
r = c.request('get', path, params={'foo':True})
assert r.status_code == 400
arg = {'foo':True, 'bar':True}
r = c.get(path, params=arg)
r = c.request('get', path, params=arg)
assert r.status_code == 200
for key, val in arg.items():
assert r.json()[key] == str(val)
assert json.loads(r.json()[key]) == val

View File

@ -38,7 +38,7 @@ def test_jwt_NoToken(dummy_app):
dummy_app.add_route('/test', test_route)
test_client = TestClient(dummy_app)
resp = test_client.get('/test')
resp = test_client.request('get', '/test')
assert resp.status_code == 200
def test_jwt_Token(dummy_app, token_builder):
@ -50,7 +50,7 @@ def test_jwt_Token(dummy_app, token_builder):
dummy_app.add_route('/test', test_route)
test_client = TestClient(dummy_app)
resp = test_client.get('/test',
resp = test_client.request('get', '/test',
headers={
'Authorization': token_builder
})
@ -65,7 +65,7 @@ def test_jwt_DebugFalse(dummy_app, token_debug_false_builder):
dummy_app.add_route('/test', test_route)
test_client = TestClient(dummy_app)
resp = test_client.get('/test',
resp = test_client.request('get', '/test',
headers={
'Authorization': token_debug_false_builder
})
@ -82,7 +82,7 @@ def test_jwt_DebugTrue(dummy_app, token_debug_true_builder):
dummy_app.add_route('/test', test_route)
test_client = TestClient(dummy_app)
resp = test_client.get('/test',
resp = test_client.request('get', '/test',
headers={
'Authorization': token_debug_true_builder
})
@ -100,7 +100,7 @@ def test_jwt_DebugTrue_DebugApp(dummy_debug_app, token_debug_true_builder):
dummy_debug_app.add_route('/test', test_route)
test_client = TestClient(dummy_debug_app)
resp = test_client.get('/test',
resp = test_client.request('get', '/test',
headers={
'Authorization': token_debug_true_builder
})

View File

@ -12,12 +12,12 @@ def test_init():
def test_call(application_debug):
c = TestClient(application_debug)
r = c.get('/abc/alphabet')
r = c.request('get', '/abc/alphabet')
assert r.status_code == 200
assert r.headers['x-domain'] == 'dummy_domain'
assert r.headers['x-acl'] == 'public'
r = c.get('/arguments')
r = c.request('get', '/arguments')
assert r.status_code == 400
assert r.headers['x-domain'] == 'dummy_domain'
assert r.headers['x-acl'] == 'public'
@ -26,7 +26,7 @@ def test_call(application_debug):
assert r.headers['x-args-optional'] == 'x'
c = TestClient(application_debug)
r = c.post('/arguments')
r = c.request('post', '/arguments')
assert r.status_code == 400
assert r.headers['x-domain'] == 'dummy_domain'
assert r.headers['x-acl'] == 'public'