diff --git a/server/tests/__init__.py b/server/tests/__init__.py index c5b8f20d24cbfabe4d6c87f66a3e9b893a51d23d..2bf699418f230976e4ac28827e6b7d2f08030ec3 100644 --- a/server/tests/__init__.py +++ b/server/tests/__init__.py @@ -1,6 +1,8 @@ import pytest from app import create_app, db +DISABLE_TESTS = False + @pytest.fixture def app(): diff --git a/server/tests/test_app.py b/server/tests/test_app.py index eb87b111aeed98a6a4d9e706febdc882b7d38c3c..e1389d3e07539d5c76a13750fae9e666f6d66488 100644 --- a/server/tests/test_app.py +++ b/server/tests/test_app.py @@ -8,11 +8,11 @@ import pytest from app.apis import http_codes from app.core import sockets -from tests import app, client, db +from tests import DISABLE_TESTS, app, client, db from tests.test_helpers import add_default_values, change_order_test, delete, get, post, put -# @pytest.mark.skip(reason="Takes long time") +@pytest.mark.skipif(DISABLE_TESTS, reason="Only run when DISABLE_TESTS is False") def test_locked_api(client): add_default_values() @@ -33,6 +33,7 @@ def test_locked_api(client): assert response.status_code == http_codes.OK +@pytest.mark.skipif(DISABLE_TESTS, reason="Only run when DISABLE_TESTS is False") def test_misc_api(client): add_default_values() @@ -52,39 +53,40 @@ def test_misc_api(client): ## Get misc response, body = get(client, "/api/misc/roles", headers=headers) assert response.status_code == http_codes.OK - assert body["count"] >= 2 + assert len(body) == 2 # There are currently two roles response, body = get(client, "/api/misc/cities", headers=headers) assert response.status_code == http_codes.OK - assert body["count"] >= 2 - assert body["items"][0]["name"] == "Linköping" and body["items"][1]["name"] == "Testköping" + assert len(body) >= 2 + assert body[0]["name"] == "Linköping" and body[1]["name"] == "Testköping" ## Cities response, body = post(client, "/api/misc/cities", {"name": "Göteborg"}, headers=headers) assert response.status_code == http_codes.OK - assert body["count"] >= 2 and body["items"][2]["name"] == "Göteborg" + assert len(body) >= 2 and body[2]["name"] == "Göteborg" # Rename city response, body = put(client, "/api/misc/cities/3", {"name": "Gbg"}, headers=headers) assert response.status_code == http_codes.OK - assert body["count"] >= 2 and body["items"][2]["name"] == "Gbg" + assert len(body) >= 2 and body[2]["name"] == "Gbg" # Delete city # First checks current cities response, body = get(client, "/api/misc/cities", headers=headers) assert response.status_code == http_codes.OK - assert body["count"] >= 3 - assert body["items"][0]["name"] == "Linköping" - assert body["items"][1]["name"] == "Testköping" - assert body["items"][2]["name"] == "Gbg" + assert len(body) >= 3 + assert body[0]["name"] == "Linköping" + assert body[1]["name"] == "Testköping" + assert body[2]["name"] == "Gbg" # Deletes city response, body = delete(client, "/api/misc/cities/3", headers=headers) assert response.status_code == http_codes.OK - assert body["count"] >= 2 - assert body["items"][0]["name"] == "Linköping" and body["items"][1]["name"] == "Testköping" + assert len(body) >= 2 + assert body[0]["name"] == "Linköping" and body[1]["name"] == "Testköping" +@pytest.mark.skipif(DISABLE_TESTS, reason="Only run when DISABLE_TESTS is False") def test_competition_api(client): add_default_values() @@ -139,6 +141,7 @@ def test_competition_api(client): assert response.status_code == http_codes.OK +@pytest.mark.skipif(DISABLE_TESTS, reason="Only run when DISABLE_TESTS is False") def test_auth_and_user_api(client): add_default_values() @@ -266,6 +269,7 @@ def test_auth_and_user_api(client): # Blacklist.query.filter(Blacklist.jti == ) +@pytest.mark.skipif(DISABLE_TESTS, reason="Only run when DISABLE_TESTS is False") def test_slide_api(client): add_default_values() @@ -385,6 +389,7 @@ def test_slide_api(client): assert c2["view_type_id"] == 3 +@pytest.mark.skipif(DISABLE_TESTS, reason="Only run when DISABLE_TESTS is False") def test_question_api(client): add_default_values() @@ -443,6 +448,7 @@ def test_question_api(client): """ +@pytest.mark.skipif(DISABLE_TESTS, reason="Only run when DISABLE_TESTS is False") def test_authorization(client): add_default_values() diff --git a/server/tests/test_db.py b/server/tests/test_db.py index 82a75a3f6f8916efefed99de346e22b91e1b0f54..9525f8971b904b5b3699349b0b328f9a0dc28b99 100644 --- a/server/tests/test_db.py +++ b/server/tests/test_db.py @@ -3,12 +3,14 @@ This file tests the database controller functions. """ import app.database.controller as dbc +import pytest from app.database.models import City, Code, Competition, Media, MediaType, Role, Slide, User -from tests import app, client, db +from tests import DISABLE_TESTS, app, client, db from tests.test_helpers import add_default_values, assert_all_slide_orders, assert_should_fail, assert_slide_order +@pytest.mark.skipif(DISABLE_TESTS, reason="Only run when DISABLE_TESTS is False") def test_default_values(client): add_default_values() @@ -40,6 +42,7 @@ def test_default_values(client): assert_should_fail(assert_all_slide_orders) +@pytest.mark.skipif(DISABLE_TESTS, reason="Only run when DISABLE_TESTS is enabled") def test_user(client): add_default_values() item_user = User.query.filter_by(email="test@test.se").first() @@ -57,6 +60,7 @@ def test_user(client): assert len(item_city.users) == 1 and item_city.users[0].id == item_user.id +@pytest.mark.skipif(DISABLE_TESTS, reason="Only run when DISABLE_TESTS is enabled") def test_media(client): add_default_values() item_user = User.query.filter_by(email="test@test.se").first() @@ -75,6 +79,7 @@ def test_media(client): assert item_media.upload_by.email == "test@test.se" +@pytest.mark.skipif(DISABLE_TESTS, reason="Only run when DISABLE_TESTS is enabled") def test_copy(client): add_default_values() @@ -135,6 +140,7 @@ def test_copy(client): assert_all_slide_orders() +@pytest.mark.skipif(DISABLE_TESTS, reason="Only run when DISABLE_TESTS is enabled") def check_slides_copy(item_slide_original, item_slide_copy, num_slides, order): """ Checks that two slides are correct copies of each other. @@ -200,6 +206,7 @@ def check_slides_copy(item_slide_original, item_slide_copy, num_slides, order): assert item_slide_copy == item_slides[order] +@pytest.mark.skipif(DISABLE_TESTS, reason="Only run when DISABLE_TESTS is enabled") def test_move_slides(client): add_default_values()