mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-22 04:54:18 +00:00
🐛 Fix bug test
This commit is contained in:
parent
3798a33452
commit
2593da8602
3 changed files with 26 additions and 28 deletions
|
@ -4,6 +4,4 @@ Pytest configuration file.
|
|||
Import global fixtures here.
|
||||
"""
|
||||
|
||||
from fixtures.flask_client import flask_client, admin_access_token, admin_headers, user_access_token, user_headers, user_create
|
||||
|
||||
|
||||
from fixtures.flask_client import flask_client, admin_access_token, admin_headers, user_access_token, user_headers, user_exists
|
||||
|
|
|
@ -40,7 +40,7 @@ def flask_client():
|
|||
ext.engine.execute(f"""DROP SCHEMA "{uniq_schema}" CASCADE;""")
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture(scope="package")
|
||||
def admin_access_token(flask_client):
|
||||
response = flask_client.post("/api/v1/login", json={
|
||||
"email": "admin@admin.com",
|
||||
|
@ -55,8 +55,17 @@ def admin_access_token(flask_client):
|
|||
return data["access_token"]
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def user_access_token(flask_client):
|
||||
@pytest.fixture(scope="package")
|
||||
def user_exists(admin_headers, flask_client):
|
||||
flask_client.post(f'/api/v1/users/', headers=admin_headers, json={
|
||||
'email': 'utente_test@nest.com',
|
||||
'password': 'password',
|
||||
'username': 'utente_test'
|
||||
})
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
def user_access_token(flask_client, user_exists):
|
||||
response = flask_client.post("/api/v1/login", json={
|
||||
"email": "utente_test@nest.com",
|
||||
"password": "password"
|
||||
|
@ -70,23 +79,13 @@ def user_access_token(flask_client):
|
|||
return data["access_token"]
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture(scope="package")
|
||||
def admin_headers(admin_access_token):
|
||||
admin_headers = {'Authorization': f"Bearer {admin_access_token}"}
|
||||
return admin_headers
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture(scope="package")
|
||||
def user_headers(user_access_token):
|
||||
user_headers = {'Authorization': f"Bearer {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'
|
||||
})
|
||||
|
||||
|
|
|
@ -4,20 +4,25 @@ from flask.testing import Client
|
|||
|
||||
|
||||
class TestUserGet:
|
||||
def test_for_success(self, flask_client: Client, admin_headers):
|
||||
def test_admin_user(self, flask_client: Client, admin_headers):
|
||||
r = flask_client.get(f'/api/v1/users/admin@admin.com', headers=admin_headers)
|
||||
assert b'success' in r.data
|
||||
assert r.json["result"] == "success"
|
||||
assert r.json["data"]["email"] == "admin@admin.com"
|
||||
assert r.json["data"]["isAdmin"] is True
|
||||
assert r.json["data"]["username"] == "admin"
|
||||
|
||||
def test_non_existing_user(self, flask_client: Client, admin_headers):
|
||||
r = flask_client.get(f'/api/v1/users/ciccio@dev.com', headers=admin_headers)
|
||||
assert r.json["result"] == "failure"
|
||||
assert r.json["msg"] == "Could not locate the user."
|
||||
|
||||
# ritorna i dati di tutti gli utenti registrati
|
||||
class TestUserGetAll:
|
||||
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.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
|
||||
|
||||
|
@ -47,14 +52,12 @@ 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'
|
||||
})
|
||||
|
@ -66,5 +69,3 @@ class TestUserPatch:
|
|||
'username': 'admin_patched'
|
||||
})
|
||||
assert b'failure' in r.data
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue