From a34ac00e74c968cf127321d5ac2e1a7c5fadfaad Mon Sep 17 00:00:00 2001 From: ckunki Date: Fri, 1 Mar 2024 10:24:06 +0100 Subject: [PATCH] fixed localstack_test --- test/integration/aws/conftest.py | 1 + test/integration/aws/localstack_test.py | 7 ++- test/unit/test_printing.py | 71 +++++++++++++++++++------ 3 files changed, 62 insertions(+), 17 deletions(-) diff --git a/test/integration/aws/conftest.py b/test/integration/aws/conftest.py index 926eda84..81d2dda0 100644 --- a/test/integration/aws/conftest.py +++ b/test/integration/aws/conftest.py @@ -8,6 +8,7 @@ from test.aws.conftest import ( default_asset_id, test_dummy_ami_id, + ec2_cloudformation_yml, ) diff --git a/test/integration/aws/localstack_test.py b/test/integration/aws/localstack_test.py index 8a49a206..5c9492f4 100644 --- a/test/integration/aws/localstack_test.py +++ b/test/integration/aws/localstack_test.py @@ -8,6 +8,7 @@ from exasol.ds.sandbox.lib.setup_ec2.run_setup_ec2 import run_lifecycle_for_ec2 from exasol.ds.sandbox.lib.tags import create_default_asset_tag + def test_ec2_lifecycle_with_local_stack( local_stack_aws_access, default_asset_id, @@ -108,7 +109,11 @@ def test_validate_cloudformation_template_fails_with_local_stack(local_stack_aws local_stack_aws_access.validate_cloudformation_template(wrong_cloudformation_template) -def test_cloudformation_access_with_local_stack(local_stack_aws_access, default_asset_id, test_dummy_ami_id): +def test_cloudformation_access_with_local_stack( + local_stack_aws_access, + default_asset_id, + test_dummy_ami_id, +): aws = local_stack_aws_access with CloudformationStackContextManager( CloudformationStack( diff --git a/test/unit/test_printing.py b/test/unit/test_printing.py index c83d71c4..e0717cc6 100644 --- a/test/unit/test_printing.py +++ b/test/unit/test_printing.py @@ -47,10 +47,16 @@ def test_printing_ami(default_asset_id, printing_mocks): print_with_printer(aws_mock, None, (AssetTypes.AMI,), "*", printing_factory) assert table_printer_mock.add_column.call_count == 8 - table_printer_mock.add_row.assert_called_once_with(TEST_AMI_ID, default_asset_id.ami_name, - 'Image Description', "no", '123/some_dummy_location', - '2022-08-16T15:02:10.000Z', "available", - default_asset_id.tag_value) + table_printer_mock.add_row.assert_called_once_with( + TEST_AMI_ID, + default_asset_id.ami_name, + "Image Description", + "no", + "123/some_dummy_location", + "2022-08-16T15:02:10.000Z", + "available", + default_asset_id.tag_value, + ) table_printer_mock.finish.assert_called_once() assert text_printer_mock.print.call_count == 2 @@ -63,9 +69,15 @@ def test_printing_snapshot(default_asset_id, printing_mocks): print_with_printer(aws_mock, None, (AssetTypes.SNAPSHOT,), "*", printing_factory) assert table_printer_mock.add_column.call_count == 7 - table_printer_mock.add_row.assert_called_once_with('snap-123', 'Created by foo', - '100%', 'vol-123', '2022-08-16, 15:03', - 'completed', default_asset_id.tag_value) + table_printer_mock.add_row.assert_called_once_with( + "snap-123", + "Created by foo", + "100%", + "vol-123", + "2022-08-16, 15:03", + "completed", + default_asset_id.tag_value, + ) table_printer_mock.finish.assert_called_once() assert text_printer_mock.print.call_count == 2 @@ -86,10 +98,16 @@ def test_print_export_image_tasks(default_asset_id, printing_mocks, progress, st assert table_printer_mock.add_column.call_count == 8 - table_printer_mock.add_row.assert_called_once_with('export-ami-123', 'VM Description', - progress, TEST_BUCKET_ID, - default_asset_id.bucket_prefix, - status, status_message, default_asset_id.tag_value) + table_printer_mock.add_row.assert_called_once_with( + "export-ami-123", + "VM Description", + progress, + TEST_BUCKET_ID, + default_asset_id.bucket_prefix, + status, + status_message, + default_asset_id.tag_value, + ) table_printer_mock.finish.assert_called_once() assert text_printer_mock.print.call_count == 2 @@ -108,7 +126,12 @@ def test_print_export_image_tasks(default_asset_id, printing_mocks, progress, st @pytest.mark.parametrize("filter_value,expected_found_s3_object", filter_for_s3) -def test_printing_s3_object(default_asset_id, printing_mocks, filter_value, expected_found_s3_object): +def test_printing_s3_object( + default_asset_id, + printing_mocks, + filter_value, + expected_found_s3_object, +): table_printer_mock, text_printer_mock, printing_factory = printing_mocks aws_access_mock: Union[AwsAccess, Mock] = create_autospec(AwsAccess, spec_set=True) @@ -120,7 +143,11 @@ def test_printing_s3_object(default_asset_id, printing_mocks, filter_value, expe assert table_printer_mock.add_column.call_count == 3 if expected_found_s3_object: - url = f"https://{TEST_CLOUDFRONT_DOMAIN_NAME}/{default_asset_id.bucket_prefix}/export-ami-123.vmdk" + url = ( + f"https://{TEST_CLOUDFRONT_DOMAIN_NAME}" + f"/{default_asset_id.bucket_prefix}" + "/export-ami-123.vmdk" + ) table_printer_mock.add_row.assert_called_once_with( f'{default_asset_id.bucket_prefix}/export-ami-123.vmdk', "2.19 GB", url) @@ -142,14 +169,26 @@ def test_printing_s3_object(default_asset_id, printing_mocks, filter_value, expe @pytest.mark.parametrize("filter_value,expected_found_cloudformation", filter_for_cloudformation) -def test_print_cloudformation_stack(default_asset_id, printing_mocks, filter_value, expected_found_cloudformation): +def test_print_cloudformation_stack( + default_asset_id, + printing_mocks, + filter_value, + expected_found_cloudformation, +): table_printer_mock, text_printer_mock, printing_factory = printing_mocks aws_mock = MagicMock() aws_mock.describe_stacks.return_value = [get_ec2_cloudformation_mock_data()] asset_id = AssetId(filter_value) if filter_value else None - aws_mock.get_all_stack_resources.return_value = get_ec2_cloudformation_stack_resources_mock_data() - print_with_printer(aws_mock, asset_id, (AssetTypes.CLOUDFORMATION,), filter_value, printing_factory) + aws_mock.get_all_stack_resources.return_value = \ + get_ec2_cloudformation_stack_resources_mock_data() + print_with_printer( + aws_mock, + asset_id, + (AssetTypes.CLOUDFORMATION,), + filter_value, + printing_factory, + ) assert table_printer_mock.add_column.call_count == 7