Skip to content

Commit

Permalink
fixed localstack_test
Browse files Browse the repository at this point in the history
  • Loading branch information
ckunki committed Mar 1, 2024
1 parent 82838ba commit a34ac00
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 17 deletions.
1 change: 1 addition & 0 deletions test/integration/aws/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from test.aws.conftest import (
default_asset_id,
test_dummy_ami_id,
ec2_cloudformation_yml,
)


Expand Down
7 changes: 6 additions & 1 deletion test/integration/aws/localstack_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
71 changes: 55 additions & 16 deletions test/unit/test_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit a34ac00

Please sign in to comment.