Skip to content

Commit

Permalink
🐛[#449] support objecttypes API with pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Coperh committed Sep 24, 2024
1 parent 9de79f1 commit caea548
Show file tree
Hide file tree
Showing 4 changed files with 271 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/objects/token/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def get_data_field_choices(self):
except requests.JSONDecodeError:
continue

if "results" in response_data:
response_data = response_data["results"]

# use only first level of properties
data_fields[object_type.id] = {
version["version"]: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://127.0.0.1:8008/api/v1/objecttypes
response:
body:
string: '[{"url":"http://127.0.0.1:8008/api/v1/objecttypes/71a2452a-66c3-4030-b5ec-a06035102e9e","uuid":"71a2452a-66c3-4030-b5ec-a06035102e9e","name":"Garry","namePlural":"Garrys","description":"","dataClassification":"open","maintainerOrganization":"","maintainerDepartment":"","contactPerson":"","contactEmail":"","source":"","updateFrequency":"unknown","providerOrganization":"","documentationUrl":"","labels":{},"createdAt":"2024-09-24","modifiedAt":"2024-09-24","allowGeometry":true,"versions":["http://127.0.0.1:8008/api/v1/objecttypes/71a2452a-66c3-4030-b5ec-a06035102e9e/versions/1"]}]'
headers:
Allow:
- GET, POST, HEAD, OPTIONS
Content-Length:
- '584'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Tue, 24 Sep 2024 14:49:45 GMT
Referrer-Policy:
- same-origin
Server:
- WSGIServer/0.2 CPython/3.11.10
Server-Timing:
- TimerPanel_utime;dur=66.08599999999998;desc="User CPU time", TimerPanel_stime;dur=41.489;desc="System
CPU time", TimerPanel_total;dur=107.57499999999999;desc="Total CPU time",
TimerPanel_total_time;dur=109.82951400001184;desc="Elapsed time", SQLPanel_sql_time;dur=2.634805998241063;desc="SQL
3 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls"
Vary:
- origin, Cookie
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
djdt-store-id:
- 011b401c548140e393c17931b9eed7e2
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://127.0.0.1:8008/api/v1/objecttypes/71a2452a-66c3-4030-b5ec-a06035102e9e/versions
response:
body:
string: '[{"url":"http://127.0.0.1:8008/api/v1/objecttypes/71a2452a-66c3-4030-b5ec-a06035102e9e/versions/1","version":1,"objectType":"http://127.0.0.1:8008/api/v1/objecttypes/71a2452a-66c3-4030-b5ec-a06035102e9e","status":"draft","jsonSchema":{"string":"value"},"createdAt":"2024-09-24","modifiedAt":"2024-09-24","publishedAt":null}]'
headers:
Allow:
- GET, POST, HEAD, OPTIONS
Content-Length:
- '324'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Tue, 24 Sep 2024 14:49:45 GMT
Referrer-Policy:
- same-origin
Server:
- WSGIServer/0.2 CPython/3.11.10
Server-Timing:
- TimerPanel_utime;dur=26.51400000000004;desc="User CPU time", TimerPanel_stime;dur=8.871000000000018;desc="System
CPU time", TimerPanel_total;dur=35.385000000000055;desc="Total CPU time",
TimerPanel_total_time;dur=29.870047997974325;desc="Elapsed time", SQLPanel_sql_time;dur=3.140712000458734;desc="SQL
3 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls"
Vary:
- origin, Cookie
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
djdt-store-id:
- 58b76bf29d284ba694ccdabb76919aa7
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://127.0.0.1:8008/api/v2/objecttypes
response:
body:
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://127.0.0.1:8008/api/v2/objecttypes/71a2452a-66c3-4030-b5ec-a06035102e9e","uuid":"71a2452a-66c3-4030-b5ec-a06035102e9e","name":"Garry","namePlural":"Garrys","description":"","dataClassification":"open","maintainerOrganization":"","maintainerDepartment":"","contactPerson":"","contactEmail":"","source":"","updateFrequency":"unknown","providerOrganization":"","documentationUrl":"","labels":{},"createdAt":"2024-09-24","modifiedAt":"2024-09-24","allowGeometry":true,"versions":["http://127.0.0.1:8008/api/v2/objecttypes/71a2452a-66c3-4030-b5ec-a06035102e9e/versions/1"]}]}'
headers:
Allow:
- GET, POST, HEAD, OPTIONS
Content-Length:
- '634'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Tue, 24 Sep 2024 14:49:45 GMT
Referrer-Policy:
- same-origin
Server:
- WSGIServer/0.2 CPython/3.11.10
Server-Timing:
- TimerPanel_utime;dur=17.129999999999868;desc="User CPU time", TimerPanel_stime;dur=2.0120000000000138;desc="System
CPU time", TimerPanel_total;dur=19.141999999999882;desc="Total CPU time",
TimerPanel_total_time;dur=21.54170200083172;desc="Elapsed time", SQLPanel_sql_time;dur=2.798614998027915;desc="SQL
4 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls"
Vary:
- origin, Cookie
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
djdt-store-id:
- a591b4b56a884263835fbf632b782baf
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://127.0.0.1:8008/api/v2/objecttypes/71a2452a-66c3-4030-b5ec-a06035102e9e/versions
response:
body:
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://127.0.0.1:8008/api/v2/objecttypes/71a2452a-66c3-4030-b5ec-a06035102e9e/versions/1","version":1,"objectType":"http://127.0.0.1:8008/api/v2/objecttypes/71a2452a-66c3-4030-b5ec-a06035102e9e","status":"draft","jsonSchema":{"string":"value"},"createdAt":"2024-09-24","modifiedAt":"2024-09-24","publishedAt":null}]}'
headers:
Allow:
- GET, POST, HEAD, OPTIONS
Content-Length:
- '374'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Tue, 24 Sep 2024 14:49:45 GMT
Referrer-Policy:
- same-origin
Server:
- WSGIServer/0.2 CPython/3.11.10
Server-Timing:
- TimerPanel_utime;dur=17.527999999999988;desc="User CPU time", TimerPanel_stime;dur=0.8290000000000242;desc="System
CPU time", TimerPanel_total;dur=18.357000000000014;desc="Total CPU time",
TimerPanel_total_time;dur=20.605010002327617;desc="Elapsed time", SQLPanel_sql_time;dur=2.700799006561283;desc="SQL
4 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls"
Vary:
- origin, Cookie
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
djdt-store-id:
- fa6e9a070865404f8c02c2ad60df23b2
status:
code: 200
message: OK
version: 1
76 changes: 76 additions & 0 deletions src/objects/token/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from django.test import TestCase, tag
from django.urls import reverse

from vcr.unittest import VCRMixin
from zgw_consumers.constants import AuthTypes
from zgw_consumers.test.factories import ServiceFactory

from objects.accounts.tests.factories import UserFactory
from objects.core.tests.factories import ObjectTypeFactory


class PermissionAdminTests(VCRMixin, TestCase):

object_types_api = "http://127.0.0.1:8008/api/{version}/"

def setUp(self):
super().setUp()

self.user = UserFactory(superuser=True)
self.client.force_login(self.user)
self.url = reverse("admin:token_permission_add")

def _get_vcr(self, **kwargs):
vcr = super()._get_vcr(**kwargs)
vcr.filter_headers = ["authorization"]
return vcr

@tag("#449")
def test_with_object_types_api_v1(self):
"""
Regression test for #449.
Test if Permission admin can still handle objecttypes API V1
"""

v1_service = ServiceFactory(
api_root=self.object_types_api.format(version="v1"),
auth_type=AuthTypes.api_key,
header_key="Authorization",
header_value="Token 5cebbb33ffa725b6ed5e9e98300061218ba98d71",
)
ObjectTypeFactory(
service=v1_service, uuid="71a2452a-66c3-4030-b5ec-a06035102e9e"
)

response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)

self.assertEqual(
self.cassette.requests[1].uri,
"http://127.0.0.1:8008/api/v1/objecttypes/71a2452a-66c3-4030-b5ec-a06035102e9e/versions",
)
print(self.cassette.__dir__())

@tag("#449")
def test_with_object_types_api_v2(self):
"""
Regression test for #449.
Test if Permission admin can handle objecttypes API V2 which added pagination
"""
v2_service = ServiceFactory(
api_root=self.object_types_api.format(version="v2"),
auth_type=AuthTypes.api_key,
header_key="Authorization",
header_value="Token 5cebbb33ffa725b6ed5e9e98300061218ba98d71",
)
ObjectTypeFactory(
service=v2_service, uuid="71a2452a-66c3-4030-b5ec-a06035102e9e"
)

response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)

self.assertEqual(
self.cassette.requests[1].uri,
"http://127.0.0.1:8008/api/v2/objecttypes/71a2452a-66c3-4030-b5ec-a06035102e9e/versions",
)

0 comments on commit caea548

Please sign in to comment.