|
37 | 37 | from localstack.testing.aws.util import is_aws_cloud |
38 | 38 | from localstack.testing.config import TEST_AWS_ACCESS_KEY_ID, TEST_AWS_SECRET_ACCESS_KEY |
39 | 39 | from localstack.testing.pytest import markers |
| 40 | +from localstack.testing.snapshots.transformer_utility import TransformerUtility |
40 | 41 | from localstack.utils import testutil |
41 | 42 | from localstack.utils.aws.arns import get_partition, parse_arn, sqs_queue_arn |
42 | 43 | from localstack.utils.net import wait_for_port_closed, wait_for_port_open |
@@ -3665,6 +3666,15 @@ def platform_credentials() -> tuple[str, str]: |
3665 | 3666 | return client_id, client_secret |
3666 | 3667 |
|
3667 | 3668 |
|
| 3669 | +@pytest.fixture(scope="class") |
| 3670 | +def phone_number() -> str: |
| 3671 | + # if you want to test phone number operations against AWS and a real phone number, replace this value |
| 3672 | + # and use this fixture. |
| 3673 | + # note: you might need to verify that number first in your AWS account due to the sms sandbox |
| 3674 | + phone_number = "+430000000000" |
| 3675 | + return phone_number |
| 3676 | + |
| 3677 | + |
3668 | 3678 | class TestSNSPlatformApplicationCrud: |
3669 | 3679 | @markers.aws.manual_setup_required |
3670 | 3680 | def test_create_platform_application( |
@@ -4680,6 +4690,85 @@ def test_set_invalid_sms_attributes(self, aws_client, snapshot, attribute_key_va |
4680 | 4690 | ) |
4681 | 4691 | snapshot.match("invalid-attribute", e.value.response) |
4682 | 4692 |
|
| 4693 | + @markers.aws.manual_setup_required |
| 4694 | + @pytest.mark.skipif(is_sns_v1_provider(), reason="Not correctly implemented in v1") |
| 4695 | + def test_is_phone_number_opted_out( |
| 4696 | + self, phone_number, aws_client, snapshot, sns_provider, account_id, region_name, cleanups |
| 4697 | + ): |
| 4698 | + # this test expects the fixture-provided phone number to be opted out |
| 4699 | + # if you want to test against AWS, you need to manually opt out a number |
| 4700 | + # https://us-east-1.console.aws.amazon.com/sms-voice/home?region=us-east-1#/opt-out-lists?name=Default&tab=opt-out-list-opted-out-numbers |
| 4701 | + sns_store = sns_provider().get_store(account_id, region_name) |
| 4702 | + |
| 4703 | + def cleanup_store(): |
| 4704 | + sns_store.PHONE_NUMBERS_OPTED_OUT.remove(phone_number) |
| 4705 | + |
| 4706 | + if not is_aws_cloud(): |
| 4707 | + sns_store.PHONE_NUMBERS_OPTED_OUT.append(phone_number) |
| 4708 | + cleanups.append(cleanup_store) |
| 4709 | + |
| 4710 | + response = aws_client.sns.check_if_phone_number_is_opted_out(phoneNumber=phone_number) |
| 4711 | + snapshot.match("phone-number-opted-out", response) |
| 4712 | + |
| 4713 | + @markers.aws.manual_setup_required |
| 4714 | + @pytest.mark.skipif(is_sns_v1_provider(), reason="Not correctly implemented in v1") |
| 4715 | + def test_list_phone_numbers_opted_out( |
| 4716 | + self, phone_number, aws_client, snapshot, sns_provider, account_id, region_name, cleanups |
| 4717 | + ): |
| 4718 | + # this test expects exactly one phone number opted out |
| 4719 | + # if you want to test against AWS, you need to manually opt out a number |
| 4720 | + # https://us-east-1.console.aws.amazon.com/sms-voice/home?region=us-east-1#/opt-out-lists?name=Default&tab=opt-out-list-opted-out-numbers |
| 4721 | + sns_store = sns_provider().get_store(account_id, region_name) |
| 4722 | + |
| 4723 | + def cleanup_store(): |
| 4724 | + sns_store.PHONE_NUMBERS_OPTED_OUT.remove(phone_number) |
| 4725 | + |
| 4726 | + if not is_aws_cloud(): |
| 4727 | + sns_store.PHONE_NUMBERS_OPTED_OUT.append(phone_number) |
| 4728 | + cleanups.append(cleanup_store) |
| 4729 | + |
| 4730 | + snapshot.add_transformer( |
| 4731 | + TransformerUtility.jsonpath( |
| 4732 | + jsonpath="$..phoneNumbers[*]", |
| 4733 | + value_replacement="phone-number", |
| 4734 | + ) |
| 4735 | + ) |
| 4736 | + response = aws_client.sns.list_phone_numbers_opted_out() |
| 4737 | + snapshot.match("list-phone-numbers-opted-out", response) |
| 4738 | + |
| 4739 | + @markers.aws.manual_setup_required |
| 4740 | + @pytest.mark.skipif(is_sns_v1_provider(), reason="Not correctly implemented in v1") |
| 4741 | + def test_opt_in_phone_number( |
| 4742 | + self, phone_number, aws_client, snapshot, sns_provider, account_id, region_name, cleanups |
| 4743 | + ): |
| 4744 | + # this test expects exactly one phone number opted out |
| 4745 | + # if you want to test against AWS, you need to manually opt out a number |
| 4746 | + # https://us-east-1.console.aws.amazon.com/sms-voice/home?region=us-east-1#/opt-out-lists?name=Default&tab=opt-out-list-opted-out-numbers |
| 4747 | + # IMPORTANT: a phone number can only be opted in once every 30 days on AWS. |
| 4748 | + # Make sure everything else is set up and taken care of properly before trying to validate this. |
| 4749 | + sns_store = sns_provider().get_store(account_id, region_name) |
| 4750 | + |
| 4751 | + def cleanup_store(): |
| 4752 | + sns_store.PHONE_NUMBERS_OPTED_OUT.remove(phone_number) |
| 4753 | + |
| 4754 | + if not is_aws_cloud(): |
| 4755 | + sns_store.PHONE_NUMBERS_OPTED_OUT.append(phone_number) |
| 4756 | + cleanups.append(cleanup_store) |
| 4757 | + response = aws_client.sns.check_if_phone_number_is_opted_out(phoneNumber=phone_number) |
| 4758 | + assert response["isOptedOut"] |
| 4759 | + |
| 4760 | + response = aws_client.sns.opt_in_phone_number(phoneNumber=phone_number) |
| 4761 | + snapshot.match("opt-in-phone-number", response) |
| 4762 | + |
| 4763 | + @markers.aws.validated |
| 4764 | + def test_opt_in_non_existing_phone_number( |
| 4765 | + self, phone_number, aws_client, snapshot, sns_provider, account_id, region_name |
| 4766 | + ): |
| 4767 | + non_existing_number = "+4411111111" |
| 4768 | + response = aws_client.sns.opt_in_phone_number(phoneNumber=non_existing_number) |
| 4769 | + |
| 4770 | + snapshot.match("opt-in-non-existing-number", response) |
| 4771 | + |
4683 | 4772 |
|
4684 | 4773 | class TestSNSSubscriptionHttp: |
4685 | 4774 | @markers.aws.validated |
|
0 commit comments