[constants] add lib "schema" Schemas for all items

This commit is contained in:
Maxime Alves LIRMM 2021-11-30 00:37:13 +01:00
parent 24bd3f5653
commit c9639ddbc0
2 changed files with 40 additions and 0 deletions

View File

@ -1 +1,27 @@
from schema import Schema, Optional
VERBS = ('GET', 'POST', 'PUT', 'PATCH', 'DELETE') 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)
})

14
tests/test_constants.py Normal file
View File

@ -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)