diff --git a/tests/test_data_integrity.py b/tests/test_data_integrity.py index bb1eeb1..cec0f3d 100644 --- a/tests/test_data_integrity.py +++ b/tests/test_data_integrity.py @@ -4,47 +4,28 @@ import pytest import em27_metadata -DATA_DIR = os.path.join( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "data" -) +_PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @pytest.mark.library @pytest.mark.action def test_data_integrity() -> None: - with open(os.path.join(DATA_DIR, "locations.json")) as f: - locations = em27_metadata.types.LocationMetadataList.model_validate_json( - f.read() - ) - - with open(os.path.join(DATA_DIR, "sensors.json")) as f: - sensors = em27_metadata.types.SensorMetadataList.model_validate_json( - f.read() - ) - - with open(os.path.join(DATA_DIR, "campaigns.json")) as f: - campaigns = em27_metadata.types.CampaignMetadataList.model_validate_json( - f.read() - ) - - location_data = em27_metadata.interfaces.EM27MetadataInterface( - locations, sensors, campaigns - ) - - example_sensor = location_data.sensors.root[0] - example_sensor_setup = example_sensor.setups[0] - - date_string = example_sensor_setup.from_datetime.strftime("%Y-%m-%d") - from_datetime = datetime.datetime.fromisoformat( - f"{date_string}T00:00:00+00:00" - ) - to_datetime = datetime.datetime.fromisoformat( - f"{date_string}T23:59:59+00:00" - ) - - example_sensor_data_contexts = location_data.get( - example_sensor.sensor_id, from_datetime, to_datetime + location_data = em27_metadata.load_from_example_data() + example_sensor_data_contexts_1 = location_data.get( + sensor_id="sid1", + from_datetime=datetime.datetime( + 2020, 8, 26, 0, 0, 0, tzinfo=datetime.timezone.utc + ), + to_datetime=datetime.datetime( + 2020, 8, 26, 23, 59, 59, tzinfo=datetime.timezone.utc + ), ) - assert len(example_sensor_data_contexts) >= 1 - for sdc in example_sensor_data_contexts: - assert sdc.location.location_id == example_sensor_setup.value.location_id + assert len(example_sensor_data_contexts_1) == 1 + example_list_str = json.dumps( + [example_sensor_data_contexts_1[0].model_dump()], + indent=2, + ).replace("\n", "").replace("\t", "").replace(" ", "") + with open(os.path.join(_PROJECT_DIR, "README.md")) as f: + assert example_list_str in f.read().replace("\n", "").replace( + "\t", "" + ).replace(" ", "")