Skip to content

Commit

Permalink
add test for delete (#124)
Browse files Browse the repository at this point in the history
* add test for delete

* Update populate_users.py
  • Loading branch information
3nids authored May 25, 2024
1 parent bbd1e28 commit 8dab395
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def handle(self, *args, **options):
adding = []
modifying = []
viewing = []
deleting = []

for model in (
"point_2056_10fields",
Expand All @@ -26,9 +27,10 @@ def handle(self, *args, **options):
):
adding.append(Permission.objects.get(codename=f"add_{model}"))
modifying.append(Permission.objects.get(codename=f"change_{model}"))
deleting.append(Permission.objects.get(codename=f"delete_{model}"))
viewing.append(Permission.objects.get(codename=f"view_{model}"))

editing = adding + modifying + viewing
editing = adding + modifying + deleting + viewing

editors, _ = Group.objects.get_or_create(name="editors")
viewers, _ = Group.objects.get_or_create(name="viewers")
Expand Down
19 changes: 19 additions & 0 deletions tests/django_oapif_tests/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,22 @@ def test_returned_id(self):
location = post_to_items.headers["Location"]
print(location)
self.assertTrue(re.match(r"^.*[0-9a-f\-]{36}$", location))

def test_delete(self):
self.client.force_authenticate(user=self.demo_editor)
data = {
"geometry": {
"type": "Point",
"coordinates": [2508500.0, 1152000.0],
"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::2056"}},
},
"properties": {"field_str_0": "test123456"},
}

url = f"{collections_url}/tests.point_2056_10fields/items"
post_to_items = self.client.post(url, data, format="json")
self.assertIn(post_to_items.status_code, (200, 201), (url, data, post_to_items.data))
location = post_to_items.headers["Location"]
fid = re.match(r"^.*([0-9a-f\-]{36})$", location).group(1)
delete_from_items = self.client.delete(f"{url}/{fid}")
self.assertIn(delete_from_items.status_code, (200, 204), f"{url}/{fid}")

0 comments on commit 8dab395

Please sign in to comment.