From 5c971707d90e14fb1988ad339b8260c2f4d4f1c0 Mon Sep 17 00:00:00 2001 From: eveleighoj <35256612+eveleighoj@users.noreply.github.com> Date: Sat, 13 Jan 2024 21:21:04 +0100 Subject: [PATCH] move test to better folder --- tests/acceptance/test_entity.py | 49 --------------------------------- tests/acceptance/test_search.py | 49 ++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 50 deletions(-) diff --git a/tests/acceptance/test_entity.py b/tests/acceptance/test_entity.py index 5482d88c..88d89774 100644 --- a/tests/acceptance/test_entity.py +++ b/tests/acceptance/test_entity.py @@ -1,6 +1,5 @@ import re import pytest -import logging from application.db.models import EntityOrm @@ -181,54 +180,6 @@ async def test_find_an_entity_via_the_search_page( ) -@pytest.mark.parametrize( - "input_values, expected_fields", - [ - ({"json": {"ancient-woodland-status": "ANW"}}, ["ancient-woodland-status"]), - ({"organisation_entity": 100}, ["organisation-entity"]), - ], -) -def test_entity_search_field_paramter_selects_correct_fields( - input_values, expected_fields, client, db_session -): - """ - The field paramter can be passed to our api to control what is - returned in the response. this paramter only affects the json - and geojson extensions. - """ - default_entity = { - "entity": "1", - "name": None, - "entry_date": None, - "start_date": None, - "end_date": None, - "dataset": "ancient-woodland", - "json": None, - "organisation_entity": None, - "prefix": "ancient-woodland", - "reference": "1", - "typology": "geography", - "geometry": "MultiPolygon (((-0.3386878967285156 53.74426323597749, -0.337904691696167 53.743857158459996, -0.33673524856567383 53.744003093019586, -0.33637046813964844 53.74463124033804, -0.3365743160247803 53.74525937826645, -0.33737897872924805 53.74541799747043, -0.33875226974487305 53.74505000000031, -0.3386878967285156 53.74426323597749)))", # noqa: E501 - "point": "POINT (-0.33737897872924805 53.74541799747043)", - } - - new_entity = { - key: (input_values[key] if key in input_values.keys() else value) - for key, value in default_entity.items() - } - - db_session.add(EntityOrm(**new_entity)) - db_session.commit() - - field_query_param_string = "&".join([f"field={field}" for field in expected_fields]) - entity = client.get(f"entity.json?{field_query_param_string}").json()["entities"][0] - logging.warning(field_query_param_string) - for field in expected_fields: - assert ( - field in entity.keys() - ), f"Expected field:{field} is not in the output fields:{entity.keys()}" - - # This test is currently failing on the pipeline due to line 51 timing out # ======================================================================== # def test_correctly_loads_an_entity_page(server_process, BASE_URL, page): diff --git a/tests/acceptance/test_search.py b/tests/acceptance/test_search.py index f8a2655d..78fdbb68 100644 --- a/tests/acceptance/test_search.py +++ b/tests/acceptance/test_search.py @@ -2,7 +2,7 @@ from datetime import datetime -from application.db.models import TypologyOrm +from application.db.models import TypologyOrm, EntityOrm from tests.acceptance.pageObjectModels.searchPOM import SearchPOM @@ -154,3 +154,50 @@ def test_search_filters_show_correct_number_of_results( searchPage.filter_by_entry_date("before", "2020", "09", "04") searchPage.search_button_click() searchPage.test_count_of_results(len(filtered)) + + +@pytest.mark.parametrize( + "input_values, expected_fields", + [ + ({"json": {"ancient-woodland-status": "ANW"}}, ["ancient-woodland-status"]), + ({"organisation_entity": 100}, ["organisation-entity"]), + ], +) +def test_entity_search_field_paramter_selects_correct_fields( + input_values, expected_fields, client, db_session +): + """ + The field paramter can be passed to our api to control what is + returned in the response. this paramter only affects the json + and geojson extensions. + """ + default_entity = { + "entity": "1", + "name": None, + "entry_date": None, + "start_date": None, + "end_date": None, + "dataset": "ancient-woodland", + "json": None, + "organisation_entity": None, + "prefix": "ancient-woodland", + "reference": "1", + "typology": "geography", + "geometry": "MultiPolygon (((-0.3386878967285156 53.74426323597749, -0.337904691696167 53.743857158459996, -0.33673524856567383 53.744003093019586, -0.33637046813964844 53.74463124033804, -0.3365743160247803 53.74525937826645, -0.33737897872924805 53.74541799747043, -0.33875226974487305 53.74505000000031, -0.3386878967285156 53.74426323597749)))", # noqa: E501 + "point": "POINT (-0.33737897872924805 53.74541799747043)", + } + + new_entity = { + key: (input_values[key] if key in input_values.keys() else value) + for key, value in default_entity.items() + } + + db_session.add(EntityOrm(**new_entity)) + db_session.commit() + + field_query_param_string = "&".join([f"field={field}" for field in expected_fields]) + entity = client.get(f"entity.json?{field_query_param_string}").json()["entities"][0] + for field in expected_fields: + assert ( + field in entity.keys() + ), f"Expected field:{field} is not in the output fields:{entity.keys()}"