Skip to content

Commit

Permalink
add test with null geom (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored May 17, 2024
1 parent bcc4340 commit 053da79
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ repos:
hooks:
- id: black
exclude: migrations/

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args: [--py39-plus]
2 changes: 1 addition & 1 deletion django_oapif/crs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"OGC",
]
CRS_URI_PATTERN = re.compile(
(rf"^http://www.opengis\.net/def/crs/" rf"(?P<auth>{'|'.join(CRS_AUTHORITY)})/" rf"[\d|\.]+?/(?P<code>\w+?)$")
rf"^http://www.opengis\.net/def/crs/" rf"(?P<auth>{'|'.join(CRS_AUTHORITY)})/" rf"[\d|\.]+?/(?P<code>\w+?)$"
)


Expand Down
6 changes: 3 additions & 3 deletions django_oapif/decorators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Any, Callable, Dict, Optional
from typing import Any, Callable, Optional

from django.contrib.gis.geos import GEOSGeometry
from django.db import models
Expand All @@ -23,8 +23,8 @@ def register_oapif_viewset(
serialize_geom_in_db: Optional[bool] = True,
geom_field: [str] = "geom",
crs: Optional[int] = None,
custom_serializer_attrs: Dict[str, Any] = None,
custom_viewset_attrs: Dict[str, Any] = None,
custom_serializer_attrs: dict[str, Any] = None,
custom_viewset_attrs: dict[str, Any] = None,
) -> Callable[[Any], models.Model]:
"""
This decorator takes care of all boilerplate code (creating a serializer, a viewset and registering it) to register
Expand Down
10 changes: 5 additions & 5 deletions tests/conformance/parse_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from itertools import islice
from os import path
from sys import argv, exit
from typing import List, NamedTuple
from typing import NamedTuple

from lxml import etree

Expand All @@ -36,13 +36,13 @@ def emoji(cls, cmp) -> str:


class Result(NamedTuple):
passed: List[str]
skipped: List[str]
failed: List[str]
passed: list[str]
skipped: list[str]
failed: list[str]

@classmethod
def load(cls, _path) -> "Result":
with open(_path, "r") as fh:
with open(_path) as fh:
results = json.load(fh)
return cls(**results)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.6 on 2024-05-17 12:06

import django.contrib.gis.db.models.fields
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('tests', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='point_2056_10fields_local_geom',
name='geom',
field=django.contrib.gis.db.models.fields.PointField(null=True, srid=2056, verbose_name='Geometry'),
),
]
2 changes: 1 addition & 1 deletion tests/django_oapif_tests/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Point_2056_10fields(BaseModelWithTenFields):

@register_oapif_viewset(crs=2056, serialize_geom_in_db=False)
class Point_2056_10fields_local_geom(BaseModelWithTenFields):
geom = models.PointField(srid=2056, verbose_name=_("Geometry"))
geom = models.PointField(srid=2056, verbose_name=_("Geometry"), null=True)


@register_oapif_viewset(geom_field=None)
Expand Down
16 changes: 14 additions & 2 deletions tests/django_oapif_tests/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_anonymous_items_options(self):
url = f"{collections_url}/{layer}/items"
response = self.client.options(url)

allowed_headers = set(s.strip() for s in response.headers["Allow"].split(","))
allowed_headers = {s.strip() for s in response.headers["Allow"].split(",")}
allowed_body = set(response.json()["actions"].keys())

self.assertEqual(allowed_body, expected)
Expand All @@ -68,8 +68,20 @@ def test_editor_items_options(self):
url = f"{collections_url}/{layer}/items"
response = self.client.options(url)

allowed_headers = set(s.strip() for s in response.headers["Allow"].split(","))
allowed_headers = {s.strip() for s in response.headers["Allow"].split(",")}
allowed_body = set(response.json()["actions"].keys())

self.assertEqual(allowed_body, expected)
self.assertEqual(allowed_headers, allowed_body)

def test_post_without_geometry(self):
self.client.force_authenticate(user=self.demo_editor)
data = {
"geometry": None,
"properties": {"field_str_0": "test123456"},
}

for layer in ("tests.point_2056_10fields_local_geom",):
url = f"{collections_url}/{layer}/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))

0 comments on commit 053da79

Please sign in to comment.