halfapi/tests/test_debug_routes.py

66 lines
2.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import pytest
from starlette.authentication import UnauthenticatedUser
from starlette.testclient import TestClient
import subprocess
import json
import os
import sys
import pprint
from halfapi.lib.constants import API_SCHEMA
def test_halfapi_whoami(application_debug):
# @TODO : If we use isolated filesystem multiple times that creates a bug.
# So we use a single function with fixture "application debug"
[0.5.3] Squashed commit of the following: commit ac935db6d62656713183707707d083298c1f34b0 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Thu Jun 17 18:52:49 2021 +0200 [tests] remove dummy-domain from dependencies commit 4d50363c9b1502d1d8b7cbafc207e80cdbe247a4 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Thu Jun 17 18:52:18 2021 +0200 [tests] update tests for 0.5.3 commit 6181592692464d21de9807e1e890b4ac92efc387 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Thu Jun 17 18:17:51 2021 +0200 [lib.*] Refactor libs commit ed7485a8a16b60dde8acc0d2b9afca00a75fce3c Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Thu Jun 17 18:15:10 2021 +0200 [app] Use HalfAPI class to be able to use custom configuration à commit fa1ca6bf9df4ea17d7fa7dfdf3694c56746e9c7f Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Wed Jun 16 15:34:25 2021 +0200 [wip] tests dummy_domain commit 86e8dd3465e0bd0f3d49f28fd9e05a52874e969a Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Tue Jun 15 18:12:13 2021 +0200 [0.5.3] ajout de la config actuelle dans les arguments des routes commit aa7ec62c7a3b5a0ae0dc0cc79bd509eece44d5ff Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Tue Jun 15 11:16:23 2021 +0200 [lib.jwtMw] verify signature even if halfapi is in DEBUG mode commit e208728d7ec61b0de583c66c348f73ac7a884108 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Tue Jun 15 10:49:46 2021 +0200 [lib.acl] args_check doesn't check required/optional arguments if "args" is not specified in request, if the target function is not async commit aa4c309778e4c969fe1314da305e02112d4641b7 Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr> Date: Tue Jun 15 09:45:37 2021 +0200 [lib.domain] SUBROUTER can be a path parameter if including ":" commit 138420461d5c1ba0c7379dcda64e9a38aa5d768d Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Tue Jun 15 07:24:32 2021 +0200 [gitignore] *.swp commit 0c1e2849bad591d62f7399d820a044cf4e06de12 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Tue Jun 15 07:24:14 2021 +0200 [tests] test get route with dummy projects commit 7227e2d7f105516b67f3acac27b242fe01b59215 Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Mon Jun 14 17:18:47 2021 +0200 [lib.domain] handle modules without ROUTES attribute commit 78c75cd60ead023e7a2d7fa2e5d1059fada0044f Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr> Date: Mon Jun 14 16:34:58 2021 +0200 [tests] add dummy_project_router tests for path-based routers (without ROUTES variable)
2021-06-17 18:53:23 +02:00
c = TestClient(application_debug)
[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
r = c.request('get', '/halfapi/whoami')
assert r.status_code == 200
def test_halfapi_log(application_debug):
# @TODO : If we use isolated filesystem multiple times that creates a bug.
# So we use a single function with fixture "application debug"
c = TestClient(application_debug)
[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
r = c.request('get', '/halfapi/log')
assert r.status_code == 200
def test_halfapi_error_400(application_debug):
# @TODO : If we use isolated filesystem multiple times that creates a bug.
# So we use a single function with fixture "application debug"
c = TestClient(application_debug)
[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
r = c.request('get', '/halfapi/error/400')
assert r.status_code == 400
def test_halfapi_error_404(application_debug):
# @TODO : If we use isolated filesystem multiple times that creates a bug.
# So we use a single function with fixture "application debug"
c = TestClient(application_debug)
[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
r = c.request('get', '/halfapi/error/404')
assert r.status_code == 404
def test_halfapi_error_500(application_debug):
# @TODO : If we use isolated filesystem multiple times that creates a bug.
# So we use a single function with fixture "application debug"
c = TestClient(application_debug)
[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
r = c.request('get', '/halfapi/error/500')
assert r.status_code == 500
def test_schema(application_debug):
c = TestClient(application_debug)
[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
r = c.request('get', '/')
2021-12-08 16:45:00 +01:00
schemas = r.json()
assert isinstance(schemas, list)
for schema in schemas:
assert isinstance(schema, dict)
assert API_SCHEMA.validate(schema)