def test_send_email_error_call_send_email(self):
        trace_id = DataTestSes.TRACE_ID
        region_name = DataTestSes.REGIONS
        sender = DataTestSes.SENDER
        subject = DataTestSes.SUBJECT
        bcc = DataTestSes.BCC
        body = DataTestSes.BODY
        error_code = mock_common_utils.get_error_code()
        error_message = mock_common_utils.get_error_message()
        client = boto3.client(service_name='ses', region_name=region_name)
        response = {'ResponseMetadata': {'HTTPStatusCode': 200}}
        with patch.object(boto3, 'client', return_value=client):
            with patch.object(client, 'send_email',
                              return_value=response) as mock_send_email:
                mock_send_email.side_effect = ClientError(
                    {'Error': {
                        'Code': error_code,
                        'Message': error_message
                    }}, 'description error')

                # call function test
                with self.assertRaises(PmError) as exception:
                    aws_common.send_email(trace_id, region_name, sender, bcc,
                                          subject, body)

        # check result
        cause_error = exception.exception.cause_error.response['Error']
        self.assertEqual(cause_error['Code'], error_code)
        self.assertEqual(cause_error['Message'], error_message)
    def test_update_cognito_user_attributes_error_call_admin_update_user_attributes(
            self):
        trace_id = copy.deepcopy(DataTestCognitoIdp.TRACE_ID)
        user_name = "test_user"
        os.environ["COGNITO_USER_POOL_ID"] = user_pool_id
        user_attributes = copy.deepcopy(
            DataTestCognitoIdp.USER_ATTRIBUTES_UPDATE)
        error_code = mock_common_utils.get_error_code()
        error_message = mock_common_utils.get_error_message()

        # create mock throw error when called function admin_update_user_attributes
        with patch.object(boto3.client("cognito-idp"),
                          'admin_update_user_attributes') as mock_method:
            mock_method.side_effect = ClientError(
                {'Error': {
                    'Code': error_code,
                    'Message': error_message
                }}, 'description error')

            # call function test
            with self.assertRaises(PmError) as exception:
                aws_common.update_cognito_user_attributes(
                    trace_id, user_name, user_attributes)

        # check result
        cause_error = exception.exception.cause_error.response['Error']
        self.assertEqual(cause_error['Code'], error_code)
        self.assertEqual(cause_error['Message'], error_message)
    def test_get_cognito_user_info_by_user_name_error_connect_cognito(self):
        # create boto3 client error
        mock_common_utils.set_error_response("500", "ERROR")
        self.create_mock_boto3_client_error()

        # call function test
        with self.assertRaises(PmError) as exception:
            aws_common.get_cognito_user_info_by_user_name(trace_id, user_name)

        # check error
        cause_error = exception.exception.cause_error.response['Error']
        self.assertEqual(cause_error['Code'],
                         mock_common_utils.get_error_code())
        self.assertEqual(cause_error['Message'],
                         mock_common_utils.get_error_message())
    def test_get_cognitor_user_pool_error_connect_cognito(self):
        attributesToGet = "email"

        # create boto3 client error
        mock_common_utils.set_error_response("500", "ERROR")
        self.create_mock_boto3_client_error()

        # call function test
        with self.assertRaises(PmError) as exception:
            aws_common.get_cognito_user_pools(trace_id, filter,
                                              attributesToGet)

        # check error
        cause_error = exception.exception.cause_error.response['Error']
        self.assertEqual(cause_error['Code'],
                         mock_common_utils.get_error_code())
        self.assertEqual(cause_error['Message'],
                         mock_common_utils.get_error_message())
    def test_process_admin_create_user_pools_error_connect_cognito(self):
        error_code = mock_common_utils.get_error_code()
        error_message = mock_common_utils.get_error_message()
        # create boto3 client error
        mock_common_utils.set_error_response(error_code, error_message)
        self.create_mock_boto3_client_error()

        # call function test
        with self.assertRaises(PmError) as exception:
            aws_common.process_admin_create_user_pools(trace_id, user_name,
                                                       user_attributes,
                                                       temporary_password,
                                                       message_action)

        # check error
        cause_error = exception.exception.cause_error.response['Error']
        self.assertEqual(cause_error['Code'], error_code)
        self.assertEqual(cause_error['Message'], error_message)
    def test_get_cognito_user_info_by_user_name_error_call_admin_get_user_by_user_not_found_exception(
            self):
        # create mock throw error when called function admin_get_user
        with patch.object(boto3.client("cognito-idp"),
                          'admin_get_user') as mock_method:
            mock_method.side_effect = ClientError(
                {
                    'Error': {
                        'Code': CommonConst.COGNITO_USER_NOT_FOUND_EXCEPTION,
                        'Message': mock_common_utils.get_error_message()
                    }
                }, 'description error')

            # call function test
            response = aws_common.get_cognito_user_info_by_user_name(
                trace_id, user_name)

        # check result
        self.assertEqual(response, None)
    def test_update_cognito_user_attributes_error_connect_cognito(self):
        trace_id = copy.deepcopy(DataTestCognitoIdp.TRACE_ID)
        user_name = "test_user"
        user_attributes = copy.deepcopy(
            DataTestCognitoIdp.USER_ATTRIBUTES_UPDATE)

        # create boto3 client error
        mock_common_utils.set_error_response("500", "ERROR")
        self.create_mock_boto3_client_error()

        # call function test
        with self.assertRaises(PmError) as exception:
            aws_common.update_cognito_user_attributes(trace_id, user_name,
                                                      user_attributes)

        # check error
        cause_error = exception.exception.cause_error.response['Error']
        self.assertEqual(cause_error['Code'],
                         mock_common_utils.get_error_code())
        self.assertEqual(cause_error['Message'],
                         mock_common_utils.get_error_message())
    def test_get_cognitor_user_pool_error_call_admin_get_user(self):
        error_code = mock_common_utils.get_error_code()
        error_message = mock_common_utils.get_error_message()

        # create mock throw error when called function admin_get_user
        with patch.object(boto3.client("cognito-idp"),
                          'admin_get_user') as mock_method:
            mock_method.side_effect = ClientError(
                {'Error': {
                    'Code': error_code,
                    'Message': error_message
                }}, 'description error')

            with self.assertRaises(PmError) as exception:
                # call function test
                aws_common.get_cognito_user_info_by_user_name(
                    trace_id, user_name)

        # check result
        cause_error = exception.exception.cause_error.response['Error']
        self.assertEqual(cause_error['Code'], error_code)
        self.assertEqual(cause_error['Message'], error_message)
    def test_get_cognitor_user_pool_error_call_list_users(self):
        attributesToGet = "email"
        error_code = mock_common_utils.get_error_code()
        error_message = mock_common_utils.get_error_message()

        # create mock throw error when called function list_users
        with patch.object(boto3.client("cognito-idp"),
                          'list_users') as mock_method:
            mock_method.side_effect = ClientError(
                {'Error': {
                    'Code': error_code,
                    'Message': error_message
                }}, 'description error')

            # call function test
            with self.assertRaises(PmError) as exception:
                aws_common.get_cognito_user_pools(trace_id, filter,
                                                  attributesToGet)

        # check result
        cause_error = exception.exception.cause_error.response['Error']
        self.assertEqual(cause_error['Code'], error_code)
        self.assertEqual(cause_error['Message'], error_message)
    def test_process_admin_create_user_pools_error_call_admin_create_user(
            self):
        error_code = mock_common_utils.get_error_code()
        error_message = mock_common_utils.get_error_message()

        # create mock throw error when called function list_users
        with patch.object(boto3.client("cognito-idp"),
                          'admin_create_user') as mock_method:
            mock_method.side_effect = ClientError(
                {'Error': {
                    'Code': error_code,
                    'Message': error_message
                }}, 'description error')

            # call function test
            with self.assertRaises(PmError) as exception:
                aws_common.process_admin_create_user_pools(
                    trace_id, user_name, user_attributes, temporary_password,
                    message_action)

        # check result
        cause_error = exception.exception.cause_error.response['Error']
        self.assertEqual(cause_error['Code'], error_code)
        self.assertEqual(cause_error['Message'], error_message)
    def test_send_email_error_client_connect_ses(self):
        trace_id = DataTestSes.TRACE_ID
        region_name = DataTestSes.REGIONS
        sender = DataTestSes.SENDER
        subject = DataTestSes.SUBJECT
        bcc = DataTestSes.BCC
        body = DataTestSes.BODY
        self.create_mock_boto3_client_error()
        mock_common_utils.set_error_response("500", "ERROR")
        with patch.object(PmLogAdapter, 'error',
                          return_value=None) as error_method:

            # call function test
            with self.assertRaises(PmError) as exception:
                aws_common.send_email(trace_id, region_name, sender, bcc,
                                      subject, body)

        # check result
        cause_error = exception.exception.cause_error.response['Error']
        self.assertEqual(cause_error['Code'],
                         mock_common_utils.get_error_code())
        self.assertEqual(cause_error['Message'],
                         mock_common_utils.get_error_message())
        error_method.assert_any_call("[%s] SESクライアント作成に失敗しました。", region_name)