[tests] fix tests and add "mix_stderr=False" to CliRunner instance
This commit is contained in:
parent
048c9f1bab
commit
8fff1f5372
|
@ -38,22 +38,30 @@ class TestDomain(TestCase):
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
class_.invoke = invoke_wrapper(class_.invoke)
|
class_.invoke = invoke_wrapper(class_.invoke)
|
||||||
self.runner = class_()
|
self.runner = class_(mix_stderr=False)
|
||||||
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def check_domain(self):
|
def check_domain(self):
|
||||||
result = self.runner.invoke(cli, '--version')
|
result = None
|
||||||
self.assertEqual(result.exit_code, 0)
|
try:
|
||||||
print(result.stdout)
|
result = self.runner.invoke(cli, '--version')
|
||||||
result = self.runner.invoke(cli, ['domain', self.DOMAIN])
|
self.assertEqual(result.exit_code, 0)
|
||||||
self.assertEqual(result.exit_code, 0)
|
result = self.runner.invoke(cli, ['domain', self.DOMAIN])
|
||||||
result_d = json.loads(result.stdout)
|
self.assertEqual(result.exit_code, 0)
|
||||||
result = self.runner.invoke(cli, ['run', '--dryrun', self.DOMAIN])
|
result_d = json.loads(result.stdout)
|
||||||
print(result.stdout)
|
result = self.runner.invoke(cli, ['run', '--help'])
|
||||||
self.assertEqual(result.exit_code, 0)
|
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
|
return result_d
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ def token_debug_true_builder():
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def runner():
|
def runner():
|
||||||
return CliRunner()
|
return CliRunner(mix_stderr=False)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -104,7 +104,7 @@ def cli_runner():
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
class_.invoke = invoke_wrapper(class_.invoke)
|
class_.invoke = invoke_wrapper(class_.invoke)
|
||||||
cli_runner_ = class_()
|
cli_runner_ = class_(mix_stderr=False)
|
||||||
|
|
||||||
yield cli_runner_
|
yield cli_runner_
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from halfapi.lib import acl
|
from halfapi.lib import acl
|
||||||
from halfapi.lib.acl import public
|
from halfapi.lib.acl import public, private
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
def random(*args):
|
def random(*args):
|
||||||
|
@ -7,13 +7,8 @@ def random(*args):
|
||||||
"""
|
"""
|
||||||
return randint(0,1) == 1
|
return randint(0,1) == 1
|
||||||
|
|
||||||
def denied(*args):
|
|
||||||
""" Access denied
|
|
||||||
"""
|
|
||||||
return False
|
|
||||||
|
|
||||||
ACLS = (
|
ACLS = (
|
||||||
('public', public.__doc__, 999),
|
('public', public.__doc__, 999),
|
||||||
('random', random.__doc__, 10),
|
('random', random.__doc__, 10),
|
||||||
('denied', denied.__doc__, 0)
|
('private', private.__doc__, 0)
|
||||||
)
|
)
|
||||||
|
|
|
@ -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):
|
def get(halfapi, data):
|
||||||
|
@ -36,3 +62,11 @@ def get(halfapi, data):
|
||||||
"""
|
"""
|
||||||
logger.error('%s', data['foo'])
|
logger.error('%s', data['foo'])
|
||||||
return {'foo': data['foo'], 'bar': data['bar']}
|
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'))}
|
||||||
|
|
|
@ -14,4 +14,4 @@ def get(halfapi):
|
||||||
returns the configuration of the domain
|
returns the configuration of the domain
|
||||||
"""
|
"""
|
||||||
logger.error('%s', halfapi)
|
logger.error('%s', halfapi)
|
||||||
return halfapi['config']
|
return halfapi['config']['domain']['dummy_domain']['config']
|
||||||
|
|
|
@ -10,33 +10,56 @@ import pprint
|
||||||
from halfapi.lib.constants import API_SCHEMA
|
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.
|
# @TODO : If we use isolated filesystem multiple times that creates a bug.
|
||||||
# So we use a single function with fixture "application debug"
|
# So we use a single function with fixture "application debug"
|
||||||
|
|
||||||
c = TestClient(application_debug)
|
c = TestClient(application_debug)
|
||||||
r = c.get('/halfapi/whoami')
|
r = c.get('/halfapi/whoami')
|
||||||
assert r.status_code == 200
|
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')
|
r = c.get('/halfapi/log')
|
||||||
assert r.status_code == 200
|
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')
|
r = c.get('/halfapi/error/400')
|
||||||
assert r.status_code == 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')
|
r = c.get('/halfapi/error/404')
|
||||||
assert r.status_code == 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')
|
r = c.get('/halfapi/error/500')
|
||||||
assert r.status_code == 500
|
assert r.status_code == 500
|
||||||
|
|
||||||
|
def test_schema(application_debug):
|
||||||
|
c = TestClient(application_debug)
|
||||||
|
|
||||||
r = c.get('/')
|
r = c.get('/')
|
||||||
schemas = r.json()
|
schemas = r.json()
|
||||||
assert isinstance(schemas, list)
|
assert isinstance(schemas, list)
|
||||||
for schema in schemas:
|
for schema in schemas:
|
||||||
assert isinstance(schema, dict)
|
assert isinstance(schema, dict)
|
||||||
assert API_SCHEMA.validate(schema)
|
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')
|
|
||||||
"""
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ def test_dummy_domain():
|
||||||
from .dummy_domain import acl
|
from .dummy_domain import acl
|
||||||
assert acl.public() is True
|
assert acl.public() is True
|
||||||
assert isinstance(acl.random(), int)
|
assert isinstance(acl.random(), int)
|
||||||
assert acl.denied() is False
|
assert acl.private() is False
|
||||||
|
|
||||||
|
|
||||||
from .dummy_domain import routers
|
from .dummy_domain import routers
|
||||||
|
|
Loading…
Reference in New Issue