From 86bc332098ec97bd767fd15869d9e9ed5271ba77 Mon Sep 17 00:00:00 2001 From: Alex de Landgraaf Date: Thu, 23 Mar 2023 10:56:22 +0100 Subject: [PATCH] [#324] Regressiontests to avoid retrieval of old objects when querying using data_attrs --- src/objects/tests/v2/test_filters.py | 26 ++++++++++++ src/objects/tests/v2/test_object_api.py | 56 +++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/src/objects/tests/v2/test_filters.py b/src/objects/tests/v2/test_filters.py index 52ed5ddc..e49f9bef 100644 --- a/src/objects/tests/v2/test_filters.py +++ b/src/objects/tests/v2/test_filters.py @@ -377,6 +377,32 @@ def test_filter_exclude_old_records(self): data = response.json()["results"] self.assertEqual(len(data), 0) + def test_filter_exclude_old_records_issue_324(self): + record_old = ObjectRecordFactory.create( + data={"adres": {"straat": "Bospad"}}, + object__object_type=self.object_type, + start_at=date.today() - timedelta(days=10), + end_at=date.today() - timedelta(days=1), + ) + record_new = ObjectRecordFactory.create( + data={"adres": {"straat": "Dorpsstraat"}}, + object=record_old.object, start_at=record_old.end_at + ) + + response = self.client.get(self.url, {"data_attrs": "adres__straat__exact__Bospad"}) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.json()["results"] + self.assertEqual(len(data), 0) + + response = self.client.get(self.url, {"data_attrs": "adres__straat__exact__Dorpsstraat"}) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.json()["results"] + self.assertEqual(len(data), 1) + def test_filter_date_field_gte(self): record = ObjectRecordFactory.create( data={"dateField": "2000-10-10"}, object__object_type=self.object_type diff --git a/src/objects/tests/v2/test_object_api.py b/src/objects/tests/v2/test_object_api.py index 12b5a43a..29b62230 100644 --- a/src/objects/tests/v2/test_object_api.py +++ b/src/objects/tests/v2/test_object_api.py @@ -219,6 +219,62 @@ def test_update_object(self, m): self.assertEqual(initial_record.corrected, current_record) self.assertEqual(initial_record.end_at, date(2020, 1, 1)) + + def test_update_object_issue_324(self, m): + mock_service_oas_get(m, OBJECT_TYPES_API, "objecttypes") + m.get( + f"{self.object_type.url}/versions/1", + json=mock_objecttype_version(self.object_type.url), + ) + m.get(self.object_type.url, json=mock_objecttype(self.object_type.url)) + + data = { + "type": self.object_type.url, + "record": { + "typeVersion": 1, + "data": {"adres": {"straat": "Bospad"}, "diameter": 30}, + "startAt": "2019-12-31", + }, + } + url = reverse("object-list") + response = self.client.post(url, data, **GEO_WRITE_KWARGS) + + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + object = Object.objects.get() + + url = reverse("object-detail", args=[object.uuid]) + data = { + "type": object.object_type.url, + "record": { + "typeVersion": 1, + "data": {"adres": {"straat": "Dorpsstraat"}, "diameter": 30}, + "startAt": "2020-01-01", + "correctionFor": 1, + }, + } + + response = self.client.put(url, data, **GEO_WRITE_KWARGS) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + object.refresh_from_db() + + self.assertEqual(object.object_type, self.object_type) + self.assertEqual(object.records.count(), 2) + url = reverse("object-list") + response = self.client.get(url, {"data_attrs": "adres__straat__exact__Bospad"}) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.json()["results"] + self.assertEqual(len(data), 0) + + response = self.client.get(url, {"data_attrs": "adres__straat__exact__Dorpsstraat"}) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = response.json()["results"] + self.assertEqual(len(data), 1) + def test_patch_object_record(self, m): mock_service_oas_get(m, OBJECT_TYPES_API, "objecttypes") m.get(