1
1
from pathlib import Path
2
- from unittest .mock import Mock , patch
3
2
4
3
from django .core .cache import cache
5
4
from django .test import TestCase
6
5
6
+ from django_setup_configuration .exceptions import ConfigurationRunFailed
7
7
from django_setup_configuration .test_utils import execute_single_step
8
8
from zgw_consumers .constants import APITypes
9
- from zgw_consumers .models import Service
10
9
from zgw_consumers .test .factories import ServiceFactory
11
10
12
11
from ...models import APIConfig
13
12
from ..steps import APIConfigConfigurationStep
14
13
15
14
TEST_FILES = (Path (__file__ ).parent / "files" ).resolve ()
16
- CONFIG_FILE_PATH_1 = str (TEST_FILES / "setup_config_api.yaml" )
17
- CONFIG_FILE_PATH_2 = str (TEST_FILES / "setup_config_api_different_service.yaml" )
15
+ CONFIG_FILE_PATH = str (TEST_FILES / "setup_config_api.yaml" )
18
16
19
17
20
18
class APIConfigConfigurationStepTests (TestCase ):
@@ -29,10 +27,13 @@ def test_configure_api_config_create_new(self):
29
27
api_type = APITypes .orc ,
30
28
api_root = "https://selectielijst.openzaak.nl/api/v1/" ,
31
29
)
30
+ config = APIConfig .get_solo ()
32
31
33
- execute_single_step ( APIConfigConfigurationStep , yaml_source = CONFIG_FILE_PATH_1 )
32
+ self . assertIsNone ( config . selectielijst_api_service )
34
33
35
- config = APIConfig .get_solo ()
34
+ execute_single_step (APIConfigConfigurationStep , yaml_source = CONFIG_FILE_PATH )
35
+
36
+ config .refresh_from_db ()
36
37
37
38
self .assertEqual (service .pk , config .selectielijst_api_service .pk )
38
39
@@ -48,36 +49,22 @@ def test_configure_api_config_update_existing(self):
48
49
config .selectielijst_api_service = service1
49
50
config .save ()
50
51
51
- execute_single_step (APIConfigConfigurationStep , yaml_source = CONFIG_FILE_PATH_2 )
52
+ execute_single_step (
53
+ APIConfigConfigurationStep ,
54
+ object_source = {
55
+ "api_configuration_enabled" : True ,
56
+ "api_configuration" : {
57
+ "selectielijst_service_identifier" : "selectielijst-new"
58
+ },
59
+ },
60
+ )
52
61
53
62
config .refresh_from_db ()
54
63
55
64
self .assertEqual (service2 .pk , config .selectielijst_api_service .pk )
56
65
57
66
def test_configure_api_config_missing_service (self ):
58
- with self .assertRaises (Service . DoesNotExist ):
67
+ with self .assertRaises (ConfigurationRunFailed ):
59
68
execute_single_step (
60
- APIConfigConfigurationStep , yaml_source = CONFIG_FILE_PATH_1
69
+ APIConfigConfigurationStep , yaml_source = CONFIG_FILE_PATH
61
70
)
62
-
63
- def test_idempotency (self ):
64
- service = ServiceFactory (
65
- slug = "selectielijst" ,
66
- api_type = APITypes .orc ,
67
- api_root = "https://selectielijst.openzaak.nl/api/v1/" ,
68
- )
69
-
70
- execute_single_step (APIConfigConfigurationStep , yaml_source = CONFIG_FILE_PATH_1 )
71
-
72
- mock = Mock ()
73
- config = APIConfig (selectielijst_api_service = service )
74
- with patch .object (config , "save" , new = mock .method ):
75
- with patch (
76
- "openarchiefbeheer.config.setup_configuration.steps.APIConfig.get_solo" ,
77
- return_value = config ,
78
- ):
79
- execute_single_step (
80
- APIConfigConfigurationStep , yaml_source = CONFIG_FILE_PATH_1
81
- )
82
-
83
- mock .method .assert_not_called ()
0 commit comments