From 3529af69f5b52e2ae6237e626bccca8b71f54e97 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi <256895@studenti.unimore.it> Date: Fri, 7 May 2021 21:22:45 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20WIP=20testing=20stuff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/backend/nest_backend/test/conftest.py | 2 +- .../nest_backend/test/fixtures/flask_client.py | 15 +++++++++++++++ code/backend/nest_backend/test/test_doa.py | 7 ++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/code/backend/nest_backend/test/conftest.py b/code/backend/nest_backend/test/conftest.py index edf569d..1b8ecc9 100644 --- a/code/backend/nest_backend/test/conftest.py +++ b/code/backend/nest_backend/test/conftest.py @@ -4,4 +4,4 @@ Pytest configuration file. Import global fixtures here. """ -from fixtures.flask_client import flask_client +from fixtures.flask_client import flask_client, access_token \ No newline at end of file diff --git a/code/backend/nest_backend/test/fixtures/flask_client.py b/code/backend/nest_backend/test/fixtures/flask_client.py index e1022cc..ea1198d 100644 --- a/code/backend/nest_backend/test/fixtures/flask_client.py +++ b/code/backend/nest_backend/test/fixtures/flask_client.py @@ -35,3 +35,18 @@ def flask_client(): # Teardown schema with app.app_context(): ext.engine.execute(f"""DROP SCHEMA "{uniq_schema}" CASCADE;""") + + +@pytest.fixture() +def access_token(flask_client): + response = flask_client.post("/api/v1/login", json={ + "username": "admin", + "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"] diff --git a/code/backend/nest_backend/test/test_doa.py b/code/backend/nest_backend/test/test_doa.py index 7180f65..0c4de26 100644 --- a/code/backend/nest_backend/test/test_doa.py +++ b/code/backend/nest_backend/test/test_doa.py @@ -1,9 +1,10 @@ import pytest from flask.testing import Client -from nest_backend.test.fixtures import flask_client # noinspection PyShadowingNames -def test_doa(flask_client: Client): - response = flask_client.get("/doa") +def test_doa(flask_client: Client, access_token: str): + response = flask_client.get("/doa", headers={ + "Authorization": f"Bearer {access_token}", + }) assert b"If you see this, the server is fine." in response.data