Skip to content

Commit 7deac01

Browse files
committed
test(Case Management): minor fixes to case-mgmt integration test
1 parent 46d7d78 commit 7deac01

File tree

1 file changed

+60
-90
lines changed

1 file changed

+60
-90
lines changed

test/integration/test_case_management_v1.py

Lines changed: 60 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
1716
'''
1817
This class contains an integration test for the Case Management service.
1918
'''
@@ -29,6 +28,7 @@
2928
# Read config file
3029
configFile = 'case_management.env'
3130

31+
3232
class TestCaseManagementV1(unittest.TestCase):
3333
"""
3434
Integration Test Class for CaseManagementV1
@@ -39,12 +39,15 @@ class TestCaseManagementV1(unittest.TestCase):
3939
# Used to store newly uploaded file id
4040
file_attachment_id = ''
4141

42+
resource_crn = 'crn:v1:staging:public:cloud-object-storage:global:a/19c52e57800c4d8bb9aefc66b3e49755:61848e72-6ba6-415e-84e2-91f3915e194d::'
43+
4244
@classmethod
4345
def setUpClass(cls):
4446
if os.path.exists(configFile):
4547
os.environ['IBM_CREDENTIALS_FILE'] = configFile
4648
else:
47-
raise unittest.SkipTest('External configuration not available, skipping...')
49+
raise unittest.SkipTest(
50+
'External configuration not available, skipping...')
4851

4952
cls.service = CaseManagementV1.new_instance()
5053
assert cls.service is not None
@@ -57,7 +60,8 @@ def test_01_create_case(self):
5760
offering_payload_type_model = {}
5861
offering_payload_type_model['group'] = 'crn_service_name'
5962
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'
6165

6266
offering_payload_model = {}
6367
offering_payload_model['name'] = 'Cloud Object Storage'
@@ -69,14 +73,12 @@ def test_01_create_case(self):
6973
severity = 4
7074
offering = offering_payload_model
7175

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={})
8082

8183
# Storing the new case number for subsequent test cases
8284
TestCaseManagementV1.new_case_number = response.result['number']
@@ -93,13 +95,11 @@ def test_02_create_case_with_empty_offering(self):
9395
severity = 4
9496

9597
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={})
103103
assert e.value.code == 400
104104

105105
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):
108108
offering_payload_type_model = {}
109109
offering_payload_type_model['group'] = 'crn_service_name'
110110
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'
112113

113114
offering_payload_model = {}
114115
offering_payload_model['name'] = 'Cloud Object Storage'
@@ -122,14 +123,12 @@ def test_03_create_case_with_empty_subject_and_description(self):
122123

123124
# Subject and description are required
124125
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={})
133132
assert e.value.code == 400
134133

135134
def test_04_get_cases(self):
@@ -139,13 +138,11 @@ def test_04_get_cases(self):
139138
sort = 'number'
140139
fields = ['number']
141140

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={})
149146

150147
assert response.status_code == 200
151148
assert response.result['total_count'] > 0
@@ -155,13 +152,12 @@ def test_05_get_case(self):
155152
fields = ['number', 'short_description']
156153
case_number = TestCaseManagementV1.new_case_number
157154

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={})
163158

164-
assert TestCaseManagementV1.new_case_number == response.result['number']
159+
assert TestCaseManagementV1.new_case_number == response.result[
160+
'number']
165161
assert response.result['short_description'] != ''
166162

167163
def test_06_get_case_with_invalid_field(self):
@@ -170,23 +166,17 @@ def test_06_get_case_with_invalid_field(self):
170166
case_number = TestCaseManagementV1.new_case_number
171167

172168
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={})
178172
assert e.value.code == 400
179173

180174
def test_07_add_comment(self):
181175

182176
case_number = TestCaseManagementV1.new_case_number
183177
comment = 'This is a test comment!'
184178

185-
response = self.service.add_comment(
186-
case_number,
187-
comment,
188-
headers={}
189-
)
179+
response = self.service.add_comment(case_number, comment, headers={})
190180

191181
assert response.status_code == 200
192182
assert comment == response.result["value"]
@@ -197,11 +187,7 @@ def test_08_add_comment_to_nonexisting_case(self):
197187
comment = 'This is a test comment!'
198188

199189
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={})
205191
assert e.value.code == 404
206192

207193
def test_09_add_watch_list_member(self):
@@ -216,33 +202,32 @@ def test_09_add_watch_list_member(self):
216202
response = self.service.add_watchlist(
217203
TestCaseManagementV1.new_case_number,
218204
watchlist=watchlist,
219-
headers={}
220-
)
205+
headers={})
221206

222207
# Non-account member cannot be added to the watch-list,
223208
# therefore the response will include a "failed" list
224209
assert response.status_code == 200
225210

226211
# 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+
]
229216
assert len(found_users) == 1
230217

231218
def test_10_file_upload(self):
232219

233220
fileName = "test_file.txt"
234221

235222
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()
237225
file_with_metadata_model['filename'] = fileName
238226

239227
file = [file_with_metadata_model]
240228

241229
response = self.service.upload_file(
242-
TestCaseManagementV1.new_case_number,
243-
file,
244-
headers={}
245-
)
230+
TestCaseManagementV1.new_case_number, file, headers={})
246231

247232
TestCaseManagementV1.file_attachment_id = response.result['id']
248233

@@ -254,8 +239,7 @@ def test_11_download_file(self):
254239
response = self.service.download_file(
255240
TestCaseManagementV1.new_case_number,
256241
TestCaseManagementV1.file_attachment_id,
257-
headers={}
258-
)
242+
headers={})
259243

260244
assert response.status_code == 200
261245
assert 'content-type' in response.headers
@@ -265,32 +249,20 @@ def test_12_delete_file(self):
265249
response = self.service.delete_file(
266250
TestCaseManagementV1.new_case_number,
267251
TestCaseManagementV1.file_attachment_id,
268-
headers={}
269-
)
252+
headers={})
270253

271254
assert response.status_code == 200
272255
# Assert the file attachment list is empty
273256
assert len(response.result['attachments']) == 0
274257

275258
def test_13_add_resource(self):
276259

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
294266

295267
def test_14_resolve_case(self):
296268

@@ -300,10 +272,8 @@ def test_14_resolve_case(self):
300272
status_payload['resolution_code'] = 1
301273

302274
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={})
307276

308277
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

Comments
 (0)