diff --git a/SAS/TMSS/test/tmss_test_environment_unittest_setup.py b/SAS/TMSS/test/tmss_test_environment_unittest_setup.py index dc5e1c5316aeb1cf29111d7182b3d4ec8e433501..128cda77d2a57539fedd30fc43c0b8dba558ca34 100644 --- a/SAS/TMSS/test/tmss_test_environment_unittest_setup.py +++ b/SAS/TMSS/test/tmss_test_environment_unittest_setup.py @@ -65,16 +65,26 @@ def _call_API_and_assert_expected_response(test_instance, url, call, data, expec if response.status_code != expected_code: print("!!! Unexpected: [%s] - %s %s: %s" % (test_instance.id(), call, url, response.content.decode('utf-8').strip())) test_instance.assertEqual(response.status_code, expected_code) - r_dict = json.loads(response.content.decode('utf-8')) - for key, value in expected_content.items(): - if key not in r_dict.keys(): - print('!!! Missing key: %s in %s' % (key, r_dict.keys())) - test_instance.assertTrue(key in r_dict.keys()) - if type(value) is list: - test_instance.assertEqual(sorted(value), sorted(r_dict[key])) # compare lists independent of ordering - else: - test_instance.assertEqual(value, r_dict[key]) - return r_dict + + content = response.content.decode('utf-8') + + if response.status_code in range(200, 100): + r_dict = json.loads(content) + for key, value in expected_content.items(): + if key not in r_dict.keys(): + print('!!! Missing key: %s in %s' % (key, r_dict.keys())) + test_instance.assertTrue(key in r_dict.keys()) + if type(value) is list: + test_instance.assertEqual(sorted(value), sorted(r_dict[key])) # compare lists independent of ordering + else: + test_instance.assertEqual(value, r_dict[key]) + return r_dict + + try: + return json.loads(content) + except: + return content + def PUT_and_assert_expected_response(test_instance, url, data, expected_code, expected_content): """