From 2a9518c9e771c9eec67aa25ee0d1e2e8b8195892 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 19 Aug 2018 13:10:04 +0200 Subject: Use status code instead of simple message for testing --- src/tests/test_api.py | 12 ++++++------ src/tests/test_user.py | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/tests') diff --git a/src/tests/test_api.py b/src/tests/test_api.py index 063f32f..741780e 100644 --- a/src/tests/test_api.py +++ b/src/tests/test_api.py @@ -11,12 +11,12 @@ def test_api_get_all_users(client, app): assert response.is_json assert re.search('username', str(response.data)) -@pytest.mark.parametrize(('username', 'message'), ( - ('', b'{"msg": "Username is required."}'), - ('neo', b'{"msg": "User neo is already registered."}'), - ('neodarz', b'{"msg": "done"}') +@pytest.mark.parametrize(('username', 'code'), ( + ('', 400), + ('neo', 409), + ('neodarz', 201) )) -def test_api_register(client, app, username, message): +def test_api_register(client, app, username, code): response = client.post('/api/user/register', data='{"username": "'+username+'"}') print(response.data) - assert message in response.data + assert code == response.status_code diff --git a/src/tests/test_user.py b/src/tests/test_user.py index f39279e..c6ddbd4 100644 --- a/src/tests/test_user.py +++ b/src/tests/test_user.py @@ -12,10 +12,10 @@ def test_get_all_users(app): def test_register_user(app): with app.app_context(): user = User(app) - assert user.register("neodarz") is None + assert user.register("neodarz")['code'] is 201 def test_register_and_remove_user(app): with app.app_context(): user = User(app) - assert user.register("neodarz") is None - assert user.remove("neodarz") is None + assert user.register("neodarz")['code'] is 201 + assert user.remove("neodarz")['code'] is 200 -- cgit v1.2.1