diff --git a/code/backend/nest_backend/test/conftest.py b/code/backend/nest_backend/test/conftest.py index 77c9127..1a6dcc4 100644 --- a/code/backend/nest_backend/test/conftest.py +++ b/code/backend/nest_backend/test/conftest.py @@ -4,4 +4,6 @@ Pytest configuration file. Import global fixtures here. """ -from fixtures.flask_client import flask_client, admin_access_token, admin_headers, user_access_token, user_headers +from fixtures.flask_client import flask_client, admin_access_token, admin_headers, user_access_token, user_headers, user_create + + diff --git a/code/backend/nest_backend/test/fixtures/flask_client.py b/code/backend/nest_backend/test/fixtures/flask_client.py index 330560b..9d1edfd 100644 --- a/code/backend/nest_backend/test/fixtures/flask_client.py +++ b/code/backend/nest_backend/test/fixtures/flask_client.py @@ -1,5 +1,8 @@ import pytest import uuid + +import requests + from nest_backend.app import app from nest_backend.gestione import gen_password from nest_backend.database import ext @@ -79,3 +82,11 @@ def user_headers(user_access_token): return user_headers +@pytest.fixture() +def user_create(admin_headers, flask_client): + r = flask_client.post(f'/api/v1/users/', headers=admin_headers, json={ + 'email': 'utente_test@nest.com', + 'password': 'password', + 'username': 'utente_test' + }) + diff --git a/code/backend/nest_backend/test/test_user.py b/code/backend/nest_backend/test/test_user.py index 0f58e48..4d4a81f 100644 --- a/code/backend/nest_backend/test/test_user.py +++ b/code/backend/nest_backend/test/test_user.py @@ -11,12 +11,13 @@ class TestUserGet: # ritorna i dati di tutti gli utenti registrati class TestUserGetAll: - def test_for_success(self, flask_client: Client, admin_headers): + def test_for_success(self, flask_client: Client, admin_headers, user_create): r = flask_client.get(f'/api/v1/users/', headers=admin_headers) assert b'success' in r.data # FIXME AssertionError in flask_client at line 63. Il test non riesce ad andare a buon fine def test_for_failure(self, flask_client: Client, user_headers): + r = flask_client.get(f'/api/v1/users/', headers=user_headers) assert b'failure' in r.data @@ -24,7 +25,7 @@ class TestUserGetAll: class TestUserAdd: def test_for_success(self, flask_client: Client, admin_headers): r = flask_client.post(f'/api/v1/users/', headers=admin_headers, json={ - 'email': 'utente_test@nest.com', + 'email': 'utente1_test@nest.com', 'password': 'password', 'username': 'utente_test' }) @@ -46,13 +47,14 @@ class TestUserDelete: # the admin tries to commit suicide def test_for_failure(self, flask_client: Client, admin_headers): + r = flask_client.delete(f'/api/v1/users/admin@admin.com', headers=admin_headers) assert b'failure' in r.data class TestUserPatch: + def test_for_success(self, flask_client: Client, admin_headers, user_create): - def test_for_success(self, flask_client: Client, admin_headers): r = flask_client.patch(f'/api/v1/users/admin@admin.com', headers=admin_headers, json={ 'username': 'admin_patched' })