From c9639ddbc09483f0462e05e01b1d0e808bc9b237 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Tue, 30 Nov 2021 00:37:13 +0100 Subject: [PATCH] [constants] add lib "schema" Schemas for all items --- halfapi/lib/constants.py | 26 ++++++++++++++++++++++++++ tests/test_constants.py | 14 ++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/test_constants.py diff --git a/halfapi/lib/constants.py b/halfapi/lib/constants.py index 562c174..294fec9 100644 --- a/halfapi/lib/constants.py +++ b/halfapi/lib/constants.py @@ -1 +1,27 @@ +from schema import Schema, Optional + VERBS = ('GET', 'POST', 'PUT', 'PATCH', 'DELETE') + +ACLS_SCHEMA = Schema([{ + 'acl': str, + Optional('args'): { + Optional('required'): { str }, + Optional('optional'): { str } + }, + Optional('out'): { str } +}]) + +ROUTE_SCHEMA = Schema({ + str: { + 'docs': lambda n: True, # Should validate an openAPI spec + 'acls': ACLS_SCHEMA + } +}) + +DOMAIN_SCHEMA = Schema({ + str: ROUTE_SCHEMA +}) + +API_SCHEMA = Schema({ + str: DOMAIN_SCHEMA # key: domain name, value: result of lib.routes.api_routes(domain_module) +}) diff --git a/tests/test_constants.py b/tests/test_constants.py new file mode 100644 index 0000000..c9cd49c --- /dev/null +++ b/tests/test_constants.py @@ -0,0 +1,14 @@ +from schema import Schema +def test_constants(): + from halfapi.lib.constants import ( + VERBS, + ACLS_SCHEMA, + ROUTE_SCHEMA, + DOMAIN_SCHEMA, + API_SCHEMA) + + assert isinstance(VERBS, tuple) + assert isinstance(ACLS_SCHEMA, Schema) + assert isinstance(ROUTE_SCHEMA, Schema) + assert isinstance(DOMAIN_SCHEMA, Schema) + assert isinstance(API_SCHEMA, Schema)