13
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
-
17
16
'''
18
17
This class contains an integration test for the Case Management service.
19
18
'''
29
28
# Read config file
30
29
configFile = 'case_management.env'
31
30
31
+
32
32
class TestCaseManagementV1 (unittest .TestCase ):
33
33
"""
34
34
Integration Test Class for CaseManagementV1
@@ -39,12 +39,15 @@ class TestCaseManagementV1(unittest.TestCase):
39
39
# Used to store newly uploaded file id
40
40
file_attachment_id = ''
41
41
42
+ resource_crn = 'crn:v1:staging:public:cloud-object-storage:global:a/19c52e57800c4d8bb9aefc66b3e49755:61848e72-6ba6-415e-84e2-91f3915e194d::'
43
+
42
44
@classmethod
43
45
def setUpClass (cls ):
44
46
if os .path .exists (configFile ):
45
47
os .environ ['IBM_CREDENTIALS_FILE' ] = configFile
46
48
else :
47
- raise unittest .SkipTest ('External configuration not available, skipping...' )
49
+ raise unittest .SkipTest (
50
+ 'External configuration not available, skipping...' )
48
51
49
52
cls .service = CaseManagementV1 .new_instance ()
50
53
assert cls .service is not None
@@ -57,7 +60,8 @@ def test_01_create_case(self):
57
60
offering_payload_type_model = {}
58
61
offering_payload_type_model ['group' ] = 'crn_service_name'
59
62
offering_payload_type_model ['key' ] = 'cloud-object-storage'
60
- offering_payload_type_model ['id' ] = 'dff97f5c-bc5e-4455-b470-411c3edbe49c'
63
+ offering_payload_type_model [
64
+ 'id' ] = 'dff97f5c-bc5e-4455-b470-411c3edbe49c'
61
65
62
66
offering_payload_model = {}
63
67
offering_payload_model ['name' ] = 'Cloud Object Storage'
@@ -69,14 +73,12 @@ def test_01_create_case(self):
69
73
severity = 4
70
74
offering = offering_payload_model
71
75
72
- response = self .service .create_case (
73
- type ,
74
- subject ,
75
- description ,
76
- severity = severity ,
77
- offering = offering ,
78
- headers = {}
79
- )
76
+ response = self .service .create_case (type ,
77
+ subject ,
78
+ description ,
79
+ severity = severity ,
80
+ offering = offering ,
81
+ headers = {})
80
82
81
83
# Storing the new case number for subsequent test cases
82
84
TestCaseManagementV1 .new_case_number = response .result ['number' ]
@@ -93,13 +95,11 @@ def test_02_create_case_with_empty_offering(self):
93
95
severity = 4
94
96
95
97
with pytest .raises (ApiException ) as e :
96
- self .service .create_case (
97
- type ,
98
- subject ,
99
- description ,
100
- severity = severity ,
101
- headers = {}
102
- )
98
+ self .service .create_case (type ,
99
+ subject ,
100
+ description ,
101
+ severity = severity ,
102
+ headers = {})
103
103
assert e .value .code == 400
104
104
105
105
def test_03_create_case_with_empty_subject_and_description (self ):
@@ -108,7 +108,8 @@ def test_03_create_case_with_empty_subject_and_description(self):
108
108
offering_payload_type_model = {}
109
109
offering_payload_type_model ['group' ] = 'crn_service_name'
110
110
offering_payload_type_model ['key' ] = 'cloud-object-storage'
111
- offering_payload_type_model ['id' ] = 'dff97f5c-bc5e-4455-b470-411c3edbe49c'
111
+ offering_payload_type_model [
112
+ 'id' ] = 'dff97f5c-bc5e-4455-b470-411c3edbe49c'
112
113
113
114
offering_payload_model = {}
114
115
offering_payload_model ['name' ] = 'Cloud Object Storage'
@@ -122,14 +123,12 @@ def test_03_create_case_with_empty_subject_and_description(self):
122
123
123
124
# Subject and description are required
124
125
with pytest .raises (ApiException ) as e :
125
- self .service .create_case (
126
- type ,
127
- subject ,
128
- description ,
129
- severity = severity ,
130
- offering = offering ,
131
- headers = {}
132
- )
126
+ self .service .create_case (type ,
127
+ subject ,
128
+ description ,
129
+ severity = severity ,
130
+ offering = offering ,
131
+ headers = {})
133
132
assert e .value .code == 400
134
133
135
134
def test_04_get_cases (self ):
@@ -139,13 +138,11 @@ def test_04_get_cases(self):
139
138
sort = 'number'
140
139
fields = ['number' ]
141
140
142
- response = self .service .get_cases (
143
- offset = offset ,
144
- limit = limit ,
145
- sort = sort ,
146
- fields = fields ,
147
- headers = {}
148
- )
141
+ response = self .service .get_cases (offset = offset ,
142
+ limit = limit ,
143
+ sort = sort ,
144
+ fields = fields ,
145
+ headers = {})
149
146
150
147
assert response .status_code == 200
151
148
assert response .result ['total_count' ] > 0
@@ -155,13 +152,12 @@ def test_05_get_case(self):
155
152
fields = ['number' , 'short_description' ]
156
153
case_number = TestCaseManagementV1 .new_case_number
157
154
158
- response = self .service .get_case (
159
- self .new_case_number ,
160
- fields = fields ,
161
- headers = {}
162
- )
155
+ response = self .service .get_case (self .new_case_number ,
156
+ fields = fields ,
157
+ headers = {})
163
158
164
- assert TestCaseManagementV1 .new_case_number == response .result ['number' ]
159
+ assert TestCaseManagementV1 .new_case_number == response .result [
160
+ 'number' ]
165
161
assert response .result ['short_description' ] != ''
166
162
167
163
def test_06_get_case_with_invalid_field (self ):
@@ -170,23 +166,17 @@ def test_06_get_case_with_invalid_field(self):
170
166
case_number = TestCaseManagementV1 .new_case_number
171
167
172
168
with pytest .raises (ApiException ) as e :
173
- self .service .get_case (
174
- self .new_case_number ,
175
- fields = fields ,
176
- headers = {}
177
- )
169
+ self .service .get_case (self .new_case_number ,
170
+ fields = fields ,
171
+ headers = {})
178
172
assert e .value .code == 400
179
173
180
174
def test_07_add_comment (self ):
181
175
182
176
case_number = TestCaseManagementV1 .new_case_number
183
177
comment = 'This is a test comment!'
184
178
185
- response = self .service .add_comment (
186
- case_number ,
187
- comment ,
188
- headers = {}
189
- )
179
+ response = self .service .add_comment (case_number , comment , headers = {})
190
180
191
181
assert response .status_code == 200
192
182
assert comment == response .result ["value" ]
@@ -197,11 +187,7 @@ def test_08_add_comment_to_nonexisting_case(self):
197
187
comment = 'This is a test comment!'
198
188
199
189
with pytest .raises (ApiException ) as e :
200
- self .service .add_comment (
201
- case_number ,
202
- comment ,
203
- headers = {}
204
- )
190
+ self .service .add_comment (case_number , comment , headers = {})
205
191
assert e .value .code == 404
206
192
207
193
def test_09_add_watch_list_member (self ):
@@ -216,33 +202,32 @@ def test_09_add_watch_list_member(self):
216
202
response = self .service .add_watchlist (
217
203
TestCaseManagementV1 .new_case_number ,
218
204
watchlist = watchlist ,
219
- headers = {}
220
- )
205
+ headers = {})
221
206
222
207
# Non-account member cannot be added to the watch-list,
223
208
# therefore the response will include a "failed" list
224
209
assert response .status_code == 200
225
210
226
211
# Loop over all returned users and find the matching one by user id
227
- found_users = [user for user in response .result ['failed' ]
228
- if user ['user_id' ] == user_id_and_realm_model ['user_id' ]]
212
+ found_users = [
213
+ user for user in response .result ['failed' ]
214
+ if user ['user_id' ] == user_id_and_realm_model ['user_id' ]
215
+ ]
229
216
assert len (found_users ) == 1
230
217
231
218
def test_10_file_upload (self ):
232
219
233
220
fileName = "test_file.txt"
234
221
235
222
file_with_metadata_model = {}
236
- file_with_metadata_model ['data' ] = io .BytesIO (b'This is a mock file.' ).getvalue ()
223
+ file_with_metadata_model ['data' ] = io .BytesIO (
224
+ b'This is a mock file.' ).getvalue ()
237
225
file_with_metadata_model ['filename' ] = fileName
238
226
239
227
file = [file_with_metadata_model ]
240
228
241
229
response = self .service .upload_file (
242
- TestCaseManagementV1 .new_case_number ,
243
- file ,
244
- headers = {}
245
- )
230
+ TestCaseManagementV1 .new_case_number , file , headers = {})
246
231
247
232
TestCaseManagementV1 .file_attachment_id = response .result ['id' ]
248
233
@@ -254,8 +239,7 @@ def test_11_download_file(self):
254
239
response = self .service .download_file (
255
240
TestCaseManagementV1 .new_case_number ,
256
241
TestCaseManagementV1 .file_attachment_id ,
257
- headers = {}
258
- )
242
+ headers = {})
259
243
260
244
assert response .status_code == 200
261
245
assert 'content-type' in response .headers
@@ -265,32 +249,20 @@ def test_12_delete_file(self):
265
249
response = self .service .delete_file (
266
250
TestCaseManagementV1 .new_case_number ,
267
251
TestCaseManagementV1 .file_attachment_id ,
268
- headers = {}
269
- )
252
+ headers = {})
270
253
271
254
assert response .status_code == 200
272
255
# Assert the file attachment list is empty
273
256
assert len (response .result ['attachments' ]) == 0
274
257
275
258
def test_13_add_resource (self ):
276
259
277
- # Adding a resource requires a valid CRN (Cloud Resource Name)
278
- # CRN's can be retrieved via the Search and Tagging API
279
- crn = 'invalid:crn'
280
- type = 'testString'
281
- id = 36.0
282
- note = 'testString'
283
-
284
- with pytest .raises (ApiException ) as e :
285
- response = self .service .add_resource (
286
- TestCaseManagementV1 .new_case_number ,
287
- crn = crn ,
288
- type = type ,
289
- id = id ,
290
- note = note ,
291
- headers = {}
292
- )
293
- assert e .value .code == 500
260
+ response = self .service .add_resource (
261
+ TestCaseManagementV1 .new_case_number ,
262
+ crn = TestCaseManagementV1 .resource_crn ,
263
+ note = 'Test resource' )
264
+ assert response .status_code == 200
265
+ assert response is not None
294
266
295
267
def test_14_resolve_case (self ):
296
268
@@ -300,10 +272,8 @@ def test_14_resolve_case(self):
300
272
status_payload ['resolution_code' ] = 1
301
273
302
274
response = self .service .update_case_status (
303
- TestCaseManagementV1 .new_case_number ,
304
- status_payload ,
305
- headers = {}
306
- )
275
+ TestCaseManagementV1 .new_case_number , status_payload , headers = {})
307
276
308
277
assert response .status_code == 200
309
- assert TestCaseManagementV1 .new_case_number == response .result ["number" ]
278
+ assert TestCaseManagementV1 .new_case_number == response .result [
279
+ "number" ]
0 commit comments