예제 #1
0
    def test_describe_vpcs_error(self):
        # create data mock
        ec2_client = ec2_utils_mock.client_connect()

        with patch.object(PmLogAdapter, 'error',
                          return_value=None) as mock_error:
            with patch.object(ec2_client, 'describe_vpcs') as mock_method:
                mock_method.side_effect = ClientError(
                    {
                        'Error': {
                            'Code': data_client_error['service_error_code'],
                            'Message': data_client_error['service_message']
                        }
                    }, 'EXCEPTION')
                with self.assertRaises(PmError) as exception:
                    # Call function test
                    ec2_utils.describe_vpcs(trace_id, aws_account, ec2_client,
                                            region_name)
                cause_error = exception.exception.cause_error.response['Error']
                # Check result
                self.assertEqual(data_client_error['service_error_code'],
                                 cause_error['Code'])
                self.assertEqual(data_client_error['service_message'],
                                 cause_error['Message'])
        mock_error.assert_any_call("[%s/%s] VPC情報の取得に失敗しました。", aws_account,
                                   region_name)
예제 #2
0
    def test_describe_vpcs_empty(self):
        # create data mock
        ec2_client = ec2_utils_mock.client_connect()

        with patch.object(ec2_client, 'describe_vpcs') as mock_method:
            mock_method.return_value = {}
            actual_describe_vpcs = ec2_utils.describe_vpcs(
                trace_id, aws_account, ec2_client, region_name)
            self.assertListEqual([], actual_describe_vpcs)
예제 #3
0
    def test_describe_vpcs_suscess(self):
        # create data mock
        ec2_client = ec2_utils_mock.client_connect()
        # Call function test
        expect_list_vpc = ec2_client.describe_vpcs()['Vpcs']

        actual_describe_vpcs = ec2_utils.describe_vpcs(trace_id, aws_account,
                                                       ec2_client, region_name)
        # Check result
        self.assertListEqual(expect_list_vpc, actual_describe_vpcs)