[tests] fix tests and add "mix_stderr=False" to CliRunner instance

This commit is contained in:
Maxime Alves LIRMM 2021-12-13 12:40:40 +01:00
parent 048c9f1bab
commit 8fff1f5372
7 changed files with 91 additions and 31 deletions

View File

@ -38,22 +38,30 @@ class TestDomain(TestCase):
return wrapper
class_.invoke = invoke_wrapper(class_.invoke)
self.runner = class_()
self.runner = class_(mix_stderr=False)
def tearDown(self):
pass
def check_domain(self):
result = self.runner.invoke(cli, '--version')
self.assertEqual(result.exit_code, 0)
print(result.stdout)
result = self.runner.invoke(cli, ['domain', self.DOMAIN])
self.assertEqual(result.exit_code, 0)
result_d = json.loads(result.stdout)
result = self.runner.invoke(cli, ['run', '--dryrun', self.DOMAIN])
print(result.stdout)
self.assertEqual(result.exit_code, 0)
result = None
try:
result = self.runner.invoke(cli, '--version')
self.assertEqual(result.exit_code, 0)
result = self.runner.invoke(cli, ['domain', self.DOMAIN])
self.assertEqual(result.exit_code, 0)
result_d = json.loads(result.stdout)
result = self.runner.invoke(cli, ['run', '--help'])
self.assertEqual(result.exit_code, 0)
result = self.runner.invoke(cli, ['run', '--dryrun', self.DOMAIN])
self.assertEqual(result.exit_code, 0)
except AssertionError as exc:
print(f'Result {result}')
print(f'Stdout {result.stdout}')
print(f'Stderr {result.stderr}')
raise exc
return result_d

View File

@ -76,7 +76,7 @@ def token_debug_true_builder():
@pytest.fixture
def runner():
return CliRunner()
return CliRunner(mix_stderr=False)
@pytest.fixture
@ -104,7 +104,7 @@ def cli_runner():
return wrapper
class_.invoke = invoke_wrapper(class_.invoke)
cli_runner_ = class_()
cli_runner_ = class_(mix_stderr=False)
yield cli_runner_

View File

@ -1,5 +1,5 @@
from halfapi.lib import acl
from halfapi.lib.acl import public
from halfapi.lib.acl import public, private
from random import randint
def random(*args):
@ -7,13 +7,8 @@ def random(*args):
"""
return randint(0,1) == 1
def denied(*args):
""" Access denied
"""
return False
ACLS = (
('public', public.__doc__, 999),
('random', random.__doc__, 10),
('denied', denied.__doc__, 0)
('private', private.__doc__, 0)
)

View File

@ -26,7 +26,33 @@ ACLS = {
}
}
},
],
'POST' : [
{
'acl':acl.private,
'args': {
'required': {
'foo', 'bar'
},
'optional': {
'x'
}
}
},
{
'acl':acl.public,
'args': {
'required': {
'foo', 'baz'
},
'optional': {
'truebidoo'
}
}
},
]
}
def get(halfapi, data):
@ -36,3 +62,11 @@ def get(halfapi, data):
"""
logger.error('%s', data['foo'])
return {'foo': data['foo'], 'bar': data['bar']}
def post(halfapi, data):
"""
description:
returns the configuration of the domain
"""
logger.error('%s', data)
return {'foo': data['foo'], 'bar': data.get('bar', data.get('baz'))}

View File

@ -14,4 +14,4 @@ def get(halfapi):
returns the configuration of the domain
"""
logger.error('%s', halfapi)
return halfapi['config']
return halfapi['config']['domain']['dummy_domain']['config']

View File

@ -10,33 +10,56 @@ import pprint
from halfapi.lib.constants import API_SCHEMA
def test_routes(application_debug):
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"
c = TestClient(application_debug)
r = c.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)
r = c.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)
r = c.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)
r = c.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)
r = c.get('/halfapi/error/500')
assert r.status_code == 500
def test_schema(application_debug):
c = TestClient(application_debug)
r = c.get('/')
schemas = r.json()
assert isinstance(schemas, list)
for schema in schemas:
assert isinstance(schema, dict)
assert API_SCHEMA.validate(schema)
"""
TODO: Find a way to test exception raising
try:
r = c.get('/halfapi/exception')
assert r.status_code == 500
except Exception:
print('exception')
"""

View File

@ -5,7 +5,7 @@ def test_dummy_domain():
from .dummy_domain import acl
assert acl.public() is True
assert isinstance(acl.random(), int)
assert acl.denied() is False
assert acl.private() is False
from .dummy_domain import routers