Skip to content

Commit

Permalink
[#324] Regressiontests to avoid retrieval of old objects when queryin…
Browse files Browse the repository at this point in the history
…g using data_attrs
  • Loading branch information
alextreme committed Mar 23, 2023
1 parent 45ea40c commit 86bc332
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/objects/tests/v2/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions src/objects/tests/v2/test_object_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 86bc332

Please sign in to comment.