From 87c7f00bb697ce1a67a5456df248219324ccb3cb Mon Sep 17 00:00:00 2001 From: diversemix Date: Mon, 25 Sep 2023 11:34:49 +0100 Subject: [PATCH] tidy unit tests --- .../mocks/services/collection_service.py | 15 ++++++- unit_tests/routers/test_collection.py | 27 +++++++------ unit_tests/routers/test_config.py | 4 +- unit_tests/routers/test_family.py | 24 +++++------ .../service/test_authorisation_service.py | 8 ++-- unit_tests/service/test_collection_service.py | 40 +++++++++---------- unit_tests/service/test_family_service.py | 38 +++++++++--------- unit_tests/service/test_geography_service.py | 2 +- unit_tests/service/test_metadata_service.py | 22 +++++----- unit_tests/service/test_token_service.py | 2 +- 10 files changed, 98 insertions(+), 84 deletions(-) diff --git a/unit_tests/mocks/services/collection_service.py b/unit_tests/mocks/services/collection_service.py index 0eab90cf..5eed0411 100644 --- a/unit_tests/mocks/services/collection_service.py +++ b/unit_tests/mocks/services/collection_service.py @@ -1,5 +1,6 @@ from typing import Optional from pytest import MonkeyPatch +from app.errors import RepositoryError from app.model.collection import CollectionReadDTO, CollectionWriteDTO from unit_tests.helpers.collection import create_collection_dto @@ -7,29 +8,41 @@ def mock_collection_service(collection_service, monkeypatch: MonkeyPatch, mocker): collection_service.missing = False + collection_service.throw_repository_error = False + + def maybe_throw(): + if collection_service.throw_repository_error: + raise RepositoryError("bad repo") + def mock_get_all_collections(): + maybe_throw() return [create_collection_dto("test")] def mock_get_collection(import_id: str) -> Optional[CollectionReadDTO]: + maybe_throw() if not collection_service.missing: return create_collection_dto(import_id) def mock_search_collections(q: str) -> list[CollectionReadDTO]: - if q == "empty": + maybe_throw() + if collection_service.missing: return [] else: return [create_collection_dto("search1")] def mock_update_collection(data: CollectionWriteDTO) -> Optional[CollectionReadDTO]: + maybe_throw() if not collection_service.missing: return create_collection_dto(data.import_id, data.title, data.description) def mock_create_collection(data: CollectionWriteDTO) -> Optional[CollectionReadDTO]: + maybe_throw() if not collection_service.missing: return create_collection_dto(data.import_id, data.title, data.description) def mock_delete_collection(import_id: str) -> bool: + maybe_throw() return not collection_service.missing monkeypatch.setattr(collection_service, "get", mock_get_collection) diff --git a/unit_tests/routers/test_collection.py b/unit_tests/routers/test_collection.py index 5ffa1374..989f3139 100644 --- a/unit_tests/routers/test_collection.py +++ b/unit_tests/routers/test_collection.py @@ -10,7 +10,7 @@ from unit_tests.helpers.collection import create_collection_dto -def test_get_all_collections_route_when_ok( +def test_get_all_when_ok( client: TestClient, collection_service_mock, user_header_token ): response = client.get("/api/v1/collections", headers=user_header_token) @@ -22,7 +22,7 @@ def test_get_all_collections_route_when_ok( assert collection_service_mock.all.call_count == 1 -def test_get_collection_route_when_ok( +def test_get_when_ok( client: TestClient, collection_service_mock, user_header_token ): response = client.get("/api/v1/collections/import_id", headers=user_header_token) @@ -32,7 +32,7 @@ def test_get_collection_route_when_ok( assert collection_service_mock.get.call_count == 1 -def test_get_collection_route_when_not_found( +def test_get_when_not_found( client: TestClient, collection_service_mock, user_header_token ): collection_service_mock.missing = True @@ -43,7 +43,7 @@ def test_get_collection_route_when_not_found( assert collection_service_mock.get.call_count == 1 -def test_search_collection_route_when_ok( +def test_search_when_ok( client: TestClient, collection_service_mock, user_header_token ): response = client.get("/api/v1/collections/?q=anything", headers=user_header_token) @@ -55,17 +55,18 @@ def test_search_collection_route_when_ok( assert collection_service_mock.search.call_count == 1 -def test_search_collection_route_when_not_found( +def test_search_when_not_found( client: TestClient, collection_service_mock, user_header_token ): - response = client.get("/api/v1/collections/?q=empty", headers=user_header_token) + collection_service_mock.missing = True + response = client.get("/api/v1/collections/?q=stuff", headers=user_header_token) assert response.status_code == status.HTTP_404_NOT_FOUND data = response.json() - assert data["detail"] == "Collections not found for term: empty" + assert data["detail"] == "Collections not found for term: stuff" assert collection_service_mock.search.call_count == 1 -def test_update_collection_route_when_ok( +def test_update_when_ok( client: TestClient, collection_service_mock, user_header_token ): new_data = create_collection_dto("col1").model_dump() @@ -78,7 +79,7 @@ def test_update_collection_route_when_ok( assert collection_service_mock.update.call_count == 1 -def test_update_collection_route_when_not_found( +def test_update_when_not_found( client: TestClient, collection_service_mock, user_header_token ): collection_service_mock.missing = True @@ -92,7 +93,7 @@ def test_update_collection_route_when_not_found( assert collection_service_mock.update.call_count == 1 -def test_create_collection_route_when_ok( +def test_create_when_ok( client: TestClient, collection_service_mock, user_header_token ): new_data = create_collection_dto("col1").model_dump() @@ -105,7 +106,7 @@ def test_create_collection_route_when_ok( assert collection_service_mock.create.call_count == 1 -def test_create_collection_route_when_not_found( +def test_create_when_not_found( client: TestClient, collection_service_mock, user_header_token ): collection_service_mock.missing = True @@ -119,7 +120,7 @@ def test_create_collection_route_when_not_found( assert collection_service_mock.create.call_count == 1 -def test_delete_collection_route_when_ok( +def test_delete_when_ok( client: TestClient, collection_service_mock, admin_user_header_token ): response = client.delete( @@ -137,7 +138,7 @@ def test_delete_collection_fails_if_not_admin( assert collection_service_mock.delete.call_count == 0 -def test_delete_collection_route_when_not_found( +def test_delete_when_not_found( client: TestClient, collection_service_mock, admin_user_header_token ): collection_service_mock.missing = True diff --git a/unit_tests/routers/test_config.py b/unit_tests/routers/test_config.py index 6b172ba3..f8911233 100644 --- a/unit_tests/routers/test_config.py +++ b/unit_tests/routers/test_config.py @@ -2,7 +2,7 @@ from fastapi.testclient import TestClient -def test_get_config(client: TestClient, user_header_token, config_service_mock): +def test_get_when_ok(client: TestClient, user_header_token, config_service_mock): response = client.get("/api/v1/config", headers=user_header_token) assert response.status_code == status.HTTP_200_OK data = response.json() @@ -13,7 +13,7 @@ def test_get_config(client: TestClient, user_header_token, config_service_mock): assert config_service_mock.get.call_count == 1 -def test_get_config_when_db_error( +def test_get_when_db_error( client: TestClient, user_header_token, config_service_mock ): config_service_mock.throw_repository_error = True diff --git a/unit_tests/routers/test_family.py b/unit_tests/routers/test_family.py index ca9a864b..aab3e0a1 100644 --- a/unit_tests/routers/test_family.py +++ b/unit_tests/routers/test_family.py @@ -10,7 +10,7 @@ from unit_tests.helpers.family import create_family_dto -def test_get_all_families_route_when_ok( +def test_get_all_when_ok( client: TestClient, family_service_mock, user_header_token ): response = client.get("/api/v1/families", headers=user_header_token) @@ -22,7 +22,7 @@ def test_get_all_families_route_when_ok( assert family_service_mock.all.call_count == 1 -def test_get_family_route_when_ok( +def test_get_when_ok( client: TestClient, family_service_mock, user_header_token ): response = client.get("/api/v1/families/import_id", headers=user_header_token) @@ -32,7 +32,7 @@ def test_get_family_route_when_ok( assert family_service_mock.get.call_count == 1 -def test_get_family_route_when_not_found( +def test_get_when_not_found( client: TestClient, family_service_mock, user_header_token ): family_service_mock.missing = True @@ -43,7 +43,7 @@ def test_get_family_route_when_not_found( assert family_service_mock.get.call_count == 1 -def test_search_family_route_when_ok( +def test_search_when_ok( client: TestClient, family_service_mock, user_header_token ): response = client.get("/api/v1/families/?q=anything", headers=user_header_token) @@ -55,7 +55,7 @@ def test_search_family_route_when_ok( assert family_service_mock.search.call_count == 1 -def test_search_family_route_when_not_found( +def test_search_when_not_found( client: TestClient, family_service_mock, user_header_token ): response = client.get("/api/v1/families/?q=empty", headers=user_header_token) @@ -65,7 +65,7 @@ def test_search_family_route_when_not_found( assert family_service_mock.search.call_count == 1 -def test_update_family_route_when_ok( +def test_update_when_ok( client: TestClient, family_service_mock, user_header_token ): new_data = create_family_dto("fam1").model_dump() @@ -76,7 +76,7 @@ def test_update_family_route_when_ok( assert family_service_mock.update.call_count == 1 -def test_update_family_route_when_not_found( +def test_update_when_not_found( client: TestClient, family_service_mock, user_header_token ): family_service_mock.missing = True @@ -88,7 +88,7 @@ def test_update_family_route_when_not_found( assert family_service_mock.update.call_count == 1 -def test_create_family_route_when_ok( +def test_create_when_ok( client: TestClient, family_service_mock, user_header_token ): new_data = create_family_dto("fam1").model_dump() @@ -99,7 +99,7 @@ def test_create_family_route_when_ok( assert family_service_mock.create.call_count == 1 -def test_create_family_route_when_not_found( +def test_create_when_not_found( client: TestClient, family_service_mock, user_header_token ): family_service_mock.missing = True @@ -113,7 +113,7 @@ def test_create_family_route_when_not_found( assert family_service_mock.create.call_count == 1 -def test_delete_family_route_when_ok( +def test_delete_when_ok( client: TestClient, family_service_mock, admin_user_header_token ): response = client.delete("/api/v1/families/fam1", headers=admin_user_header_token) @@ -121,7 +121,7 @@ def test_delete_family_route_when_ok( assert family_service_mock.delete.call_count == 1 -def test_delete_family_fails_if_not_admin( +def test_delete_fails_when_not_admin( client: TestClient, family_service_mock, user_header_token ): response = client.delete("/api/v1/families/fam1", headers=user_header_token) @@ -129,7 +129,7 @@ def test_delete_family_fails_if_not_admin( assert family_service_mock.delete.call_count == 0 -def test_delete_family_route_when_not_found( +def test_delete_when_not_found( client: TestClient, family_service_mock, admin_user_header_token ): family_service_mock.missing = True diff --git a/unit_tests/service/test_authorisation_service.py b/unit_tests/service/test_authorisation_service.py index fd08e2a6..266e96bf 100644 --- a/unit_tests/service/test_authorisation_service.py +++ b/unit_tests/service/test_authorisation_service.py @@ -13,7 +13,7 @@ def test_password_hash_matches(): assert auth_service.verify_password(PLAIN_PASSWORD, HASH_PASSWORD) is True -def test_auth_user_raises_when_no_user( +def test_raises_when_user_not_found( app_user_repo_mock, ): app_user_repo_mock.error = True @@ -24,7 +24,7 @@ def test_auth_user_raises_when_no_user( assert app_user_repo_mock.get_user_by_email.call_count == 1 -def test_auth_user_raises_when_no_match( +def test_raises_when_incorrect_password( app_user_repo_mock, ): with pytest.raises(AuthenticationError) as e: @@ -34,7 +34,7 @@ def test_auth_user_raises_when_no_match( assert app_user_repo_mock.get_user_by_email.call_count == 1 -def test_auth_user_raises_when_no_password( +def test_raises_when_no_password( app_user_repo_mock, ): with pytest.raises(AuthenticationError) as e: @@ -44,7 +44,7 @@ def test_auth_user_raises_when_no_password( assert app_user_repo_mock.get_user_by_email.call_count == 1 -def test_auth_user_can_auth( +def test_can_auth( app_user_repo_mock, ): token = auth_service.authenticate_user(VALID_USERNAME, PLAIN_PASSWORD) diff --git a/unit_tests/service/test_collection_service.py b/unit_tests/service/test_collection_service.py index d559e1ec..b8f98501 100644 --- a/unit_tests/service/test_collection_service.py +++ b/unit_tests/service/test_collection_service.py @@ -2,10 +2,10 @@ from app.errors import ValidationError from app.model.collection import CollectionReadDTO, CollectionWriteDTO import app.service.collection as collection_service -from unit_tests.mocks.repos.collection_repo import create_collection_dto +from unit_tests.mocks.repos.collection_repo import create_collection_dto as create_dto -def to_write_dto(dto: CollectionReadDTO) -> CollectionWriteDTO: +def _to_write_dto(dto: CollectionReadDTO) -> CollectionWriteDTO: return CollectionWriteDTO( import_id=dto.import_id, title=dto.title, @@ -17,21 +17,21 @@ def to_write_dto(dto: CollectionReadDTO) -> CollectionWriteDTO: # --- GET -def test_collection_get(collection_repo_mock): +def test_get(collection_repo_mock): result = collection_service.get("id.1.2.3") assert result is not None assert result.import_id == "id.1.2.3" assert collection_repo_mock.get.call_count == 1 -def test_collection_service_get_returns_none(collection_repo_mock): +def test_service_get_returns_none(collection_repo_mock): collection_repo_mock.return_empty = True result = collection_service.get("id.1.2.3") assert result is not None assert collection_repo_mock.get.call_count == 1 -def test_get_collection_raises_if_invalid_id(collection_repo_mock): +def test_get_raises_if_invalid_id(collection_repo_mock): with pytest.raises(ValidationError) as e: collection_service.get("a.b.c") expected_msg = "The import id a.b.c is invalid!" @@ -66,14 +66,14 @@ def test_delete_collection(collection_repo_mock): assert collection_repo_mock.delete.call_count == 1 -def test_delete_collection_missing(collection_repo_mock): +def test_delete_missing(collection_repo_mock): collection_repo_mock.return_empty = True ok = collection_service.delete("a.b.c.d") assert not ok assert collection_repo_mock.delete.call_count == 1 -def test_delete_collection_raises_if_invalid_id(collection_repo_mock): +def test_delete_raises_if_invalid_id(collection_repo_mock): import_id = "invalid" with pytest.raises(ValidationError) as e: collection_service.delete(import_id) @@ -91,24 +91,24 @@ def test_update_collection( collection = collection_service.get("a.b.c.d") assert collection is not None - result = collection_service.update(to_write_dto(collection)) + result = collection_service.update(_to_write_dto(collection)) assert result is not None assert collection_repo_mock.update.call_count == 1 -def test_update_collection_missing( +def test_update_missing( collection_repo_mock, ): collection = collection_service.get("a.b.c.d") assert collection is not None collection_repo_mock.return_empty = True - result = collection_service.update(to_write_dto(collection)) + result = collection_service.update(_to_write_dto(collection)) assert result is None assert collection_repo_mock.update.call_count == 1 -def test_update_collection_raiseson_invalid_id( +def test_update_raises_when_invalid_id( collection_repo_mock, ): collection = collection_service.get("a.b.c.d") @@ -116,7 +116,7 @@ def test_update_collection_raiseson_invalid_id( collection.import_id = "invalid" with pytest.raises(ValidationError) as e: - collection_service.update(to_write_dto(collection)) + collection_service.update(_to_write_dto(collection)) expected_msg = f"The import id {collection.import_id} is invalid!" assert e.value.message == expected_msg assert collection_repo_mock.update.call_count == 0 @@ -129,31 +129,31 @@ def test_create_collection( collection_repo_mock, organisation_repo_mock, ): - new_collection = create_collection_dto(import_id="A.0.0.5") - collection = collection_service.create(to_write_dto(new_collection)) + new_collection = create_dto(import_id="A.0.0.5") + collection = collection_service.create(_to_write_dto(new_collection)) assert collection is not None assert collection_repo_mock.create.call_count == 1 # Ensure the collection service uses the org service to validate assert organisation_repo_mock.get_id_from_name.call_count == 1 -def test_create_collection_repo_fails( +def test_create_when_db_fails( collection_repo_mock, organisation_repo_mock, ): - new_collection = create_collection_dto(import_id="a.b.c.d") + new_collection = create_dto(import_id="a.b.c.d") collection_repo_mock.return_empty = True - collection = collection_service.create(to_write_dto(new_collection)) + collection = collection_service.create(_to_write_dto(new_collection)) assert collection is None assert collection_repo_mock.create.call_count == 1 # Ensure the collection service uses the geo service to validate assert organisation_repo_mock.get_id_from_name.call_count == 1 -def test_create_collection_raiseson_invalid_id(collection_repo_mock): - new_collection = create_collection_dto(import_id="invalid") +def test_create_raises_when_invalid_id(collection_repo_mock): + new_collection = create_dto(import_id="invalid") with pytest.raises(ValidationError) as e: - collection_service.create(to_write_dto(new_collection)) + collection_service.create(_to_write_dto(new_collection)) expected_msg = f"The import id {new_collection.import_id} is invalid!" assert e.value.message == expected_msg assert collection_repo_mock.create.call_count == 0 diff --git a/unit_tests/service/test_family_service.py b/unit_tests/service/test_family_service.py index bdf23351..7d2afbeb 100644 --- a/unit_tests/service/test_family_service.py +++ b/unit_tests/service/test_family_service.py @@ -25,20 +25,20 @@ def to_write_dto(dto: FamilyReadDTO) -> FamilyWriteDTO: # --- GET -def test_family_get_returns_family_if_exists(family_repo_mock): +def test_get_returns_family_if_exists(family_repo_mock): result = family_service.get("a.b.c.d") assert result is not None assert family_repo_mock.get.call_count == 1 -def test_family_get_returns_none_if_missing(family_repo_mock): +def test_get_returns_none_if_missing(family_repo_mock): family_repo_mock.return_empty = True result = family_service.get("a.b.c.d") assert result is None assert family_repo_mock.get.call_count == 1 -def test_family_get_raises_if_invalid_id(family_repo_mock): +def test_get_raises_when_invalid_id(family_repo_mock): with pytest.raises(ValidationError) as e: family_service.get("a.b.c") expected_msg = "The import id a.b.c is invalid!" @@ -49,14 +49,14 @@ def test_family_get_raises_if_invalid_id(family_repo_mock): # --- SEARCH -def test_search_families(family_repo_mock): +def test_search(family_repo_mock): result = family_service.search("two") assert result is not None assert len(result) == 1 assert family_repo_mock.search.call_count == 1 -def test_search_families_missing(family_repo_mock): +def test_search_missing(family_repo_mock): family_repo_mock.return_empty = True result = family_service.search("empty") assert result is not None @@ -67,20 +67,20 @@ def test_search_families_missing(family_repo_mock): # --- DELETE -def test_delete_family(family_repo_mock): +def test_delete(family_repo_mock): ok = family_service.delete("a.b.c.d") assert ok assert family_repo_mock.delete.call_count == 1 -def test_delete_family_missing(family_repo_mock): +def test_delete_missing(family_repo_mock): family_repo_mock.return_empty = True ok = family_service.delete("a.b.c.d") assert not ok assert family_repo_mock.delete.call_count == 1 -def test_delete_family_raises_if_invalid_id(family_repo_mock): +def test_delete_raises_when_invalid_id(family_repo_mock): import_id = "invalid" with pytest.raises(ValidationError) as e: family_service.delete(import_id) @@ -92,7 +92,7 @@ def test_delete_family_raises_if_invalid_id(family_repo_mock): # --- UPDATE -def test_update_family( +def test_update( family_repo_mock, geography_repo_mock, organisation_repo_mock, @@ -110,7 +110,7 @@ def test_update_family( assert metadata_repo_mock.get_schema_for_org.call_count == 1 -def test_update_family_missing( +def test_update_when_missing( family_repo_mock, geography_repo_mock, organisation_repo_mock, @@ -127,7 +127,7 @@ def test_update_family_missing( assert geography_repo_mock.get_id_from_value.call_count == 1 -def test_update_family_raiseson_invalid_id( +def test_update_raises_when_id_invalid( family_repo_mock, geography_repo_mock, organisation_repo_mock, @@ -144,7 +144,7 @@ def test_update_family_raiseson_invalid_id( assert family_repo_mock.update.call_count == 0 -def test_update_family_raiseson_invalid_category( +def test_update_raises_when_category_invalid( family_repo_mock, geography_repo_mock, organisation_repo_mock, @@ -161,7 +161,7 @@ def test_update_family_raiseson_invalid_category( assert family_repo_mock.update.call_count == 0 -def test_update_family_raiseson_invalid_organisation( +def test_update_raises_when_organisation_invalid( family_repo_mock, geography_repo_mock, organisation_repo_mock, @@ -179,7 +179,7 @@ def test_update_family_raiseson_invalid_organisation( assert family_repo_mock.update.call_count == 0 -def test_update_family_raiseson_invalid_geography( +def test_update_family_raises_when_geography_invalid( family_repo_mock, geography_repo_mock, organisation_repo_mock, @@ -196,7 +196,7 @@ def test_update_family_raiseson_invalid_geography( assert family_repo_mock.update.call_count == 0 -def test_update_family_raiseson_invalid_metadata( +def test_update_family_raises_when_metadata_invalid( family_repo_mock, geography_repo_mock, organisation_repo_mock, @@ -216,7 +216,7 @@ def test_update_family_raiseson_invalid_metadata( # --- CREATE -def test_create_family( +def test_create( family_repo_mock, geography_repo_mock, organisation_repo_mock, @@ -232,7 +232,7 @@ def test_create_family( assert metadata_repo_mock.get_schema_for_org.call_count == 1 -def test_create_family_repo_fails( +def test_create_repo_fails( family_repo_mock, geography_repo_mock, organisation_repo_mock, @@ -249,7 +249,7 @@ def test_create_family_repo_fails( assert metadata_repo_mock.get_schema_for_org.call_count == 1 -def test_create_family_raiseson_invalid_id(family_repo_mock): +def test_create_raises_when_id_invalid(family_repo_mock): new_family = create_family_dto(import_id="invalid") with pytest.raises(ValidationError) as e: family_service.create(to_write_dto(new_family)) @@ -258,7 +258,7 @@ def test_create_family_raiseson_invalid_id(family_repo_mock): assert family_repo_mock.create.call_count == 0 -def test_create_raiseson_invalid_category(family_repo_mock, geography_repo_mock): +def test_create_raises_when_category_inavlid(family_repo_mock, geography_repo_mock): new_family = create_family_dto(import_id="A.0.0.5") new_family.category = "invalid" with pytest.raises(ValidationError) as e: diff --git a/unit_tests/service/test_geography_service.py b/unit_tests/service/test_geography_service.py index aeef206f..41eaba90 100644 --- a/unit_tests/service/test_geography_service.py +++ b/unit_tests/service/test_geography_service.py @@ -3,7 +3,7 @@ import app.service.geography as geography_service -def test_geo_service_validate_raiseson_invalid_value( +def test_geo_service_validate_raises_when_invalid( organisation_repo_mock, geography_repo_mock, ): diff --git a/unit_tests/service/test_metadata_service.py b/unit_tests/service/test_metadata_service.py index d0a721af..5f4002e5 100644 --- a/unit_tests/service/test_metadata_service.py +++ b/unit_tests/service/test_metadata_service.py @@ -55,51 +55,51 @@ # ----- PASSES -def test_metadata_good_when_any_and_allow_blanks(): +def test_good_when_any_and_allow_blanks(): assert _validate(SCHEMA_ANY_BLANKS, {"author": ["henry"]}) assert _validate(SCHEMA_ANY_BLANKS, {"author": ""}) -def test_metadata_good_when_values_and_allow_blanks(): +def test_good_when_values_and_allow_blanks(): assert _validate(SCHEMA_VALUES_BLANKS, {"author": ["peter"]}) assert _validate(SCHEMA_VALUES_BLANKS, {"author": ""}) -def test_metadata_good_when_any_and_no_blanks(): +def test_good_when_any_and_no_blanks(): assert _validate(SCHEMA_ANY_NO_BLANKS, {"author": ["henry"]}) -def test_metadata_good_when_values_and_no_blanks(): +def test_good_when_values_and_no_blanks(): assert _validate(SCHEMA_VALUES_NO_BLANKS, {"author": ["peter"]}) -def test_metadata_good_when_blank_schema_and_data(): +def test_good_when_blank_schema_and_data(): assert _validate({}, {}) # ----- FAILS -def test_metadata_fails_when_no_data(): +def test_fails_when_no_data(): with pytest.raises(ValidationError) as e: _validate(SCHEMA_ANY_BLANKS, {}) expected_msg = "Values for the following are missing: {'author'}" assert e.value.message == expected_msg -def test_metadata_fails_when_invalid_key(): +def test_fails_when_invalid_key(): with pytest.raises(ValidationError) as e: _validate(SCHEMA_ANY_BLANKS, {"Something": ["value"], "author": ["peter"]}) expected_msg = "Unknown 'Something' not in ['author']" assert e.value.message == expected_msg -def test_metadata_fails_when_any_and_allow_blanks(): +def test_fails_when_any_and_allow_blanks(): # This should never fail pass -def test_metadata_fails_when_values_and_allow_blanks(): +def test_fails_when_values_and_allow_blanks(): with pytest.raises(ValidationError) as e: _validate(SCHEMA_VALUES_BLANKS, {"author": ["henry"]}) expected_msg = ( @@ -108,14 +108,14 @@ def test_metadata_fails_when_values_and_allow_blanks(): assert e.value.message == expected_msg -def test_metadata_fails_any_and_no_blanks(): +def test_fails_any_and_no_blanks(): with pytest.raises(ValidationError) as e: _validate(SCHEMA_ANY_NO_BLANKS, {"author": [""]}) expected_msg = "Value for author is blank, and that is not allowed" assert e.value.message == expected_msg -def test_metadata_fails_values_and_no_blanks(): +def test_fails_values_and_no_blanks(): with pytest.raises(ValidationError) as e: _validate(SCHEMA_VALUES_NO_BLANKS, {"author": ["henry"]}) expected_msg = ( diff --git a/unit_tests/service/test_token_service.py b/unit_tests/service/test_token_service.py index 5f8d98a7..b156c18b 100644 --- a/unit_tests/service/test_token_service.py +++ b/unit_tests/service/test_token_service.py @@ -17,7 +17,7 @@ "authorisation", [{}, {"e2": False}, {"e3": {"a": 1}}], ) -def test_token_encoded_and_decoded(email: str, is_superuser: bool, authorisation: dict): +def test_ok_when_encoded_and_decoded(email: str, is_superuser: bool, authorisation: dict): token = token_service.encode(email, is_superuser, authorisation) assert token is not None assert len(token) > 200