9
9
10
10
from open_inwoner .accounts .choices import LoginTypeChoices
11
11
from open_inwoner .accounts .tests .factories import UserFactory
12
+ from open_inwoner .accounts .views .cases import SimpleFile
13
+ from open_inwoner .utils .test import paginated_response
12
14
13
- from ...accounts .views .cases import SimpleFile
14
15
from ..models import OpenZaakConfig
15
16
from .factories import ServiceFactory
16
17
18
+ ZAKEN_ROOT = "https://zaken.nl/api/v1/"
17
19
CATALOGI_ROOT = "https://catalogi.nl/api/v1/"
18
20
DOCUMENTEN_ROOT = "https://documenten.nl/api/v1/"
19
21
@@ -31,6 +33,12 @@ def setUpTestData(self):
31
33
login_type = LoginTypeChoices .
digid ,
bsn = "900222086" ,
email = "[email protected] "
32
34
)
33
35
self .config = OpenZaakConfig .get_solo ()
36
+ self .zaak_service = ServiceFactory (api_root = ZAKEN_ROOT , api_type = APITypes .zrc )
37
+ self .config .zaak_service = self .zaak_service
38
+ self .catalogi_service = ServiceFactory (
39
+ api_root = CATALOGI_ROOT , api_type = APITypes .ztc
40
+ )
41
+ self .config .catalogi_service = self .catalogi_service
34
42
self .document_service = ServiceFactory (
35
43
api_root = DOCUMENTEN_ROOT , api_type = APITypes .drc
36
44
)
@@ -40,6 +48,35 @@ def setUpTestData(self):
40
48
)
41
49
self .config .save ()
42
50
51
+ self .zaak = generate_oas_component (
52
+ "zrc" ,
53
+ "schemas/Zaak" ,
54
+ uuid = "d8bbdeb7-770f-4ca9-b1ea-77b4730bf67d" ,
55
+ url = f"{ ZAKEN_ROOT } zaken/d8bbdeb7-770f-4ca9-b1ea-77b4730bf67d" ,
56
+ zaaktype = f"{ CATALOGI_ROOT } zaaktypen/53340e34-7581-4b04-884f" ,
57
+ identificatie = "ZAAK-2022-0000000024" ,
58
+ omschrijving = "Zaak naar aanleiding van ingezonden formulier" ,
59
+ startdatum = "2022-01-02" ,
60
+ einddatum = None ,
61
+ status = f"{ ZAKEN_ROOT } statussen/3da89990-c7fc-476a-ad13-c9023450083c" ,
62
+ )
63
+ self .zaak_informatie_object = generate_oas_component (
64
+ "zrc" ,
65
+ "schemas/ZaakInformatieObject" ,
66
+ url = f"{ ZAKEN_ROOT } zaakinformatieobjecten/e55153aa-ad2c-4a07-ae75-15add57d6" ,
67
+ informatieobject = f"{ DOCUMENTEN_ROOT } enkelvoudiginformatieobjecten/014c38fe-b010-4412-881c-3000032fb812" ,
68
+ zaak = f"{ ZAKEN_ROOT } zaken/d8bbdeb7-770f-4ca9-b1ea-77b4730bf67d" ,
69
+ aard_relatie_weergave = "some content" ,
70
+ titel = "" ,
71
+ beschrijving = "" ,
72
+ registratiedatum = "2021-01-12" ,
73
+ )
74
+ self .role = generate_oas_component (
75
+ "zrc" ,
76
+ "schemas/Rol" ,
77
+ url = f"{ ZAKEN_ROOT } rollen/f33153aa-ad2c-4a07-ae75-15add5891" ,
78
+ betrokkene_identificatie = "foo" ,
79
+ )
43
80
self .informatie_object_content = "my document content" .encode ("utf8" )
44
81
self .informatie_object = generate_oas_component (
45
82
"drc" ,
@@ -60,13 +97,33 @@ def setUpTestData(self):
60
97
url = reverse (
61
98
"accounts:case_document_download" ,
62
99
kwargs = {
63
- "object_id" : self .informatie_object ["uuid" ],
100
+ "object_id" : self .zaak ["uuid" ],
101
+ "info_id" : self .informatie_object ["uuid" ],
64
102
},
65
103
),
66
104
)
67
105
68
- def _setUpMocks (self , m ):
106
+ def _setUpOASMocks (self , m ):
107
+ mock_service_oas_get (m , ZAKEN_ROOT , "zrc" )
108
+ mock_service_oas_get (m , CATALOGI_ROOT , "ztc" )
69
109
mock_service_oas_get (m , DOCUMENTEN_ROOT , "drc" )
110
+
111
+ def _setUpAccessMocks (self , m ):
112
+ # the minimal mocks needed to be able to access the information object
113
+ self ._setUpOASMocks (m )
114
+ m .get (self .zaak ["url" ], json = self .zaak )
115
+ m .get (
116
+ f"{ ZAKEN_ROOT } rollen?zaak={ self .zaak ['url' ]} &betrokkeneIdentificatie__natuurlijkPersoon__inpBsn={ self .user .bsn } " ,
117
+ json = paginated_response ([self .role ]),
118
+ )
119
+ m .get (
120
+ f"{ ZAKEN_ROOT } zaakinformatieobjecten?zaak={ self .zaak ['url' ]} &informatieobject={ self .informatie_object ['url' ]} " ,
121
+ # note the real API doesn't return a paginated_response here
122
+ json = [self .zaak_informatie_object ],
123
+ )
124
+
125
+ def _setUpMocks (self , m ):
126
+ self ._setUpAccessMocks (m )
70
127
m .get (self .informatie_object ["url" ], json = self .informatie_object )
71
128
m .get (self .informatie_object ["inhoud" ], content = self .informatie_object_content )
72
129
@@ -75,7 +132,8 @@ def test_document_content_is_retrieved_when_user_logged_in_via_digid(self, m):
75
132
url = reverse (
76
133
"accounts:case_document_download" ,
77
134
kwargs = {
78
- "object_id" : self .informatie_object ["uuid" ],
135
+ "object_id" : self .zaak ["uuid" ],
136
+ "info_id" : self .informatie_object ["uuid" ],
79
137
},
80
138
)
81
139
response = self .app .get (url , user = self .user )
@@ -94,7 +152,8 @@ def test_document_content_is_retrieved_when_user_logged_in_via_digid(self, m):
94
152
)
95
153
96
154
def test_document_content_with_bad_status_is_http_403 (self , m ):
97
- mock_service_oas_get (m , DOCUMENTEN_ROOT , "drc" )
155
+ self ._setUpAccessMocks (m )
156
+
98
157
info_object = generate_oas_component (
99
158
"drc" ,
100
159
"schemas/EnkelvoudigInformatieObject" ,
@@ -109,13 +168,15 @@ def test_document_content_with_bad_status_is_http_403(self, m):
109
168
url = reverse (
110
169
"accounts:case_document_download" ,
111
170
kwargs = {
112
- "object_id" : info_object ["uuid" ],
171
+ "object_id" : self .zaak ["uuid" ],
172
+ "info_id" : info_object ["uuid" ],
113
173
},
114
174
)
115
175
self .app .get (url , user = self .user , status = 403 )
116
176
117
177
def test_document_content_with_bad_confidentiality_is_http_403 (self , m ):
118
- mock_service_oas_get (m , DOCUMENTEN_ROOT , "drc" )
178
+ self ._setUpAccessMocks (m )
179
+
119
180
info_object = generate_oas_component (
120
181
"drc" ,
121
182
"schemas/EnkelvoudigInformatieObject" ,
@@ -130,7 +191,8 @@ def test_document_content_with_bad_confidentiality_is_http_403(self, m):
130
191
url = reverse (
131
192
"accounts:case_document_download" ,
132
193
kwargs = {
133
- "object_id" : info_object ["uuid" ],
194
+ "object_id" : self .zaak ["uuid" ],
195
+ "info_id" : info_object ["uuid" ],
134
196
},
135
197
)
136
198
self .app .get (url , user = self .user , status = 403 )
@@ -156,27 +218,58 @@ def test_anonymous_user_has_no_access_to_download_page(self, m):
156
218
f"{ reverse ('login' )} ?next={ self .informatie_object_file .url } " ,
157
219
)
158
220
221
+ def test_no_data_is_retrieved_when_case_object_http_404 (self , m ):
222
+ self ._setUpOASMocks (m )
223
+ m .get (self .zaak ["url" ], status_code = 404 )
224
+
225
+ self .app .get (self .informatie_object_file .url , user = self .user , status = 404 )
226
+
227
+ def test_no_data_is_retrieved_when_no_related_roles_are_found_for_user_bsn (self , m ):
228
+ self ._setUpOASMocks (m )
229
+ m .get (self .zaak ["url" ], json = self .zaak )
230
+ m .get (
231
+ f"{ ZAKEN_ROOT } rollen?zaak={ self .zaak ['url' ]} &betrokkeneIdentificatie__natuurlijkPersoon__inpBsn={ self .user .bsn } " ,
232
+ # no roles found
233
+ json = paginated_response ([]),
234
+ )
235
+ self .app .get (self .informatie_object_file .url , user = self .user , status = 403 )
236
+
237
+ def test_no_data_is_retrieved_when_no_matching_case_info_object_is_found (self , m ):
238
+ self ._setUpOASMocks (m )
239
+ m .get (self .zaak ["url" ], json = self .zaak )
240
+ m .get (
241
+ f"{ ZAKEN_ROOT } rollen?zaak={ self .zaak ['url' ]} &betrokkeneIdentificatie__natuurlijkPersoon__inpBsn={ self .user .bsn } " ,
242
+ json = paginated_response ([self .role ]),
243
+ )
244
+ m .get (self .informatie_object ["url" ], json = self .informatie_object )
245
+ m .get (
246
+ f"{ ZAKEN_ROOT } zaakinformatieobjecten?zaak={ self .zaak ['url' ]} &informatieobject={ self .informatie_object ['url' ]} " ,
247
+ # no case info objects found
248
+ json = [],
249
+ )
250
+ self .app .get (self .informatie_object_file .url , user = self .user , status = 403 )
251
+
159
252
def test_no_data_is_retrieved_when_info_object_http_404 (self , m ):
160
- mock_service_oas_get ( m , DOCUMENTEN_ROOT , "drc" )
253
+ self . _setUpAccessMocks ( m )
161
254
m .get (self .informatie_object ["url" ], status_code = 404 )
162
255
163
256
self .app .get (self .informatie_object_file .url , user = self .user , status = 404 )
164
257
165
258
def test_no_data_is_retrieved_when_info_object_http_500 (self , m ):
166
- mock_service_oas_get ( m , DOCUMENTEN_ROOT , "drc" )
259
+ self . _setUpAccessMocks ( m )
167
260
m .get (self .informatie_object ["url" ], status_code = 500 )
168
261
169
262
self .app .get (self .informatie_object_file .url , user = self .user , status = 404 )
170
263
171
264
def test_no_data_is_retrieved_when_document_download_data_http_404 (self , m ):
172
- mock_service_oas_get ( m , DOCUMENTEN_ROOT , "drc" )
265
+ self . _setUpAccessMocks ( m )
173
266
m .get (self .informatie_object ["url" ], json = self .informatie_object )
174
267
m .get (self .informatie_object ["inhoud" ], status_code = 404 )
175
268
176
269
self .app .get (self .informatie_object_file .url , user = self .user , status = 404 )
177
270
178
271
def test_no_data_is_retrieved_when_document_download_data_http_500 (self , m ):
179
- mock_service_oas_get ( m , DOCUMENTEN_ROOT , "drc" )
272
+ self . _setUpAccessMocks ( m )
180
273
m .get (self .informatie_object ["url" ], json = self .informatie_object )
181
274
m .get (self .informatie_object ["inhoud" ], status_code = 500 )
182
275
0 commit comments