Skip to content

Commit 0083434

Browse files
committed
[#4267] Refactor test to use VCR
1 parent d8f2286 commit 0083434

File tree

3 files changed

+213
-110
lines changed

3 files changed

+213
-110
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate, br
9+
Authorization:
10+
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyMDQ1OTE5NywiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.G5nvV_Ql-T934x3WK_YxPCXrV-nZiYpP_nHQeQSRinc
11+
Connection:
12+
- keep-alive
13+
User-Agent:
14+
- python-requests/2.32.2
15+
method: GET
16+
uri: http://localhost:8003/catalogi/api/v1/catalogussen
17+
response:
18+
body:
19+
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","domein":"TEST","rsin":"000000000","contactpersoonBeheerNaam":"Test
20+
name","contactpersoonBeheerTelefoonnummer":"","contactpersoonBeheerEmailadres":"","zaaktypen":["http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc","http://localhost:8003/catalogi/api/v1/zaaktypen/119dbe23-cbf2-4759-80e5-29bb28b3d95f"],"besluittypen":[],"informatieobjecttypen":["http://localhost:8003/catalogi/api/v1/informatieobjecttypen/7a474713-0833-402a-8441-e467c08ac55b","http://localhost:8003/catalogi/api/v1/informatieobjecttypen/b2d83b94-9b9b-4e80-a82f-73ff993c62f3","http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7"],"naam":"Test
21+
catalog","versie":"","begindatumVersie":null}]}'
22+
headers:
23+
API-version:
24+
- 1.3.1
25+
Allow:
26+
- GET, POST, HEAD, OPTIONS
27+
Content-Length:
28+
- '886'
29+
Content-Type:
30+
- application/json
31+
Cross-Origin-Opener-Policy:
32+
- same-origin
33+
Referrer-Policy:
34+
- same-origin
35+
Vary:
36+
- Accept, origin
37+
X-Content-Type-Options:
38+
- nosniff
39+
X-Frame-Options:
40+
- DENY
41+
status:
42+
code: 200
43+
message: OK
44+
- request:
45+
body: null
46+
headers:
47+
Accept:
48+
- '*/*'
49+
Accept-Encoding:
50+
- gzip, deflate, br
51+
Authorization:
52+
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyMDQ1OTE5NywiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.G5nvV_Ql-T934x3WK_YxPCXrV-nZiYpP_nHQeQSRinc
53+
Connection:
54+
- keep-alive
55+
User-Agent:
56+
- python-requests/2.32.2
57+
method: GET
58+
uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen
59+
response:
60+
body:
61+
string: '{"count":3,"next":null,"previous":null,"results":[{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"Attachment
62+
Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test
63+
category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":["http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc"],"beginObject":"2024-03-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/b2d83b94-9b9b-4e80-a82f-73ff993c62f3","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"CSV
64+
Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test
65+
category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/7a474713-0833-402a-8441-e467c08ac55b","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"PDF
66+
Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test
67+
category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null}]}'
68+
headers:
69+
API-version:
70+
- 1.3.1
71+
Allow:
72+
- GET, POST, HEAD, OPTIONS
73+
Content-Length:
74+
- '2517'
75+
Content-Type:
76+
- application/json
77+
Cross-Origin-Opener-Policy:
78+
- same-origin
79+
Referrer-Policy:
80+
- same-origin
81+
Vary:
82+
- Accept, origin
83+
X-Content-Type-Options:
84+
- nosniff
85+
X-Frame-Options:
86+
- DENY
87+
status:
88+
code: 200
89+
message: OK
90+
version: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate, br
9+
Authorization:
10+
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyMDQ1OTE5NywiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.G5nvV_Ql-T934x3WK_YxPCXrV-nZiYpP_nHQeQSRinc
11+
Connection:
12+
- keep-alive
13+
User-Agent:
14+
- python-requests/2.32.2
15+
method: GET
16+
uri: http://localhost:8003/catalogi/api/v1/catalogussen
17+
response:
18+
body:
19+
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","domein":"TEST","rsin":"000000000","contactpersoonBeheerNaam":"Test
20+
name","contactpersoonBeheerTelefoonnummer":"","contactpersoonBeheerEmailadres":"","zaaktypen":["http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc","http://localhost:8003/catalogi/api/v1/zaaktypen/119dbe23-cbf2-4759-80e5-29bb28b3d95f"],"besluittypen":[],"informatieobjecttypen":["http://localhost:8003/catalogi/api/v1/informatieobjecttypen/7a474713-0833-402a-8441-e467c08ac55b","http://localhost:8003/catalogi/api/v1/informatieobjecttypen/b2d83b94-9b9b-4e80-a82f-73ff993c62f3","http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7"],"naam":"Test
21+
catalog","versie":"","begindatumVersie":null}]}'
22+
headers:
23+
API-version:
24+
- 1.3.1
25+
Allow:
26+
- GET, POST, HEAD, OPTIONS
27+
Content-Length:
28+
- '886'
29+
Content-Type:
30+
- application/json
31+
Cross-Origin-Opener-Policy:
32+
- same-origin
33+
Referrer-Policy:
34+
- same-origin
35+
Vary:
36+
- Accept, origin
37+
X-Content-Type-Options:
38+
- nosniff
39+
X-Frame-Options:
40+
- DENY
41+
status:
42+
code: 200
43+
message: OK
44+
- request:
45+
body: null
46+
headers:
47+
Accept:
48+
- '*/*'
49+
Accept-Encoding:
50+
- gzip, deflate, br
51+
Authorization:
52+
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcyMDQ1OTE5NywiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.G5nvV_Ql-T934x3WK_YxPCXrV-nZiYpP_nHQeQSRinc
53+
Connection:
54+
- keep-alive
55+
User-Agent:
56+
- python-requests/2.32.2
57+
method: GET
58+
uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen
59+
response:
60+
body:
61+
string: '{"count":3,"next":null,"previous":null,"results":[{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"Attachment
62+
Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test
63+
category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":["http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc"],"beginObject":"2024-03-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/b2d83b94-9b9b-4e80-a82f-73ff993c62f3","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"CSV
64+
Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test
65+
category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null},{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/7a474713-0833-402a-8441-e467c08ac55b","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"PDF
66+
Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":null,"concept":false,"besluittypen":[],"informatieobjectcategorie":"Test
67+
category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":[],"beginObject":"2024-03-19","eindeObject":null}]}'
68+
headers:
69+
API-version:
70+
- 1.3.1
71+
Allow:
72+
- GET, POST, HEAD, OPTIONS
73+
Content-Length:
74+
- '2517'
75+
Content-Type:
76+
- application/json
77+
Cross-Origin-Opener-Policy:
78+
- same-origin
79+
Referrer-Policy:
80+
- same-origin
81+
Vary:
82+
- Accept, origin
83+
X-Content-Type-Options:
84+
- nosniff
85+
X-Frame-Options:
86+
- DENY
87+
status:
88+
code: 200
89+
message: OK
90+
version: 1
+33-110
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,46 @@
1-
import requests_mock
1+
from pathlib import Path
2+
23
from furl import furl
34
from rest_framework import status
45
from rest_framework.reverse import reverse
56
from rest_framework.test import APITestCase
6-
from zgw_consumers.test import generate_oas_component
7+
from zgw_consumers.constants import APITypes, AuthTypes
8+
from zgw_consumers.test.factories import ServiceFactory
79

810
from openforms.accounts.tests.factories import StaffUserFactory, UserFactory
9-
from openforms.registrations.contrib.objects_api.models import ObjectsAPIGroupConfig
11+
from openforms.registrations.contrib.objects_api.tests.factories import (
12+
ObjectsAPIGroupConfigFactory,
13+
)
1014
from openforms.registrations.contrib.zgw_apis.tests.factories import (
1115
ZGWApiGroupConfigFactory,
1216
)
17+
from openforms.utils.tests.vcr import OFVCRMixin
18+
1319

20+
class GetInformatieObjecttypesViewTests(OFVCRMixin, APITestCase):
21+
22+
VCR_TEST_FILES = Path(__file__).parent / "files"
1423

15-
@requests_mock.Mocker()
16-
class GetInformatieObjecttypesView(APITestCase):
1724
@classmethod
1825
def setUpTestData(cls):
1926
super().setUpTestData()
2027

21-
cls.zgw_group1 = ZGWApiGroupConfigFactory.create(
22-
zrc_service__api_root="https://zaken-1.nl/api/v1/",
23-
drc_service__api_root="https://documenten-1.nl/api/v1/",
24-
ztc_service__api_root="https://catalogus-1.nl/api/v1/",
25-
)
26-
cls.zgw_group2 = ZGWApiGroupConfigFactory.create(
27-
zrc_service__api_root="https://zaken-2.nl/api/v1/",
28-
drc_service__api_root="https://documenten-2.nl/api/v1/",
29-
ztc_service__api_root="https://catalogus-2.nl/api/v1/",
30-
)
31-
cls.objects_api_group1 = ObjectsAPIGroupConfig.objects.create(
32-
catalogi_service=cls.zgw_group1.ztc_service
33-
)
34-
35-
def install_mocks(self, m):
36-
informatieobjecttypen1 = [
37-
generate_oas_component(
38-
"catalogi",
39-
"schemas/InformatieObjectType",
40-
url="https://catalogus-1.nl/api/v1/informatieobjecttypen/111",
41-
catalogus="https://catalogus-1.nl/api/v1/catalogussen/111",
42-
),
43-
generate_oas_component(
44-
"catalogi",
45-
"schemas/InformatieObjectType",
46-
url="https://catalogus-1.nl/api/v1/informatieobjecttypen/222",
47-
catalogus="https://catalogus-1.nl/api/v1/catalogussen/111",
48-
),
49-
]
50-
m.get(
51-
"https://catalogus-1.nl/api/v1/catalogussen",
52-
status_code=200,
53-
json={
54-
"count": 1,
55-
"next": None,
56-
"previous": None,
57-
"results": [
58-
generate_oas_component(
59-
"catalogi",
60-
"schemas/Catalogus",
61-
url="https://catalogus-1.nl/api/v1/catalogussen/111",
62-
volgnummer=1,
63-
informatieobjecttypen=informatieobjecttypen1,
64-
),
65-
],
66-
},
67-
)
68-
m.get(
69-
"https://catalogus-1.nl/api/v1/informatieobjecttypen",
70-
status_code=200,
71-
json={
72-
"count": 2,
73-
"next": None,
74-
"previous": None,
75-
"results": informatieobjecttypen1,
76-
},
28+
# create services for the docker-compose Open Zaak instance.
29+
catalogi_service = ServiceFactory.create(
30+
api_root="http://localhost:8003/catalogi/api/v1/",
31+
api_type=APITypes.ztc,
32+
auth_type=AuthTypes.zgw,
33+
client_id="test_client_id",
34+
secret="test_secret_key",
7735
)
78-
79-
informatieobjecttypen2 = [
80-
generate_oas_component(
81-
"catalogi",
82-
"schemas/InformatieObjectType",
83-
url="https://catalogus-2.nl/api/v1/informatieobjecttypen/111",
84-
catalogus="https://catalogus-2.nl/api/v1/catalogussen/111",
85-
),
86-
]
87-
m.get(
88-
"https://catalogus-2.nl/api/v1/catalogussen",
89-
status_code=200,
90-
json={
91-
"count": 1,
92-
"next": None,
93-
"previous": None,
94-
"results": [
95-
generate_oas_component(
96-
"catalogi",
97-
"schemas/Catalogus",
98-
url="https://catalogus-2.nl/api/v1/catalogussen/111",
99-
volgnummer=1,
100-
informatieobjecttypen=informatieobjecttypen2,
101-
),
102-
],
103-
},
36+
cls.zgw_group = ZGWApiGroupConfigFactory.create(
37+
ztc_service=catalogi_service,
10438
)
105-
m.get(
106-
"https://catalogus-2.nl/api/v1/informatieobjecttypen",
107-
status_code=200,
108-
json={
109-
"count": 1,
110-
"next": None,
111-
"previous": None,
112-
"results": informatieobjecttypen2,
113-
},
39+
cls.objects_api_group = ObjectsAPIGroupConfigFactory.create(
40+
catalogi_service=catalogi_service,
11441
)
11542

116-
def test_must_be_logged_in_as_admin(self, m):
43+
def test_must_be_logged_in_as_admin(self):
11744
user = UserFactory.create()
11845
url = reverse("api:iotypen-list")
11946
self.client.force_login(user)
@@ -122,24 +49,22 @@ def test_must_be_logged_in_as_admin(self, m):
12249

12350
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
12451

125-
def test_retrieve_with_explicit_zgw_api_group(self, m):
52+
def test_retrieve_with_explicit_zgw_api_group(self):
12653
user = StaffUserFactory.create()
12754
url = furl(reverse("api:iotypen-list"))
128-
url.args["zgw_api_group"] = self.zgw_group2.pk
55+
url.args["zgw_api_group"] = self.zgw_group.pk
12956
url.args["registration_backend"] = "zgw-create-zaak"
13057
self.client.force_login(user)
13158

132-
self.install_mocks(m)
133-
13459
response = self.client.get(url.url)
13560

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

13863
data = response.json()
13964

140-
self.assertEqual(len(data), 1)
65+
self.assertEqual(len(data), 3)
14166

142-
def test_filter_with_invalid_zgw_group(self, m):
67+
def test_filter_with_invalid_zgw_group(self):
14368
user = StaffUserFactory.create()
14469
url = furl(reverse("api:iotypen-list"))
14570
url.args["zgw_api_group"] = "INVALID"
@@ -150,7 +75,7 @@ def test_filter_with_invalid_zgw_group(self, m):
15075

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

153-
def test_missing_zgw_api_group(self, m):
78+
def test_missing_zgw_api_group(self):
15479
user = StaffUserFactory.create()
15580
url = furl(reverse("api:iotypen-list"))
15681
url.args["registration_backend"] = "zgw-create-zaak"
@@ -160,7 +85,7 @@ def test_missing_zgw_api_group(self, m):
16085

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

163-
def test_missing_objects_api_group(self, m):
88+
def test_missing_objects_api_group(self):
16489
user = StaffUserFactory.create()
16590
url = furl(reverse("api:iotypen-list"))
16691
url.args["registration_backend"] = "objects_api"
@@ -170,19 +95,17 @@ def test_missing_objects_api_group(self, m):
17095

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

173-
def test_retrieve_with_explicit_objects_api_group(self, m):
98+
def test_retrieve_with_explicit_objects_api_group(self):
17499
user = StaffUserFactory.create()
175100
url = furl(reverse("api:iotypen-list"))
176-
url.args["objects_api_group"] = self.objects_api_group1.pk
101+
url.args["objects_api_group"] = self.objects_api_group.pk
177102
url.args["registration_backend"] = "objects_api"
178103
self.client.force_login(user)
179104

180-
self.install_mocks(m)
181-
182105
response = self.client.get(url.url)
183106

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

186109
data = response.json()
187110

188-
self.assertEqual(len(data), 2)
111+
self.assertEqual(len(data), 3)

0 commit comments

Comments
 (0)