Skip to content

Commit

Permalink
Merge pull request #74 from maykinmedia/feature/remove-required-geo-h…
Browse files Browse the repository at this point in the history
…eaders

Feature/remove required geo headers
  • Loading branch information
annashamray committed Oct 2, 2020
2 parents 45e16b6 + d7380a5 commit 1498e0e
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 384 deletions.
2 changes: 1 addition & 1 deletion src/objects/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)


class ObjectViewSet(SearchMixin, GeoMixin, viewsets.ModelViewSet):
class ObjectViewSet(SearchMixin, viewsets.ModelViewSet):
queryset = Object.objects.order_by("-pk")
serializer_class = ObjectSerializer
filterset_class = ObjectFilterSet
Expand Down
4 changes: 1 addition & 3 deletions src/objects/conf/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
{
"DEFAULT_INFO": "objects.api.schema.info",
"SECURITY_DEFINITIONS": None,
"DEFAULT_FIELD_INSPECTORS": (
"vng_api_common.inspectors.geojson.GeometryFieldInspector",
)
"DEFAULT_FIELD_INSPECTORS": ("objects.utils.inspectors.GeometryFieldInspector",)
+ BASE_SWAGGER_SETTINGS["DEFAULT_FIELD_INSPECTORS"],
}
)
4 changes: 1 addition & 3 deletions src/objects/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from objects.core.tests.factores import ObjectFactory

from .utils import GEO_READ_KWARGS

OBJECT_TYPE = "https://example.com/objecttypes/v1/types/a6c109"


Expand All @@ -17,7 +15,7 @@ def test_filter_object_type(self):
object = ObjectFactory.create(object_type=OBJECT_TYPE)
ObjectFactory.create()

response = self.client.get(self.url, {"type": OBJECT_TYPE}, **GEO_READ_KWARGS)
response = self.client.get(self.url, {"type": OBJECT_TYPE})

self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down
3 changes: 0 additions & 3 deletions src/objects/tests/test_geo_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from objects.core.tests.factores import ObjectRecordFactory

from .constants import POLYGON_AMSTERDAM_CENTRUM
from .utils import GEO_WRITE_KWARGS

OBJECT_TYPE = "https://example.com/objecttypes/v1/types/a6c109"

Expand All @@ -33,7 +32,6 @@ def test_filter_within(self):
}
}
},
**GEO_WRITE_KWARGS,
)

self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down Expand Up @@ -63,7 +61,6 @@ def test_filter_objecttype(self):
},
"type": OBJECT_TYPE,
},
**GEO_WRITE_KWARGS,
)

self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down
12 changes: 6 additions & 6 deletions src/objects/tests/test_object_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from objects.core.models import Object
from objects.core.tests.factores import ObjectFactory, ObjectRecordFactory

from .utils import GEO_READ_KWARGS, GEO_WRITE_KWARGS, mock_objecttype
from .utils import mock_objecttype

OBJECT_TYPE = "https://example.com/objecttypes/v1/types/a6c109"

Expand All @@ -28,7 +28,7 @@ def test_retrieve_object(self, m):
)
url = reverse("object-detail", args=[object.uuid])

response = self.client.get(url, **GEO_READ_KWARGS)
response = self.client.get(url)

self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down Expand Up @@ -69,7 +69,7 @@ def test_create_object(self, m):
},
}

response = self.client.post(url, data, **GEO_WRITE_KWARGS)
response = self.client.post(url, data)

self.assertEqual(response.status_code, status.HTTP_201_CREATED)

Expand Down Expand Up @@ -109,7 +109,7 @@ def test_update_object(self, m):
},
}

response = self.client.put(url, data, **GEO_WRITE_KWARGS)
response = self.client.put(url, data)

self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down Expand Up @@ -154,7 +154,7 @@ def test_patch_object_record(self, m):
},
}

response = self.client.patch(url, data, **GEO_WRITE_KWARGS)
response = self.client.patch(url, data)

self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down Expand Up @@ -198,7 +198,7 @@ def test_history_object(self, m):
)
url = reverse("object-history", args=[object.uuid])

response = self.client.get(url, **GEO_READ_KWARGS)
response = self.client.get(url)

self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down
16 changes: 8 additions & 8 deletions src/objects/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from objects.core.models import Object
from objects.core.tests.factores import ObjectRecordFactory

from .utils import GEO_READ_KWARGS, GEO_WRITE_KWARGS, mock_objecttype
from .utils import mock_objecttype

OBJECT_TYPE = "https://example.com/objecttypes/v1/types/a6c109"

Expand All @@ -28,7 +28,7 @@ def test_create_object_invalid_objecttype_url(self, m):
},
}

response = self.client.post(url, data, **GEO_WRITE_KWARGS)
response = self.client.post(url, data)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(Object.objects.count(), 0)
Expand All @@ -53,7 +53,7 @@ def test_create_object_no_version(self, m):
},
}

response = self.client.post(url, data, **GEO_WRITE_KWARGS)
response = self.client.post(url, data)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(Object.objects.count(), 0)
Expand All @@ -77,7 +77,7 @@ def test_create_object_schema_invalid(self, m):
},
}

response = self.client.post(url, data, **GEO_WRITE_KWARGS)
response = self.client.post(url, data)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(Object.objects.count(), 0)
Expand All @@ -93,7 +93,7 @@ def test_create_object_without_record_invalid(self, m):
"type": OBJECT_TYPE,
}

response = self.client.post(url, data, **GEO_WRITE_KWARGS)
response = self.client.post(url, data)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(Object.objects.count(), 0)
Expand All @@ -113,7 +113,7 @@ def test_create_object_correction_invalid(self, m):
},
}

response = self.client.post(url, data, **GEO_WRITE_KWARGS)
response = self.client.post(url, data)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(Object.objects.exclude(id=record.object.id).count(), 0)
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_update_object_with_correction_invalid(self, m):
},
}

response = self.client.put(url, data, **GEO_WRITE_KWARGS)
response = self.client.put(url, data)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

Expand All @@ -166,7 +166,7 @@ def test_update_object_type_invalid(self, m):
"type": OBJECT_TYPE,
}

response = self.client.patch(url, data, **GEO_WRITE_KWARGS)
response = self.client.patch(url, data)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

Expand Down
5 changes: 0 additions & 5 deletions src/objects/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
GEO_READ_KWARGS = {"HTTP_ACCEPT_CRS": "EPSG:4326"}

GEO_WRITE_KWARGS = {"HTTP_ACCEPT_CRS": "EPSG:4326", "HTTP_CONTENT_CRS": "EPSG:4326"}


def mock_objecttype(url: str) -> dict:
return {
"url": url,
Expand Down
13 changes: 13 additions & 0 deletions src/objects/utils/inspectors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from vng_api_common.inspectors.geojson import (
GeometryFieldInspector as _GeometryFieldInspector,
)


class GeometryFieldInspector(_GeometryFieldInspector):
""" don't show GEO headers since they are not required now"""

def get_request_header_parameters(self, serializer):
return []

def get_response_headers(self, serializer, status=None):
return None

0 comments on commit 1498e0e

Please sign in to comment.