-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛[#449] support objecttypes API with pagination #454
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from django.test import TestCase, tag | ||
from django.urls import reverse | ||
|
||
from maykin_2fa.test import disable_admin_mfa | ||
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 | ||
|
||
|
||
@disable_admin_mfa() | ||
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", | ||
) | ||
object_type = ObjectTypeFactory( | ||
service=v1_service, uuid="71a2452a-66c3-4030-b5ec-a06035102e9e" | ||
) | ||
|
||
response = self.client.get(self.url) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
|
||
form = response.context["adminform"].form | ||
choices = list(form.fields["object_type"].choices) | ||
|
||
self.assertEqual( | ||
choices[1][0].value, | ||
object_type.id, | ||
) | ||
self.assertEqual( | ||
choices[1][1], | ||
f"{v1_service.label}: {object_type._name}", | ||
) | ||
|
||
@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", | ||
Comment on lines
+69
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should a docker container be made for objecttypes for testing here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so. We should be able to change and modify these tests.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've split this into a separate issue #457 |
||
) | ||
object_type = ObjectTypeFactory( | ||
service=v2_service, uuid="71a2452a-66c3-4030-b5ec-a06035102e9e" | ||
) | ||
|
||
response = self.client.get(self.url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
form = response.context["adminform"].form | ||
choices = list(form.fields["object_type"].choices) | ||
|
||
self.assertEqual( | ||
choices[1][0].value, | ||
object_type.id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bit of a nitpick, but is it possible to check the label here as well? Currently it will probably just check if the |
||
) | ||
Comment on lines
+82
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like there was an easier way to check this with normal Django but maybe I'm thinking of webtest. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm yeah I think that's probably webtest |
||
self.assertEqual( | ||
choices[1][1], | ||
f"{v2_service.label}: {object_type._name}", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check will be pointless once Objectstypes API V1 is discontinued