[wip] tests dummy_domain
This commit is contained in:
parent
86e8dd3465
commit
fa1ca6bf9d
|
@ -212,8 +212,8 @@ def dummy_app():
|
|||
backend=JWTAuthenticationBackend(secret_key='dummysecret')
|
||||
)
|
||||
return app
|
||||
@pytest.fixture
|
||||
|
||||
@pytest.fixture
|
||||
def dummy_debug_app():
|
||||
app = Starlette(debug=True)
|
||||
app.add_route('/',
|
||||
|
@ -251,19 +251,23 @@ def create_route():
|
|||
|
||||
@pytest.fixture
|
||||
def dummy_project():
|
||||
halfapi_dirname = tempfile.mkdtemp(prefix='halfapi_')
|
||||
domain_dirname = os.path.join(halfapi_dirname, 'test_domain')
|
||||
halfapi_path = os.path.join(halfapi_dirname, '.halfapi')
|
||||
os.mkdir(halfapi_path)
|
||||
os.mkdir(os.path.join(domain_dirname))
|
||||
os.mkdir(os.path.join(domain_dirname, 'test_router'))
|
||||
halfapi_config = tempfile.mktemp()
|
||||
halfapi_secret = tempfile.mktemp()
|
||||
domain = 'dummy_domain'
|
||||
|
||||
with open(os.path.join(halfapi_path, 'config'), 'w') as f:
|
||||
with open(halfapi_config, 'w') as f:
|
||||
f.writelines([
|
||||
'[domains]',
|
||||
f'test_domain = test_router'
|
||||
'[project]\n',
|
||||
'name = lirmm_api\n',
|
||||
'halfapi_version = 0.5.0\n',
|
||||
f'secret = {halfapi_secret}\n',
|
||||
'port = 3050\n',
|
||||
'loglevel = debug\n',
|
||||
'[domains]\n',
|
||||
f'{domain}= .routers'
|
||||
])
|
||||
with open(os.path.join(halfapi_dirname, 'test_domain', '__init__.py'), 'w') as f:
|
||||
f.write('')
|
||||
|
||||
return (halfapi_dirname, 'test_domain')
|
||||
with open(halfapi_secret, 'w') as f:
|
||||
f.write('turlututu')
|
||||
|
||||
return (halfapi_config, 'dummy_domain', 'routers')
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
ROUTES={
|
||||
'': {
|
||||
'SUBROUTES': ['abc','act']
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
ROUTES={
|
||||
'': {
|
||||
'SUBROUTES': ['alphabet', 'pinnochio']
|
||||
}
|
||||
}
|
|
@ -1,17 +1,8 @@
|
|||
from starlette.responses import PlainTextResponse
|
||||
from dummy_domain import acl
|
||||
|
||||
ROUTES={
|
||||
'': {
|
||||
ACLS = {
|
||||
'GET': [{'acl':acl.public}]
|
||||
},
|
||||
'{test:uuid}': {
|
||||
'GET': [{'acl':None}],
|
||||
'POST': [{'acl':None}],
|
||||
'PATCH': [{'acl':None}],
|
||||
'PUT': [{'acl':None}]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async def get(request, *args, **kwargs):
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
from halfapi.lib import acl
|
||||
ACLS = {
|
||||
'GET': [{'acl':acl.public}],
|
||||
'POST': [{'acl':acl.public}],
|
||||
'PATCH': [{'acl':acl.public}],
|
||||
'PUT': [{'acl':acl.public}]
|
||||
}
|
||||
|
||||
def get(test):
|
||||
return str(test)
|
||||
|
||||
def post(test):
|
||||
return str(test)
|
||||
|
||||
def patch(test):
|
||||
return str(test)
|
||||
|
||||
def put(test):
|
||||
return str(test)
|
|
@ -1,2 +1,6 @@
|
|||
ROUTES={
|
||||
from halfapi.lib import acl
|
||||
ACLS = {
|
||||
'GET' : [{acl.public}]
|
||||
}
|
||||
def get():
|
||||
raise NotImplementedError
|
||||
|
|
|
@ -10,69 +10,14 @@ from starlette.testclient import TestClient
|
|||
from halfapi.lib.routes import gen_starlette_routes
|
||||
|
||||
|
||||
def test_create_route(dummy_project, create_route):
|
||||
|
||||
create_route(os.path.join(dummy_project[0], dummy_project[1]),
|
||||
'get', '/test')
|
||||
create_route(os.path.join(dummy_project[0], dummy_project[1]),
|
||||
'post', '/test')
|
||||
create_route(os.path.join(dummy_project[0], dummy_project[1]),
|
||||
'put', '/test')
|
||||
|
||||
os.chdir(dummy_project[0])
|
||||
|
||||
sys.path.insert(0, '.')
|
||||
router_path = os.path.join('.', dummy_project[1], 'test')
|
||||
os.path.isdir(router_path)
|
||||
try:
|
||||
mod = importlib.import_module('.'.join((dummy_project[1], 'test')))
|
||||
except ModuleNotFoundError as exc:
|
||||
print('.'.join((dummy_project[1], 'test')))
|
||||
print(os.listdir('.'))
|
||||
raise exc
|
||||
|
||||
assert hasattr(mod, 'get')
|
||||
assert hasattr(mod, 'post')
|
||||
assert hasattr(mod, 'put')
|
||||
|
||||
def test_has_route(dummy_project, create_route):
|
||||
|
||||
create_route(os.path.join(dummy_project[0], dummy_project[1]),
|
||||
'get', '/test')
|
||||
|
||||
create_route(os.path.join(dummy_project[0], dummy_project[1]),
|
||||
'post', '/test/tutu')
|
||||
|
||||
create_route(os.path.join(dummy_project[0], dummy_project[1]),
|
||||
'patch', '/test/ID')
|
||||
|
||||
|
||||
os.chdir(dummy_project[0])
|
||||
sys.path.insert(0, '.')
|
||||
try:
|
||||
mod = importlib.import_module(dummy_project[1], 'test')
|
||||
except ModuleNotFoundError as exc:
|
||||
print('.'.join((dummy_project[1], 'test')))
|
||||
print(os.listdir('.'))
|
||||
raise exc
|
||||
|
||||
for elt in gen_starlette_routes({dummy_project[1]: mod}):
|
||||
assert(isinstance(elt, Route))
|
||||
|
||||
|
||||
|
||||
def test_get_route(dummy_project, create_route):
|
||||
|
||||
create_route(os.path.join(dummy_project[0], dummy_project[1]),
|
||||
'get', '/test')
|
||||
|
||||
create_route(os.path.join(dummy_project[0], dummy_project[1]),
|
||||
'post', '/test/tutu')
|
||||
|
||||
create_route(os.path.join(dummy_project[0], dummy_project[1]),
|
||||
'post', '/test/ID')
|
||||
|
||||
def test_get_route(dummy_project):
|
||||
from halfapi.app import application
|
||||
os.environ['HALFAPI_CONFIG'] = dummy_project[0]
|
||||
c = TestClient(application)
|
||||
r = c.get(f'/{dummy_project[1]}/test')
|
||||
print(f'/{dummy_project[1]}/alphabet')
|
||||
r = c.get(f'/{dummy_project[1]}/alphabet')
|
||||
try:
|
||||
assert r.status_code == 200
|
||||
except AssertionError as exc:
|
||||
print('.'.join((dummy_project[1], 'routers')))
|
||||
raise exc
|
||||
|
|
Loading…
Reference in New Issue