Squashed commit of the following:

commit 4552d85cc49fda572e54aa9c8054031554bfcb3a
Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr>
Date:   Thu Oct 7 13:57:37 2021 +0200

    [0.5.13]

commit 38032acfac559155b31c12cf12673c81b7cfdf20
Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr>
Date:   Thu Oct 7 13:57:12 2021 +0200

    add 503 error code

commit 6f516e844b0f3786aa571d1ac8d575247ff7b7fe
Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr>
Date:   Thu Oct 7 13:26:15 2021 +0200

    [ci] add run halfapi --version
This commit is contained in:
Maxime Alves LIRMM@home 2021-10-07 13:58:03 +02:00
parent 8b88d7f1b4
commit c99e636d6e
5 changed files with 50 additions and 5 deletions

View File

@ -31,6 +31,7 @@ before_script:
test: test:
script: script:
- pipenv run pytest -v - pipenv run pytest -v
- pipenv run halfapi --version
run: run:
script: script:

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
__version__ = '0.5.12' __version__ = '0.5.13'
def version(): def version():
return f'HalfAPI version:{__version__}' return f'HalfAPI version:{__version__}'

View File

@ -31,7 +31,8 @@ from .lib.timing import HTimingClient
from halfapi.lib.jwt_middleware import JWTAuthenticationBackend from halfapi.lib.jwt_middleware import JWTAuthenticationBackend
from halfapi.lib.responses import (ORJSONResponse, UnauthorizedResponse, from halfapi.lib.responses import (ORJSONResponse, UnauthorizedResponse,
NotFoundResponse, InternalServerErrorResponse, NotImplementedResponse) NotFoundResponse, InternalServerErrorResponse, NotImplementedResponse,
ServiceUnavailableResponse)
from halfapi.lib.routes import gen_starlette_routes, debug_routes from halfapi.lib.routes import gen_starlette_routes, debug_routes
from halfapi.lib.schemas import get_api_routes, get_api_domain_routes, schema_json, get_acls from halfapi.lib.schemas import get_api_routes, get_api_domain_routes, schema_json, get_acls
@ -88,7 +89,8 @@ class HalfAPI:
401: UnauthorizedResponse, 401: UnauthorizedResponse,
404: NotFoundResponse, 404: NotFoundResponse,
500: InternalServerErrorResponse, 500: InternalServerErrorResponse,
501: NotImplementedResponse 501: NotImplementedResponse,
503: ServiceUnavailableResponse
} }
) )

View File

@ -11,6 +11,7 @@ Classes :
- NotImplementedResponse - NotImplementedResponse
- ORJSONResponse - ORJSONResponse
- PlainTextResponse - PlainTextResponse
- ServiceUnavailableResponse
- UnauthorizedResponse - UnauthorizedResponse
""" """
@ -31,6 +32,7 @@ __all__ = [
'NotImplementedResponse', 'NotImplementedResponse',
'ORJSONResponse', 'ORJSONResponse',
'PlainTextResponse', 'PlainTextResponse',
'ServiceUnavailableResponse',
'UnauthorizedResponse'] 'UnauthorizedResponse']
@ -54,6 +56,11 @@ class NotImplementedResponse(Response):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(status_code=501) super().__init__(status_code=501)
class ServiceUnavailableResponse(Response):
""" The 503 Service Unavailable default Response
"""
def __init__(self, *args, **kwargs):
super().__init__(status_code=503)
class UnauthorizedResponse(Response): class UnauthorizedResponse(Response):
""" The 401 Not Found default Response """ The 401 Not Found default Response

View File

@ -2,8 +2,8 @@ import json
import decimal import decimal
import datetime import datetime
from halfapi.lib.responses import ORJSONResponse from starlette.responses import Response
from halfapi.lib.responses import *
def test_orjson(): def test_orjson():
test_obj = { test_obj = {
@ -25,3 +25,38 @@ def test_orjson():
assert isinstance(test_obj_dec['date'], str) assert isinstance(test_obj_dec['date'], str)
assert test_obj_dec['date'] == '0001-01-01' assert test_obj_dec['date'] == '0001-01-01'
assert test_obj_dec['datetime'] == '0001-01-01T00:00:00' assert test_obj_dec['datetime'] == '0001-01-01T00:00:00'
def test_responses():
resp = HJSONResponse('')
assert isinstance(resp, Response)
assert resp.status_code == 200
resp = ORJSONResponse('')
assert isinstance(resp, Response)
assert resp.status_code == 200
resp = PlainTextResponse()
assert isinstance(resp, Response)
assert resp.status_code == 200
def test_errors():
resp = ServiceUnavailableResponse()
assert isinstance(resp, Response)
assert resp.status_code == 503
resp = UnauthorizedResponse()
assert isinstance(resp, Response)
assert resp.status_code == 401
resp = InternalServerErrorResponse()
assert isinstance(resp, Response)
assert resp.status_code == 500
resp = NotFoundResponse()
assert isinstance(resp, Response)
assert resp.status_code == 404
resp = NotImplementedResponse()
assert isinstance(resp, Response)
assert resp.status_code == 501