mirror of
https://github.com/pds-nest/nest.git
synced 2025-02-16 12:43:58 +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.
|
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()
|
@pytest.fixture()
|
||||||
def access_token(flask_client):
|
def admin_access_token(flask_client):
|
||||||
response = flask_client.post("/api/v1/login", json={
|
response = flask_client.post("/api/v1/login", json={
|
||||||
"email": "admin@admin.com",
|
"email": "admin@admin.com",
|
||||||
"password": "password"
|
"password": "password"
|
||||||
|
@ -53,6 +53,29 @@ def access_token(flask_client):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def headers(access_token):
|
def user_access_token(flask_client):
|
||||||
headers = {'Authorization': f"Bearer {access_token}"}
|
response = flask_client.post("/api/v1/login", json={
|
||||||
return headers
|
"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
|
# noinspection PyShadowingNames
|
||||||
def test_doa(flask_client: Client, access_token: str):
|
def test_doa(flask_client: Client, admin_headers):
|
||||||
response = flask_client.get("/doa", headers={
|
response = flask_client.get("/doa", headers=admin_headers)
|
||||||
"Authorization": f"Bearer {access_token}",
|
|
||||||
})
|
|
||||||
assert b"If you see this, the server is fine." in response.data
|
assert b"If you see this, the server is fine." in response.data
|
||||||
|
|
|
@ -1,24 +1,20 @@
|
||||||
from flask.testing import Client
|
from flask.testing import Client
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TestUserGet:
|
class TestUserGet:
|
||||||
def test_for_success(self, flask_client: Client, headers):
|
def test_for_success(self, flask_client: Client, admin_headers):
|
||||||
r = flask_client.get(f'/api/v1/users/admin@admin.com', headers=headers)
|
r = flask_client.get(f'/api/v1/users/admin@admin.com', headers=admin_headers)
|
||||||
assert b'success' in r.data
|
assert b'success' in r.data
|
||||||
|
|
||||||
|
|
||||||
class TestUserAdd:
|
class TestUserAdd:
|
||||||
def test_for_success(self, flask_client: Client, headers):
|
def test_for_success(self, flask_client: Client, admin_headers):
|
||||||
r = flask_client.post(f'/api/v1/users/', headers=headers,
|
r = flask_client.post(f'/api/v1/users/', headers=admin_headers,
|
||||||
json={'email': 'utente_test@nest.com', 'password': 'password', 'username': 'utente_test'})
|
json={'email': 'utente_test@nest.com', 'password': 'password', 'username': 'utente_test'})
|
||||||
assert b'success' in r.data
|
assert b'success' in r.data
|
||||||
|
|
||||||
|
|
||||||
class TestUserDelete:
|
class TestUserDelete:
|
||||||
def test_for_success(self, flask_client: Client, headers):
|
def test_for_success(self, flask_client: Client, admin_headers):
|
||||||
r = flask_client.delete(f'/api/v1/users/utente_test@nest.com', headers=headers)
|
r = flask_client.delete(f'/api/v1/users/utente_test@nest.com', headers=admin_headers)
|
||||||
assert b'success' in r.data
|
assert b'success' in r.data
|
||||||
|
|
Loading…
Add table
Reference in a new issue