Code Duplication    Length = 11-12 lines in 3 locations

tests/test_tpm.py 3 locations

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