mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-22 04:54:18 +00:00
fix
This commit is contained in:
parent
e294734d86
commit
d48d1e0f3f
4 changed files with 36 additions and 19 deletions
|
@ -4,4 +4,4 @@ Pytest configuration file.
|
|||
Import global fixtures here.
|
||||
"""
|
||||
|
||||
from fixtures.flask_client import flask_client, access_token, headers
|
||||
from fixtures.flask_client import flask_client, admin_access_token, admin_headers, user_access_token, user_headers
|
||||
|
|
|
@ -38,7 +38,7 @@ def flask_client():
|
|||
|
||||
|
||||
@pytest.fixture()
|
||||
def access_token(flask_client):
|
||||
def admin_access_token(flask_client):
|
||||
response = flask_client.post("/api/v1/login", json={
|
||||
"email": "admin@admin.com",
|
||||
"password": "password"
|
||||
|
@ -53,6 +53,29 @@ def access_token(flask_client):
|
|||
|
||||
|
||||
@pytest.fixture()
|
||||
def headers(access_token):
|
||||
headers = {'Authorization': f"Bearer {access_token}"}
|
||||
return headers
|
||||
def user_access_token(flask_client):
|
||||
response = flask_client.post("/api/v1/login", json={
|
||||
"email": "utente_test@nest.com",
|
||||
"password": "password"
|
||||
})
|
||||
assert response.json is not None
|
||||
assert "result" in response.json
|
||||
assert response.json["result"] == "success"
|
||||
assert "data" in response.json
|
||||
data = response.json["data"]
|
||||
assert "access_token" in data
|
||||
return data["access_token"]
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def admin_headers(admin_access_token):
|
||||
admin_headers = {'Authorization': f"Bearer {admin_access_token}"}
|
||||
return admin_headers
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def user_headers(user_access_token):
|
||||
user_headers = {'Authorization': f"Bearer {user_access_token}"}
|
||||
return user_headers
|
||||
|
||||
|
||||
|
|
|
@ -3,8 +3,6 @@ from flask.testing import Client
|
|||
|
||||
|
||||
# noinspection PyShadowingNames
|
||||
def test_doa(flask_client: Client, access_token: str):
|
||||
response = flask_client.get("/doa", headers={
|
||||
"Authorization": f"Bearer {access_token}",
|
||||
})
|
||||
def test_doa(flask_client: Client, admin_headers):
|
||||
response = flask_client.get("/doa", headers=admin_headers)
|
||||
assert b"If you see this, the server is fine." in response.data
|
||||
|
|
|
@ -1,24 +1,20 @@
|
|||
from flask.testing import Client
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class TestUserGet:
|
||||
def test_for_success(self, flask_client: Client, headers):
|
||||
r = flask_client.get(f'/api/v1/users/admin@admin.com', headers=headers)
|
||||
def test_for_success(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
|
||||
|
||||
|
||||
class TestUserAdd:
|
||||
def test_for_success(self, flask_client: Client, headers):
|
||||
r = flask_client.post(f'/api/v1/users/', headers=headers,
|
||||
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', 'password': 'password', 'username': 'utente_test'})
|
||||
assert b'success' in r.data
|
||||
|
||||
|
||||
class TestUserDelete:
|
||||
def test_for_success(self, flask_client: Client, headers):
|
||||
r = flask_client.delete(f'/api/v1/users/utente_test@nest.com', headers=headers)
|
||||
def test_for_success(self, flask_client: Client, admin_headers):
|
||||
r = flask_client.delete(f'/api/v1/users/utente_test@nest.com', headers=admin_headers)
|
||||
assert b'success' in r.data
|
||||
|
|
Loading…
Reference in a new issue