Add API tests

This commit is contained in:
crudo 2017-12-27 11:02:38 +01:00
parent d4e41024b0
commit 597db33271
4 changed files with 35 additions and 0 deletions

View File

@ -11,6 +11,7 @@ log = get_logger(__name__)
class User(View):
async def get(self):
uid = self.request.match_info.get('uid', None)
if uid is None:
return HTTPUnprocessableEntity()

View File

@ -4,5 +4,7 @@ from phi.api.rest import User
api_routes = [
route('*', '/user', User),
route('*', '/user/', User),
route('*', '/user/{uid}', User)
]

View File

@ -1,5 +1,6 @@
import pytest
import phi.ldap.client
import phi.api.app
@pytest.fixture
@ -15,3 +16,19 @@ def ldap_client():
client.open()
yield client
client.close()
@pytest.fixture
def api_app():
return phi.api.app.api_app({
'ldap': {
'host': 'localhost',
'port': 389,
'encryption': 'TLSv1.2',
'ciphers': 'HIGH',
'validate': 'False',
'username': 'uid=phi,ou=Services,dc=unit,dc=macaomilano,dc=org',
'password': 'phi',
'base_dn': 'dc=unit,dc=macaomilano,dc=org',
'attribute_id': 'uid',
'attribute_mail': 'mail'}})

15
test/test_api.py Normal file
View File

@ -0,0 +1,15 @@
async def test_user_request_not_valid(test_client, api_app):
client = await test_client(api_app)
resp = await client.get('/user')
assert resp.status == 422
resp = None
resp = await client.get('/user/')
assert resp.status == 422
async def test_user_not_found(test_client, api_app):
client = await test_client(api_app)
resp = await client.get('/user/nonexistent')
assert resp.status == 404