5
5
from django .core .files .storage .memory import InMemoryStorage
6
6
from django .test import TestCase
7
7
8
- from open_inwoner .openzaak .import_export import (
9
- CatalogusConfigExport ,
10
- CatalogusConfigImport ,
11
- )
8
+ from open_inwoner .openzaak .import_export import ZGWConfigExport , ZGWConfigImport
12
9
from open_inwoner .openzaak .models import (
13
10
CatalogusConfig ,
14
11
ZaakTypeConfig ,
29
26
30
27
31
28
class ZGWExportImportMockData :
32
- def __init__ (self , count = 0 ):
29
+ def __init__ (self , count = 0 , with_dupes = False ):
33
30
self .original_url = f"https://foo.{ count } .maykinmedia.nl"
34
31
self .original_uuid = "a1591906-3368-470a-a957-4b8634c275a1"
35
32
self .service = ServiceFactory (slug = f"service-{ count } " )
@@ -81,6 +78,14 @@ def __init__(self, count=0):
81
78
omschrijving = "informatieobject" ,
82
79
zaaktype_uuids = [self .original_uuid ],
83
80
)
81
+ if with_dupes :
82
+ self .ztc_resultaat_2 = ZaakTypeResultaatTypeConfigFactory (
83
+ zaaktype_config = self .ztc ,
84
+ resultaattype_url = self .original_url ,
85
+ omschrijving = "status omschrijving" , # test dupes across models
86
+ zaaktype_uuids = [self .original_uuid ],
87
+ description = "" ,
88
+ )
84
89
85
90
86
91
class ExportObjectTests (TestCase ):
@@ -94,17 +99,17 @@ def test_export_only_accepts_queryset(self):
94
99
for arg in (list (), set (), tuple (), None , "" , CatalogusConfig .objects .first ()):
95
100
with self .subTest (f"Default factory should not accept { arg } " ):
96
101
with self .assertRaises (TypeError ):
97
- CatalogusConfigExport .from_catalogus_configs (arg )
102
+ ZGWConfigExport .from_catalogus_configs (arg )
98
103
99
104
def test_export_only_accepts_queryset_of_correct_type (self ):
100
105
with self .assertRaises (ValueError ):
101
- CatalogusConfigExport .from_catalogus_configs (ZaakTypeConfig .objects .all ())
106
+ ZGWConfigExport .from_catalogus_configs (ZaakTypeConfig .objects .all ())
102
107
103
108
def test_equality_operator (self ):
104
- export_a = CatalogusConfigExport .from_catalogus_configs (
109
+ export_a = ZGWConfigExport .from_catalogus_configs (
105
110
CatalogusConfig .objects .filter (pk = self .mocks [0 ].catalogus .pk )
106
111
)
107
- export_b = CatalogusConfigExport .from_catalogus_configs (
112
+ export_b = ZGWConfigExport .from_catalogus_configs (
108
113
CatalogusConfig .objects .filter (pk = self .mocks [1 ].catalogus .pk )
109
114
)
110
115
@@ -113,14 +118,14 @@ def test_equality_operator(self):
113
118
self .assertFalse (export_a == export_b )
114
119
115
120
def test_only_models_related_to_exported_catalogus_config_are_included (self ):
116
- export = CatalogusConfigExport .from_catalogus_configs (
121
+ export = ZGWConfigExport .from_catalogus_configs (
117
122
CatalogusConfig .objects .filter (pk = self .mocks [0 ].catalogus .pk )
118
123
)
119
124
120
125
for export_field , mock_field in zip (
121
126
(
122
127
"catalogus_configs" ,
123
- "zaak_type_configs " ,
128
+ "zaaktype_configs " ,
124
129
"zaak_status_type_configs" ,
125
130
"zaak_resultaat_type_configs" ,
126
131
"zaak_informatie_object_type_configs" ,
@@ -148,6 +153,79 @@ def test_only_models_related_to_exported_catalogus_config_are_included(self):
148
153
)
149
154
150
155
156
+ class ZaakTypeConfigExportTest (TestCase ):
157
+ def setUp (self ):
158
+ self .mocks = ZGWExportImportMockData (0 )
159
+
160
+ def test_export_zaaktype_configs (self ):
161
+ export = ZGWConfigExport .from_zaaktype_configs (
162
+ ZaakTypeConfig .objects .filter (pk = self .mocks .ztc .pk )
163
+ )
164
+ rows = export .as_dicts ()
165
+
166
+ expected = [
167
+ {
168
+ "model" : "openzaak.zaaktypeconfig" ,
169
+ "fields" : {
170
+ "urls" : '["https://foo.0.maykinmedia.nl"]' ,
171
+ "catalogus" : ["DM-0" , "123456789" ],
172
+ "identificatie" : "ztc-id-a-0" ,
173
+ "omschrijving" : "zaaktypeconfig" ,
174
+ "notify_status_changes" : False ,
175
+ "description" : "" ,
176
+ "external_document_upload_url" : "" ,
177
+ "document_upload_enabled" : False ,
178
+ "contact_form_enabled" : False ,
179
+ "contact_subject_code" : "" ,
180
+ "relevante_zaakperiode" : None ,
181
+ },
182
+ },
183
+ {
184
+ "model" : "openzaak.zaaktypeinformatieobjecttypeconfig" ,
185
+ "fields" : {
186
+ "zaaktype_config" : ["ztc-id-a-0" , "DM-0" , "123456789" ],
187
+ "informatieobjecttype_url" : "https://foo.0.maykinmedia.nl" ,
188
+ "omschrijving" : "informatieobject" ,
189
+ "zaaktype_uuids" : '["a1591906-3368-470a-a957-4b8634c275a1"]' ,
190
+ "document_upload_enabled" : False ,
191
+ "document_notification_enabled" : False ,
192
+ },
193
+ },
194
+ {
195
+ "model" : "openzaak.zaaktypestatustypeconfig" ,
196
+ "fields" : {
197
+ "zaaktype_config" : ["ztc-id-a-0" , "DM-0" , "123456789" ],
198
+ "statustype_url" : "https://foo.0.maykinmedia.nl" ,
199
+ "omschrijving" : "status omschrijving" ,
200
+ "statustekst" : "" ,
201
+ "zaaktype_uuids" : '["a1591906-3368-470a-a957-4b8634c275a1"]' ,
202
+ "status_indicator" : "" ,
203
+ "status_indicator_text" : "" ,
204
+ "document_upload_description" : "" ,
205
+ "description" : "status" ,
206
+ "notify_status_change" : True ,
207
+ "action_required" : False ,
208
+ "document_upload_enabled" : True ,
209
+ "call_to_action_url" : "" ,
210
+ "call_to_action_text" : "" ,
211
+ "case_link_text" : "" ,
212
+ },
213
+ },
214
+ {
215
+ "model" : "openzaak.zaaktyperesultaattypeconfig" ,
216
+ "fields" : {
217
+ "zaaktype_config" : ["ztc-id-a-0" , "DM-0" , "123456789" ],
218
+ "resultaattype_url" : "https://foo.0.maykinmedia.nl" ,
219
+ "omschrijving" : "resultaat" ,
220
+ "zaaktype_uuids" : '["a1591906-3368-470a-a957-4b8634c275a1"]' ,
221
+ "description" : "" ,
222
+ },
223
+ },
224
+ ]
225
+
226
+ self .assertEqual (rows , expected )
227
+
228
+
151
229
class TestCatalogusExport (TestCase ):
152
230
def setUp (self ):
153
231
self .mocks = [
@@ -156,7 +234,7 @@ def setUp(self):
156
234
]
157
235
158
236
def test_export_catalogus_configs (self ):
159
- export = CatalogusConfigExport .from_catalogus_configs (
237
+ export = ZGWConfigExport .from_catalogus_configs (
160
238
CatalogusConfig .objects .filter (pk = self .mocks [0 ].catalogus .pk )
161
239
)
162
240
rows = export .as_dicts ()
@@ -233,9 +311,7 @@ def test_export_catalogus_configs(self):
233
311
self .assertEqual (rows , expected )
234
312
235
313
def test_export_catalogus_configs_as_jsonl (self ):
236
- export = CatalogusConfigExport .from_catalogus_configs (
237
- CatalogusConfig .objects .all ()
238
- )
314
+ export = ZGWConfigExport .from_catalogus_configs (CatalogusConfig .objects .all ())
239
315
rows = list (export .as_jsonl_iter ())
240
316
241
317
expected = [
@@ -276,6 +352,7 @@ def setUp(self):
276
352
]
277
353
self .json_dupes = [
278
354
'{"model": "openzaak.zaaktypestatustypeconfig", "fields": {"zaaktype_config": ["ztc-id-a-0", "DM-0", "123456789"], "statustype_url": "https://bar.maykinmedia.nl", "omschrijving": "status omschrijving", "statustekst": "statustekst nieuw", "zaaktype_uuids": "[]", "status_indicator": "", "status_indicator_text": "", "document_upload_description": "", "description": "status", "notify_status_change": true, "action_required": false, "document_upload_enabled": true, "call_to_action_url": "", "call_to_action_text": "", "case_link_text": ""}}' ,
355
+ '{"model": "openzaak.zaaktyperesultaattypeconfig", "fields": {"zaaktype_config": ["ztc-id-a-0", "DM-0", "123456789"], "resultaattype_url": "https://bar.maykinmedia.nl", "omschrijving": "status omschrijving", "zaaktype_uuids": "[]", "description": "description new"}}' ,
279
356
]
280
357
self .jsonl = "\n " .join (self .json_lines )
281
358
self .jsonl_with_dupes = "\n " .join (self .json_lines + self .json_dupes )
@@ -284,14 +361,14 @@ def test_import_jsonl_update_success(self):
284
361
mocks = ZGWExportImportMockData ()
285
362
self .storage .save ("import.jsonl" , io .StringIO (self .jsonl ))
286
363
287
- import_result = CatalogusConfigImport .import_from_jsonl_file_in_django_storage (
364
+ import_result = ZGWConfigImport .import_from_jsonl_file_in_django_storage (
288
365
"import.jsonl" , self .storage
289
366
)
290
367
291
368
# check import
292
369
self .assertEqual (
293
370
import_result ,
294
- CatalogusConfigImport (
371
+ ZGWConfigImport (
295
372
total_rows_processed = 5 ,
296
373
catalogus_configs_imported = 1 ,
297
374
zaaktype_configs_imported = 1 ,
@@ -371,7 +448,7 @@ def test_import_jsonl_missing_statustype_config(self):
371
448
# we use `asdict` and replace the Exceptions with string representations
372
449
# because for Exceptions raised from within dataclasses, equality ==/is identity
373
450
import_result = dataclasses .asdict (
374
- CatalogusConfigImport .import_from_jsonl_file_in_django_storage (
451
+ ZGWConfigImport .import_from_jsonl_file_in_django_storage (
375
452
"import.jsonl" , self .storage
376
453
)
377
454
)
@@ -380,7 +457,7 @@ def test_import_jsonl_missing_statustype_config(self):
380
457
"ZaakTypeConfig identificatie = 'ztc-id-a-0'"
381
458
)
382
459
import_expected = dataclasses .asdict (
383
- CatalogusConfigImport (
460
+ ZGWConfigImport (
384
461
total_rows_processed = 6 ,
385
462
catalogus_configs_imported = 1 ,
386
463
zaaktype_configs_imported = 1 ,
@@ -417,7 +494,7 @@ def test_import_jsonl_update_statustype_config_missing_zt_config(self):
417
494
# we use `asdict` and replace the Exceptions with string representations
418
495
# because for Exceptions raised from within dataclasses, equality ==/is identity
419
496
import_result = dataclasses .asdict (
420
- CatalogusConfigImport .import_from_jsonl_file_in_django_storage (
497
+ ZGWConfigImport .import_from_jsonl_file_in_django_storage (
421
498
"import.jsonl" , self .storage
422
499
)
423
500
)
@@ -426,7 +503,7 @@ def test_import_jsonl_update_statustype_config_missing_zt_config(self):
426
503
"ZaakTypeConfig identificatie = 'bogus'"
427
504
)
428
505
import_expected = dataclasses .asdict (
429
- CatalogusConfigImport (
506
+ ZGWConfigImport (
430
507
total_rows_processed = 6 ,
431
508
catalogus_configs_imported = 1 ,
432
509
zaaktype_configs_imported = 1 ,
@@ -463,7 +540,7 @@ def test_import_jsonl_update_reports_duplicate_db_records(self):
463
540
# we use `asdict` and replace the Exceptions with string representations
464
541
# because for Exceptions raised from within dataclasses, equality ==/is identity
465
542
import_result = dataclasses .asdict (
466
- CatalogusConfigImport .import_from_jsonl_file_in_django_storage (
543
+ ZGWConfigImport .import_from_jsonl_file_in_django_storage (
467
544
"import.jsonl" , self .storage
468
545
)
469
546
)
@@ -472,7 +549,7 @@ def test_import_jsonl_update_reports_duplicate_db_records(self):
472
549
"ZaakTypeConfig identificatie = 'ztc-id-a-0'"
473
550
)
474
551
import_expected = dataclasses .asdict (
475
- CatalogusConfigImport (
552
+ ZGWConfigImport (
476
553
total_rows_processed = 5 ,
477
554
catalogus_configs_imported = 1 ,
478
555
zaaktype_configs_imported = 1 ,
@@ -489,14 +566,14 @@ def test_import_jsonl_update_reports_duplicate_db_records(self):
489
566
self .assertEqual (import_result , import_expected )
490
567
491
568
def test_import_jsonl_update_reports_duplicate_natural_keys_in_upload_file (self ):
492
- mocks = ZGWExportImportMockData ()
569
+ mocks = ZGWExportImportMockData (with_dupes = True )
493
570
494
571
self .storage .save ("import.jsonl" , io .StringIO (self .jsonl_with_dupes ))
495
572
496
573
# we use `asdict` and replace the Exceptions with string representations
497
574
# because for Exceptions raised from within dataclasses, equality ==/is identity
498
575
import_result = dataclasses .asdict (
499
- CatalogusConfigImport .import_from_jsonl_file_in_django_storage (
576
+ ZGWConfigImport .import_from_jsonl_file_in_django_storage (
500
577
"import.jsonl" , self .storage
501
578
)
502
579
)
@@ -505,13 +582,14 @@ def test_import_jsonl_update_reports_duplicate_natural_keys_in_upload_file(self)
505
582
"natural keys: omschrijving = 'status omschrijving', ZaakTypeConfig identificatie = 'ztc-id-a-0'"
506
583
)
507
584
import_expected = dataclasses .asdict (
508
- CatalogusConfigImport (
509
- total_rows_processed = 6 ,
585
+ ZGWConfigImport (
586
+ total_rows_processed = 7 ,
510
587
catalogus_configs_imported = 1 ,
511
588
zaaktype_configs_imported = 1 ,
512
589
zaak_informatie_object_type_configs_imported = 1 ,
513
590
zaak_status_type_configs_imported = 1 ,
514
- zaak_resultaat_type_configs_imported = 1 ,
591
+ # resultaat_type_config with "status omschrijving" should be imported
592
+ zaak_resultaat_type_configs_imported = 2 ,
515
593
import_errors = [expected_error ],
516
594
),
517
595
)
@@ -538,9 +616,7 @@ def test_import_jsonl_fails_with_catalogus_domein_rsin_mismatch(self):
538
616
with self .assertLogs (
539
617
logger = "open_inwoner.openzaak.import_export" , level = "ERROR"
540
618
) as cm :
541
- import_result = CatalogusConfigImport .from_jsonl_stream_or_string (
542
- import_line
543
- )
619
+ import_result = ZGWConfigImport .from_jsonl_stream_or_string (import_line )
544
620
self .assertEqual (
545
621
cm .output ,
546
622
[
@@ -567,7 +643,7 @@ def test_import_jsonl_fails_with_catalogus_domein_rsin_mismatch(self):
567
643
def test_bad_import_types (self ):
568
644
for bad_type in (set (), list (), b"" ):
569
645
with self .assertRaises (ValueError ):
570
- CatalogusConfigImport .from_jsonl_stream_or_string (bad_type )
646
+ ZGWConfigImport .from_jsonl_stream_or_string (bad_type )
571
647
572
648
def test_valid_input_types_are_accepted (self ):
573
649
ZGWExportImportMockData ()
@@ -578,10 +654,10 @@ def test_valid_input_types_are_accepted(self):
578
654
self .jsonl ,
579
655
):
580
656
with self .subTest (f"Input type { type (input )} " ):
581
- import_result = CatalogusConfigImport .from_jsonl_stream_or_string (input )
657
+ import_result = ZGWConfigImport .from_jsonl_stream_or_string (input )
582
658
self .assertEqual (
583
659
import_result ,
584
- CatalogusConfigImport (
660
+ ZGWConfigImport (
585
661
total_rows_processed = 5 ,
586
662
catalogus_configs_imported = 1 ,
587
663
zaaktype_configs_imported = 1 ,
@@ -597,9 +673,7 @@ def test_import_is_atomic(self):
597
673
bad_jsonl = self .jsonl + "\n " + bad_line
598
674
599
675
with self .assertRaises (KeyError ):
600
- CatalogusConfigImport .from_jsonl_stream_or_string (
601
- stream_or_string = bad_jsonl
602
- )
676
+ ZGWConfigImport .from_jsonl_stream_or_string (stream_or_string = bad_jsonl )
603
677
604
678
counts = (
605
679
CatalogusConfig .objects .count (),
@@ -622,11 +696,7 @@ def setUp(self):
622
696
ZGWExportImportMockData ()
623
697
624
698
def test_exports_can_be_imported (self ):
625
- export = CatalogusConfigExport .from_catalogus_configs (
626
- CatalogusConfig .objects .all ()
627
- )
628
- import_result = CatalogusConfigImport .from_jsonl_stream_or_string (
629
- export .as_jsonl ()
630
- )
699
+ export = ZGWConfigExport .from_catalogus_configs (CatalogusConfig .objects .all ())
700
+ import_result = ZGWConfigImport .from_jsonl_stream_or_string (export .as_jsonl ())
631
701
632
702
self .assertEqual (import_result .total_rows_processed , 5 )
0 commit comments