diff --git a/moto/sns/models.py b/moto/sns/models.py index 26125b90c..7d4ff85d1 100644 --- a/moto/sns/models.py +++ b/moto/sns/models.py @@ -662,6 +662,9 @@ class SNSBackend(BaseBackend): def delete_platform_application(self, platform_arn): self.applications.pop(platform_arn) + endpoints = self.list_endpoints_by_platform_application(platform_arn) + for endpoint in endpoints: + self.platform_endpoints.pop(endpoint.arn) def create_platform_endpoint( self, region, application, custom_user_data, token, attributes diff --git a/tests/test_sns/test_application_boto3.py b/tests/test_sns/test_application_boto3.py index 8c31f217d..4489ccfed 100644 --- a/tests/test_sns/test_application_boto3.py +++ b/tests/test_sns/test_application_boto3.py @@ -375,3 +375,26 @@ def test_get_sms_attributes_filtered(): response["attributes"].should.contain("DefaultSMSType") response["attributes"].should_not.contain("test") response["attributes"]["DefaultSMSType"].should.equal("Transactional") + + +@mock_sns +def test_delete_endpoints_of_delete_app(): + conn = boto3.client("sns", region_name="us-east-1") + + platform_app_arn = conn.create_platform_application( + Name="app-test-kevs", Platform="GCM", Attributes={"PlatformCredential": "test"} + )["PlatformApplicationArn"] + + endpoint_arn = conn.create_platform_endpoint( + PlatformApplicationArn=platform_app_arn, + Token="test", + )["EndpointArn"] + + conn.delete_platform_application(PlatformApplicationArn=platform_app_arn) + + with pytest.raises(conn.exceptions.NotFoundException) as excinfo: + conn.get_endpoint_attributes(EndpointArn=endpoint_arn) + error = excinfo.value.response["Error"] + error["Type"].should.equal("Sender") + error["Code"].should.equal("NotFound") + error["Message"].should.equal("Endpoint does not exist")