16
16
# https://creativecommons.org/licenses/by/4.0/legalcode
17
17
from typing import Any
18
18
19
- from dioptra .client .base import DioptraResponseProtocol
19
+ from dioptra .client .base import CollectionClient , DioptraResponseProtocol
20
20
from dioptra .client .drafts import (
21
21
ModifyResourceDraftsSubCollectionClient ,
22
22
NewResourceDraftsSubCollectionClient ,
23
23
)
24
24
from dioptra .client .snapshots import SnapshotsSubCollectionClient
25
25
from dioptra .client .tags import TagsSubCollectionClient
26
+ from dioptra .client .workflows import WorkflowsCollectionClient
26
27
27
28
from . import asserts
28
29
29
30
30
31
def run_new_resource_drafts_tests (
31
- client : NewResourceDraftsSubCollectionClient [DioptraResponseProtocol ],
32
+ resource_client : CollectionClient [DioptraResponseProtocol ],
33
+ draft_client : NewResourceDraftsSubCollectionClient [DioptraResponseProtocol ],
34
+ workflow_client : WorkflowsCollectionClient [DioptraResponseProtocol ],
32
35
* resource_ids : str | int ,
33
36
drafts : dict [str , Any ],
34
37
draft1_mod : dict [str , Any ],
@@ -38,83 +41,111 @@ def run_new_resource_drafts_tests(
38
41
group_id : int | None = None ,
39
42
) -> None :
40
43
# Creation operation tests
41
- draft1_response = client .create (
44
+ draft1_response = draft_client .create (
42
45
* resource_ids , group_id = group_id , ** drafts ["draft1" ]
43
46
).json ()
44
47
asserts .assert_draft_response_contents_matches_expectations (
45
48
draft1_response , draft1_expected
46
49
)
47
50
asserts .assert_retrieving_draft_by_id_works (
48
- client ,
51
+ draft_client ,
49
52
* resource_ids ,
50
53
draft_id = draft1_response ["id" ],
51
54
expected = draft1_response ,
52
55
)
53
56
54
- draft2_response = client .create (
57
+ draft2_response = draft_client .create (
55
58
* resource_ids , group_id = group_id , ** drafts ["draft2" ]
56
59
).json ()
57
60
asserts .assert_draft_response_contents_matches_expectations (
58
61
draft2_response , draft2_expected
59
62
)
60
63
asserts .assert_retrieving_draft_by_id_works (
61
- client ,
64
+ draft_client ,
62
65
* resource_ids ,
63
66
draft_id = draft2_response ["id" ],
64
67
expected = draft2_response ,
65
68
)
66
69
asserts .assert_retrieving_drafts_works (
67
- client ,
70
+ draft_client ,
68
71
* resource_ids ,
69
72
expected = [draft1_response , draft2_response ],
70
73
)
71
74
72
75
# Modify operation tests
73
- response = client .modify (
76
+ response = draft_client .modify (
74
77
* resource_ids , draft_id = draft1_response ["id" ], ** draft1_mod
75
78
).json ()
76
79
asserts .assert_draft_response_contents_matches_expectations (
77
80
response , draft1_mod_expected
78
81
)
79
82
80
83
# Delete operation tests
81
- client .delete (* resource_ids , draft_id = draft1_response ["id" ])
84
+ draft_client .delete (* resource_ids , draft_id = draft1_response ["id" ])
85
+ asserts .assert_new_draft_is_not_found (
86
+ draft_client , * resource_ids , draft_id = draft1_response ["id" ]
87
+ )
88
+
89
+ # Commit operation tests
90
+ commit_response = workflow_client .commit_draft (draft2_response ["id" ]).json ()
82
91
asserts .assert_new_draft_is_not_found (
83
- client , * resource_ids , draft_id = draft1_response ["id" ]
92
+ draft_client , * resource_ids , draft_id = draft2_response ["id" ]
93
+ )
94
+ resource_response = resource_client .get_by_id (* commit_response ["id" ]).json ()
95
+ asserts .assert_resource_contents_match_expectations (
96
+ resource_response , draft2_expected ["payload" ]
84
97
)
85
98
86
99
87
100
def run_existing_resource_drafts_tests (
88
- client : ModifyResourceDraftsSubCollectionClient [DioptraResponseProtocol ],
101
+ resource_client : CollectionClient [DioptraResponseProtocol ],
102
+ draft_client : ModifyResourceDraftsSubCollectionClient [DioptraResponseProtocol ],
103
+ workflow_client : WorkflowsCollectionClient [DioptraResponseProtocol ],
89
104
* resource_ids : str | int ,
90
105
draft : dict [str , Any ],
91
106
draft_mod : dict [str , Any ],
92
107
draft_expected : dict [str , Any ],
93
108
draft_mod_expected : dict [str , Any ],
94
109
) -> None :
95
110
# Creation operation tests
96
- response = client .create (* resource_ids , ** draft ).json ()
111
+ response = draft_client .create (* resource_ids , ** draft ).json ()
97
112
asserts .assert_draft_response_contents_matches_expectations (
98
113
response , draft_expected
99
114
)
100
115
asserts .assert_retrieving_draft_by_resource_id_works (
101
- client , * resource_ids , expected = response
116
+ draft_client , * resource_ids , expected = response
102
117
)
103
118
asserts .assert_creating_another_existing_draft_fails (
104
- client , * resource_ids , payload = draft
119
+ draft_client , * resource_ids , payload = draft
105
120
)
106
121
107
122
# Modify operation tests
108
- response = client .modify (
123
+ response = draft_client .modify (
109
124
* resource_ids , resource_snapshot_id = response ["resourceSnapshot" ], ** draft_mod
110
125
).json ()
111
126
asserts .assert_draft_response_contents_matches_expectations (
112
127
response , draft_mod_expected
113
128
)
114
129
115
130
# Delete operation tests
116
- client .delete (* resource_ids )
117
- asserts .assert_existing_draft_is_not_found (client , * resource_ids )
131
+ draft_client .delete (* resource_ids )
132
+ asserts .assert_existing_draft_is_not_found (draft_client , * resource_ids )
133
+
134
+ # Commit operation tests
135
+ draft_response = draft_client .create (* resource_ids , ** draft ).json ()
136
+ resource_response = resource_client .modify_by_id (* resource_ids , ** draft_mod ).json ()
137
+ commit_response = workflow_client .commit_draft (draft_response ["id" ]).json ()
138
+ draft_response = draft_client .modify (
139
+ * resource_ids ,
140
+ resource_snapshot_id = commit_response ["detail" ]["curr_snapshot_id" ],
141
+ ** draft ,
142
+ ).json ()
143
+ commit_response = workflow_client .commit_draft (draft_response ["id" ]).json ()
144
+ asserts .assert_existing_draft_is_not_found (draft_client , * resource_ids )
145
+ resource_response = resource_client .get_by_id (* commit_response ["id" ]).json ()
146
+ asserts .assert_resource_contents_match_expectations (
147
+ resource_response , draft_expected ["payload" ]
148
+ )
118
149
119
150
120
151
def run_resource_snapshots_tests (
0 commit comments