@@ 1018-1029 (lines=12) @@ | ||
1015 | ||
1016 | def test_exception_on_error_in_result(self): |
|
1017 | """Exception if "error" found in result.""" |
|
1018 | exception_error = 'something bad happened' |
|
1019 | error_json={'error': 'not good', 'message': exception_error} |
|
1020 | path_to_mock = 'passwords/json_error.json' |
|
1021 | request_url = api_url + path_to_mock |
|
1022 | with self.assertRaises(tpm.TPMException) as context: |
|
1023 | with requests_mock.Mocker() as m: |
|
1024 | m.get(request_url, json=error_json) |
|
1025 | response = self.client.show_password('json_error') |
|
1026 | log.debug("context exception: {}".format(context.exception)) |
|
1027 | self.assertTrue(exception_error in str(context.exception)) |
|
1028 | ||
1029 | def test_exception_on_403(self): |
|
1030 | """Exception if 403 forbidden.""" |
|
1031 | path_to_mock = 'passwords.json' |
|
1032 | request_url = api_url + path_to_mock |
|
@@ 1055-1065 (lines=11) @@ | ||
1052 | ||
1053 | def test_exception_on_405(self): |
|
1054 | """Exception if 405 Method Not Allowed.""" |
|
1055 | path_to_mock = 'passwords.json' |
|
1056 | request_url = api_url + path_to_mock |
|
1057 | exception_error = "{} Method Not Allowed".format(request_url) |
|
1058 | with self.assertRaises(ValueError) as context: |
|
1059 | with requests_mock.Mocker() as m: |
|
1060 | m.get(request_url, text='Method Not Allowed', status_code=405) |
|
1061 | response = self.client.list_passwords() |
|
1062 | log.debug("context exception: {}".format(context.exception)) |
|
1063 | self.assertTrue(str(context.exception).endswith(exception_error)) |
|
1064 | ||
@@ 1043-1053 (lines=11) @@ | ||
1040 | ||
1041 | def test_exception_on_404(self): |
|
1042 | """Exception if 404 not found.""" |
|
1043 | path_to_mock = 'passwords.json' |
|
1044 | request_url = api_url + path_to_mock |
|
1045 | exception_error = "{} not found".format(request_url) |
|
1046 | with self.assertRaises(tpm.TPMException) as context: |
|
1047 | with requests_mock.Mocker() as m: |
|
1048 | m.get(request_url, text='not found', status_code=404) |
|
1049 | response = self.client.list_passwords() |
|
1050 | log.debug("context exception: {}".format(context.exception)) |
|
1051 | self.assertTrue(exception_error in str(context.exception)) |
|
1052 | ||
1053 | def test_exception_on_405(self): |
|
1054 | """Exception if 405 Method Not Allowed.""" |
|
1055 | path_to_mock = 'passwords.json' |
|
1056 | request_url = api_url + path_to_mock |