def test_get_credential_report_error_connect_iam(self):
        expected_error_response = copy.deepcopy(DataCommon.ERROR_RESPONSE)
        expected_operation_name = copy.deepcopy(DataCommon.OPERATION_NAME)

        # mock error client
        with patch.object(session, 'client') as mock_method:
            mock_method.side_effect = ClientError(
                error_response=expected_error_response,
                operation_name=expected_operation_name)
            with patch.object(PmLogAdapter, 'error',
                              return_value=None) as mock_method_error:
                with self.assertRaises(PmError) as exception:
                    IAMUtils.get_credential_report(trace_id, session,
                                                   aws_account)

        # check error
        actual_cause_error = exception.exception.cause_error
        self.assertEqual(expected_error_response['Error'],
                         actual_cause_error.response['Error'])
        self.assertEqual(expected_operation_name,
                         actual_cause_error.operation_name)

        # check message log error
        mock_method_error.assert_any_call("[%s] IAMクライアント作成に失敗しました。",
                                          aws_account)
    def test_get_credential_report_success_response_not_exists_content(self):
        # connect client
        client_connect_iam = iam_utils.client_connect()

        expected_data_credential_report = []

        # mock client
        with patch.object(session, 'client') as mock_method_client:
            mock_method_client.return_value = client_connect_iam
            # mock response API get_credential_report
            with patch.object(client_connect_iam,
                              'get_credential_report') as mock_method:
                mock_method.return_value = {}
                actual_credential_report = IAMUtils.get_credential_report(
                    trace_id, session, aws_account)

        # check response
        self.assertEqual(expected_data_credential_report,
                         actual_credential_report)

        # check connect client
        mock_method_client.assert_any_call(service_name="iam")
    def test_get_credential_report_success_response_exists_content(self):
        # connect client
        client_connect_iam = iam_utils.client_connect()

        expected_credential_report = copy.deepcopy(
            DataTestIAM.DATA_GET_CREDENTIAL_REPORT)

        # mock client
        with patch.object(session, 'client') as mock_method_client:
            mock_method_client.return_value = client_connect_iam
            # mock response API get_credential_report
            with patch.object(client_connect_iam,
                              'get_credential_report') as mock_method:
                mock_method.return_value = expected_credential_report
                actual_credential_report = IAMUtils.get_credential_report(
                    trace_id, session, aws_account)

        # check response
        self.assertEqual(expected_credential_report['Content'].decode(),
                         actual_credential_report)

        # check connect client
        mock_method_client.assert_any_call(service_name="iam")