From 6f91845299358b3b55b54f6110515e3b081a9ef3 Mon Sep 17 00:00:00 2001 From: Robert Micheletto Date: Mon, 14 Sep 2020 17:00:25 -0400 Subject: [PATCH 1/4] WIP: Adding sns tests. --- aws/sns/__init__.py | 0 aws/sns/resources.py | 23 +++++++++++++++++++++++ aws/sns/test_sns_pending_verified.py | 12 ++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 aws/sns/__init__.py create mode 100644 aws/sns/resources.py create mode 100644 aws/sns/test_sns_pending_verified.py diff --git a/aws/sns/__init__.py b/aws/sns/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/aws/sns/resources.py b/aws/sns/resources.py new file mode 100644 index 0000000..5e88841 --- /dev/null +++ b/aws/sns/resources.py @@ -0,0 +1,23 @@ +from conftest import botocore_client + +def sns_subscriptions(): + "https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sns.html#subscription" + return( + botocore_client.get("sns", "list_subscriptions", [], {}) + .extract_key("Subscriptions") + .flatten() + .values() + ) + +def sns_subscription_attributes(): + "https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sns.html#subscription" + return [ + botocore_client.get( + service_name="sns", + method_name="get_subscription_attributes", + call_args=[], + call_kwargs={"SubscriptionArn": subscription["SubscriptionArn"]}, + ) + .extract_key("Attributes") + for subscription in sns_subscriptions() + ] diff --git a/aws/sns/test_sns_pending_verified.py b/aws/sns/test_sns_pending_verified.py new file mode 100644 index 0000000..9a385b8 --- /dev/null +++ b/aws/sns/test_sns_pending_verified.py @@ -0,0 +1,12 @@ +import pytest + +from aws.sns.resources import sns_subscription_attributes + +@pytest.mark.sns +@pytest.mark.parametrize( + "pending_verification", + sns_subscription_attributes(), + ids=lambda subscription: subscription["PendingVerification"], +) +def test_sns_pending_verified(pending_verification): + assert pending_verification == "false" From 3893553d7b1b553762de38944c01ac2e697b34a6 Mon Sep 17 00:00:00 2001 From: Robert Micheletto Date: Wed, 16 Sep 2020 18:08:45 -0400 Subject: [PATCH 2/4] This now works and is relatively fast. It combines the suggestion from g-k, fixes from sven, and the slice from rds_db_snapshots_attributes(). --- aws/sns/resources.py | 3 +++ aws/sns/test_sns_pending_verified.py | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/aws/sns/resources.py b/aws/sns/resources.py index 5e88841..9ca6b83 100644 --- a/aws/sns/resources.py +++ b/aws/sns/resources.py @@ -17,7 +17,10 @@ def sns_subscription_attributes(): method_name="get_subscription_attributes", call_args=[], call_kwargs={"SubscriptionArn": subscription["SubscriptionArn"]}, + profiles=[subscription["__pytest_meta"]["profile"]], + regions=[subscription["__pytest_meta"]["region"]], ) .extract_key("Attributes") + .values()[0] for subscription in sns_subscriptions() ] diff --git a/aws/sns/test_sns_pending_verified.py b/aws/sns/test_sns_pending_verified.py index 9a385b8..c6201e9 100644 --- a/aws/sns/test_sns_pending_verified.py +++ b/aws/sns/test_sns_pending_verified.py @@ -4,9 +4,9 @@ @pytest.mark.sns @pytest.mark.parametrize( - "pending_verification", - sns_subscription_attributes(), - ids=lambda subscription: subscription["PendingVerification"], + "subscription_attrs", + sns_subscription_attributes(), + ids=lambda subscription: subscription["SubscriptionArn"], ) -def test_sns_pending_verified(pending_verification): - assert pending_verification == "false" +def test_sns_pending_verified(subscription_attrs): + assert subscription_attrs["PendingConfirmation"] == "false" From aa98d6fad2b9b7e8647df0d3213d5f56d39bea9e Mon Sep 17 00:00:00 2001 From: Sven Marnach Date: Thu, 17 Sep 2020 09:04:21 +0200 Subject: [PATCH 3/4] Reformat with black. --- aws/sns/resources.py | 4 +++- aws/sns/test_sns_pending_verified.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/aws/sns/resources.py b/aws/sns/resources.py index 9ca6b83..0461ae5 100644 --- a/aws/sns/resources.py +++ b/aws/sns/resources.py @@ -1,14 +1,16 @@ from conftest import botocore_client + def sns_subscriptions(): "https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sns.html#subscription" - return( + return ( botocore_client.get("sns", "list_subscriptions", [], {}) .extract_key("Subscriptions") .flatten() .values() ) + def sns_subscription_attributes(): "https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sns.html#subscription" return [ diff --git a/aws/sns/test_sns_pending_verified.py b/aws/sns/test_sns_pending_verified.py index c6201e9..a7a5dc6 100644 --- a/aws/sns/test_sns_pending_verified.py +++ b/aws/sns/test_sns_pending_verified.py @@ -2,6 +2,7 @@ from aws.sns.resources import sns_subscription_attributes + @pytest.mark.sns @pytest.mark.parametrize( "subscription_attrs", From 6d3ba83478482178851cf41c6aad759d70fb9f50 Mon Sep 17 00:00:00 2001 From: Robert Micheletto Date: Thu, 17 Sep 2020 14:02:16 -0400 Subject: [PATCH 4/4] Updates for latest pytest. --- aws/conftest.py | 1 + aws/sns/test_sns_pending_verified.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/aws/conftest.py b/aws/conftest.py index 4c2b6cf..213a57f 100644 --- a/aws/conftest.py +++ b/aws/conftest.py @@ -10,6 +10,7 @@ def pytest_configure(config): "rds", "redshift", "s3", + "sns", ]: config.addinivalue_line( "markers", "{}: mark tests against {}".format(svc_name, svc_name) diff --git a/aws/sns/test_sns_pending_verified.py b/aws/sns/test_sns_pending_verified.py index a7a5dc6..cc36794 100644 --- a/aws/sns/test_sns_pending_verified.py +++ b/aws/sns/test_sns_pending_verified.py @@ -1,4 +1,5 @@ import pytest +from helpers import get_param_id from aws.sns.resources import sns_subscription_attributes @@ -7,7 +8,7 @@ @pytest.mark.parametrize( "subscription_attrs", sns_subscription_attributes(), - ids=lambda subscription: subscription["SubscriptionArn"], + ids=lambda subscription: get_param_id(subscription, "SubscriptionArn"), ) def test_sns_pending_verified(subscription_attrs): assert subscription_attrs["PendingConfirmation"] == "false"