2015-03-14 13:06:31 +00:00
|
|
|
import boto
|
|
|
|
from boto.exception import BotoServerError
|
2017-02-16 03:35:45 +00:00
|
|
|
from moto import mock_sns_deprecated
|
2019-12-17 02:05:29 +00:00
|
|
|
from moto.core import ACCOUNT_ID
|
2021-10-18 19:44:29 +00:00
|
|
|
import sure # noqa # pylint: disable=unused-import
|
2015-03-14 13:06:31 +00:00
|
|
|
|
|
|
|
|
2021-09-23 11:50:59 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_sns_deprecated
|
2015-03-14 13:06:31 +00:00
|
|
|
def test_create_platform_application():
|
|
|
|
conn = boto.connect_sns()
|
|
|
|
platform_application = conn.create_platform_application(
|
|
|
|
name="my-application",
|
|
|
|
platform="APNS",
|
|
|
|
attributes={
|
|
|
|
"PlatformCredential": "platform_credential",
|
|
|
|
"PlatformPrincipal": "platform_principal",
|
|
|
|
},
|
|
|
|
)
|
2019-10-31 15:44:26 +00:00
|
|
|
application_arn = platform_application["CreatePlatformApplicationResponse"][
|
|
|
|
"CreatePlatformApplicationResult"
|
|
|
|
]["PlatformApplicationArn"]
|
2017-02-24 02:37:43 +00:00
|
|
|
application_arn.should.equal(
|
2019-12-16 00:22:26 +00:00
|
|
|
"arn:aws:sns:us-east-1:{}:app/APNS/my-application".format(ACCOUNT_ID)
|
2019-10-31 15:44:26 +00:00
|
|
|
)
|
2015-03-14 13:06:31 +00:00
|
|
|
|
|
|
|
|
2021-09-23 11:50:59 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_sns_deprecated
|
2015-03-14 13:06:31 +00:00
|
|
|
def test_get_platform_application_attributes():
|
|
|
|
conn = boto.connect_sns()
|
|
|
|
platform_application = conn.create_platform_application(
|
|
|
|
name="my-application",
|
|
|
|
platform="APNS",
|
|
|
|
attributes={
|
|
|
|
"PlatformCredential": "platform_credential",
|
|
|
|
"PlatformPrincipal": "platform_principal",
|
|
|
|
},
|
|
|
|
)
|
2019-10-31 15:44:26 +00:00
|
|
|
arn = platform_application["CreatePlatformApplicationResponse"][
|
|
|
|
"CreatePlatformApplicationResult"
|
|
|
|
]["PlatformApplicationArn"]
|
|
|
|
attributes = conn.get_platform_application_attributes(arn)[
|
|
|
|
"GetPlatformApplicationAttributesResponse"
|
|
|
|
]["GetPlatformApplicationAttributesResult"]["Attributes"]
|
|
|
|
attributes.should.equal(
|
|
|
|
{
|
|
|
|
"PlatformCredential": "platform_credential",
|
|
|
|
"PlatformPrincipal": "platform_principal",
|
|
|
|
}
|
|
|
|
)
|
2015-03-14 13:06:31 +00:00
|
|
|
|
|
|
|
|
2021-09-23 11:50:59 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_sns_deprecated
|
2015-03-14 13:06:31 +00:00
|
|
|
def test_get_missing_platform_application_attributes():
|
|
|
|
conn = boto.connect_sns()
|
2017-02-24 02:37:43 +00:00
|
|
|
conn.get_platform_application_attributes.when.called_with(
|
2019-10-31 15:44:26 +00:00
|
|
|
"a-fake-arn"
|
|
|
|
).should.throw(BotoServerError)
|
2015-03-14 13:06:31 +00:00
|
|
|
|
|
|
|
|
2021-09-23 11:50:59 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_sns_deprecated
|
2015-03-14 13:06:31 +00:00
|
|
|
def test_set_platform_application_attributes():
|
|
|
|
conn = boto.connect_sns()
|
|
|
|
platform_application = conn.create_platform_application(
|
|
|
|
name="my-application",
|
|
|
|
platform="APNS",
|
|
|
|
attributes={
|
|
|
|
"PlatformCredential": "platform_credential",
|
|
|
|
"PlatformPrincipal": "platform_principal",
|
|
|
|
},
|
|
|
|
)
|
2019-10-31 15:44:26 +00:00
|
|
|
arn = platform_application["CreatePlatformApplicationResponse"][
|
|
|
|
"CreatePlatformApplicationResult"
|
|
|
|
]["PlatformApplicationArn"]
|
|
|
|
conn.set_platform_application_attributes(arn, {"PlatformPrincipal": "other"})
|
|
|
|
attributes = conn.get_platform_application_attributes(arn)[
|
|
|
|
"GetPlatformApplicationAttributesResponse"
|
|
|
|
]["GetPlatformApplicationAttributesResult"]["Attributes"]
|
|
|
|
attributes.should.equal(
|
|
|
|
{"PlatformCredential": "platform_credential", "PlatformPrincipal": "other"}
|
|
|
|
)
|
2015-03-14 13:06:31 +00:00
|
|
|
|
|
|
|
|
2021-09-23 11:50:59 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_sns_deprecated
|
2015-03-14 13:06:31 +00:00
|
|
|
def test_list_platform_applications():
|
|
|
|
conn = boto.connect_sns()
|
2019-10-31 15:44:26 +00:00
|
|
|
conn.create_platform_application(name="application1", platform="APNS")
|
|
|
|
conn.create_platform_application(name="application2", platform="APNS")
|
2015-03-14 13:06:31 +00:00
|
|
|
|
2020-01-20 23:21:11 +00:00
|
|
|
applications_response = conn.list_platform_applications()
|
|
|
|
applications = applications_response["ListPlatformApplicationsResponse"][
|
2019-10-31 15:44:26 +00:00
|
|
|
"ListPlatformApplicationsResult"
|
|
|
|
]["PlatformApplications"]
|
2015-03-14 13:06:31 +00:00
|
|
|
applications.should.have.length_of(2)
|
|
|
|
|
|
|
|
|
2021-09-23 11:50:59 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_sns_deprecated
|
2015-03-14 13:06:31 +00:00
|
|
|
def test_delete_platform_application():
|
|
|
|
conn = boto.connect_sns()
|
2019-10-31 15:44:26 +00:00
|
|
|
conn.create_platform_application(name="application1", platform="APNS")
|
|
|
|
conn.create_platform_application(name="application2", platform="APNS")
|
2015-03-14 13:06:31 +00:00
|
|
|
|
2020-01-20 23:21:11 +00:00
|
|
|
applications_response = conn.list_platform_applications()
|
|
|
|
applications = applications_response["ListPlatformApplicationsResponse"][
|
2019-10-31 15:44:26 +00:00
|
|
|
"ListPlatformApplicationsResult"
|
|
|
|
]["PlatformApplications"]
|
2015-03-14 13:06:31 +00:00
|
|
|
applications.should.have.length_of(2)
|
|
|
|
|
2019-10-31 15:44:26 +00:00
|
|
|
application_arn = applications[0]["PlatformApplicationArn"]
|
2015-03-14 13:06:31 +00:00
|
|
|
conn.delete_platform_application(application_arn)
|
|
|
|
|
2020-01-20 23:21:11 +00:00
|
|
|
applications_response = conn.list_platform_applications()
|
|
|
|
applications = applications_response["ListPlatformApplicationsResponse"][
|
2019-10-31 15:44:26 +00:00
|
|
|
"ListPlatformApplicationsResult"
|
|
|
|
]["PlatformApplications"]
|
2015-03-14 13:06:31 +00:00
|
|
|
applications.should.have.length_of(1)
|
|
|
|
|
|
|
|
|
2021-09-23 11:50:59 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_sns_deprecated
|
2015-03-14 13:06:31 +00:00
|
|
|
def test_create_platform_endpoint():
|
|
|
|
conn = boto.connect_sns()
|
|
|
|
platform_application = conn.create_platform_application(
|
2019-10-31 15:44:26 +00:00
|
|
|
name="my-application", platform="APNS"
|
2015-03-14 13:06:31 +00:00
|
|
|
)
|
2019-10-31 15:44:26 +00:00
|
|
|
application_arn = platform_application["CreatePlatformApplicationResponse"][
|
|
|
|
"CreatePlatformApplicationResult"
|
|
|
|
]["PlatformApplicationArn"]
|
2015-03-14 13:06:31 +00:00
|
|
|
|
|
|
|
endpoint = conn.create_platform_endpoint(
|
|
|
|
platform_application_arn=application_arn,
|
|
|
|
token="some_unique_id",
|
|
|
|
custom_user_data="some user data",
|
2019-10-31 15:44:26 +00:00
|
|
|
attributes={"Enabled": False},
|
2015-03-14 13:06:31 +00:00
|
|
|
)
|
|
|
|
|
2019-10-31 15:44:26 +00:00
|
|
|
endpoint_arn = endpoint["CreatePlatformEndpointResponse"][
|
|
|
|
"CreatePlatformEndpointResult"
|
|
|
|
]["EndpointArn"]
|
2017-02-24 02:37:43 +00:00
|
|
|
endpoint_arn.should.contain(
|
2019-12-16 00:22:26 +00:00
|
|
|
"arn:aws:sns:us-east-1:{}:endpoint/APNS/my-application/".format(ACCOUNT_ID)
|
2019-10-31 15:44:26 +00:00
|
|
|
)
|
2015-03-06 17:35:17 +00:00
|
|
|
|
|
|
|
|
2021-09-23 11:50:59 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_sns_deprecated
|
2015-03-06 17:35:17 +00:00
|
|
|
def test_get_list_endpoints_by_platform_application():
|
|
|
|
conn = boto.connect_sns()
|
2015-03-14 13:06:31 +00:00
|
|
|
platform_application = conn.create_platform_application(
|
2019-10-31 15:44:26 +00:00
|
|
|
name="my-application", platform="APNS"
|
2015-03-14 13:06:31 +00:00
|
|
|
)
|
2019-10-31 15:44:26 +00:00
|
|
|
application_arn = platform_application["CreatePlatformApplicationResponse"][
|
|
|
|
"CreatePlatformApplicationResult"
|
|
|
|
]["PlatformApplicationArn"]
|
2015-03-14 13:06:31 +00:00
|
|
|
|
|
|
|
endpoint = conn.create_platform_endpoint(
|
|
|
|
platform_application_arn=application_arn,
|
|
|
|
token="some_unique_id",
|
|
|
|
custom_user_data="some user data",
|
2019-10-31 15:44:26 +00:00
|
|
|
attributes={"CustomUserData": "some data"},
|
2015-03-14 13:06:31 +00:00
|
|
|
)
|
2019-10-31 15:44:26 +00:00
|
|
|
endpoint_arn = endpoint["CreatePlatformEndpointResponse"][
|
|
|
|
"CreatePlatformEndpointResult"
|
|
|
|
]["EndpointArn"]
|
2015-03-14 13:06:31 +00:00
|
|
|
|
2015-03-06 17:35:17 +00:00
|
|
|
endpoint_list = conn.list_endpoints_by_platform_application(
|
2015-03-14 13:06:31 +00:00
|
|
|
platform_application_arn=application_arn
|
2019-10-31 15:44:26 +00:00
|
|
|
)["ListEndpointsByPlatformApplicationResponse"][
|
|
|
|
"ListEndpointsByPlatformApplicationResult"
|
|
|
|
][
|
|
|
|
"Endpoints"
|
|
|
|
]
|
2015-03-06 17:35:17 +00:00
|
|
|
|
|
|
|
endpoint_list.should.have.length_of(1)
|
2019-10-31 15:44:26 +00:00
|
|
|
endpoint_list[0]["Attributes"]["CustomUserData"].should.equal("some data")
|
|
|
|
endpoint_list[0]["EndpointArn"].should.equal(endpoint_arn)
|
2015-03-14 13:06:31 +00:00
|
|
|
|
|
|
|
|
2021-09-23 11:50:59 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_sns_deprecated
|
2015-03-14 13:06:31 +00:00
|
|
|
def test_get_endpoint_attributes():
|
|
|
|
conn = boto.connect_sns()
|
|
|
|
platform_application = conn.create_platform_application(
|
2019-10-31 15:44:26 +00:00
|
|
|
name="my-application", platform="APNS"
|
2015-03-14 13:06:31 +00:00
|
|
|
)
|
2019-10-31 15:44:26 +00:00
|
|
|
application_arn = platform_application["CreatePlatformApplicationResponse"][
|
|
|
|
"CreatePlatformApplicationResult"
|
|
|
|
]["PlatformApplicationArn"]
|
2015-03-14 13:06:31 +00:00
|
|
|
|
|
|
|
endpoint = conn.create_platform_endpoint(
|
|
|
|
platform_application_arn=application_arn,
|
|
|
|
token="some_unique_id",
|
|
|
|
custom_user_data="some user data",
|
2020-12-14 15:08:33 +00:00
|
|
|
attributes={"CustomUserData": "some data"},
|
2019-10-31 15:44:26 +00:00
|
|
|
)
|
|
|
|
endpoint_arn = endpoint["CreatePlatformEndpointResponse"][
|
|
|
|
"CreatePlatformEndpointResult"
|
|
|
|
]["EndpointArn"]
|
|
|
|
|
|
|
|
attributes = conn.get_endpoint_attributes(endpoint_arn)[
|
|
|
|
"GetEndpointAttributesResponse"
|
|
|
|
]["GetEndpointAttributesResult"]["Attributes"]
|
|
|
|
attributes.should.equal(
|
2020-12-14 15:08:33 +00:00
|
|
|
{"Token": "some_unique_id", "Enabled": "true", "CustomUserData": "some data"}
|
2015-03-14 13:06:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-09-23 11:50:59 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_sns_deprecated
|
2015-03-14 13:06:31 +00:00
|
|
|
def test_get_missing_endpoint_attributes():
|
|
|
|
conn = boto.connect_sns()
|
2019-10-31 15:44:26 +00:00
|
|
|
conn.get_endpoint_attributes.when.called_with("a-fake-arn").should.throw(
|
|
|
|
BotoServerError
|
|
|
|
)
|
2015-03-14 13:06:31 +00:00
|
|
|
|
|
|
|
|
2021-09-23 11:50:59 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_sns_deprecated
|
2015-03-14 13:06:31 +00:00
|
|
|
def test_set_endpoint_attributes():
|
|
|
|
conn = boto.connect_sns()
|
|
|
|
platform_application = conn.create_platform_application(
|
2019-10-31 15:44:26 +00:00
|
|
|
name="my-application", platform="APNS"
|
2015-03-14 13:06:31 +00:00
|
|
|
)
|
2019-10-31 15:44:26 +00:00
|
|
|
application_arn = platform_application["CreatePlatformApplicationResponse"][
|
|
|
|
"CreatePlatformApplicationResult"
|
|
|
|
]["PlatformApplicationArn"]
|
2015-03-14 13:06:31 +00:00
|
|
|
|
|
|
|
endpoint = conn.create_platform_endpoint(
|
|
|
|
platform_application_arn=application_arn,
|
|
|
|
token="some_unique_id",
|
|
|
|
custom_user_data="some user data",
|
2019-10-31 15:44:26 +00:00
|
|
|
attributes={"Enabled": False, "CustomUserData": "some data"},
|
|
|
|
)
|
|
|
|
endpoint_arn = endpoint["CreatePlatformEndpointResponse"][
|
|
|
|
"CreatePlatformEndpointResult"
|
|
|
|
]["EndpointArn"]
|
|
|
|
|
|
|
|
conn.set_endpoint_attributes(endpoint_arn, {"CustomUserData": "other data"})
|
|
|
|
attributes = conn.get_endpoint_attributes(endpoint_arn)[
|
|
|
|
"GetEndpointAttributesResponse"
|
|
|
|
]["GetEndpointAttributesResult"]["Attributes"]
|
|
|
|
attributes.should.equal(
|
2020-12-14 15:08:33 +00:00
|
|
|
{"Token": "some_unique_id", "Enabled": "false", "CustomUserData": "other data"}
|
2015-03-14 13:06:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-09-23 11:50:59 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_sns_deprecated
|
2016-05-02 12:34:51 +00:00
|
|
|
def test_delete_endpoint():
|
|
|
|
conn = boto.connect_sns()
|
|
|
|
platform_application = conn.create_platform_application(
|
2019-10-31 15:44:26 +00:00
|
|
|
name="my-application", platform="APNS"
|
2016-05-02 12:34:51 +00:00
|
|
|
)
|
2019-10-31 15:44:26 +00:00
|
|
|
application_arn = platform_application["CreatePlatformApplicationResponse"][
|
|
|
|
"CreatePlatformApplicationResult"
|
|
|
|
]["PlatformApplicationArn"]
|
2016-05-02 12:34:51 +00:00
|
|
|
|
|
|
|
endpoint = conn.create_platform_endpoint(
|
|
|
|
platform_application_arn=application_arn,
|
|
|
|
token="some_unique_id",
|
|
|
|
custom_user_data="some user data",
|
2019-10-31 15:44:26 +00:00
|
|
|
attributes={"Enabled": False, "CustomUserData": "some data"},
|
2016-05-02 12:34:51 +00:00
|
|
|
)
|
2019-10-31 15:44:26 +00:00
|
|
|
endpoint_arn = endpoint["CreatePlatformEndpointResponse"][
|
|
|
|
"CreatePlatformEndpointResult"
|
|
|
|
]["EndpointArn"]
|
2016-05-02 12:34:51 +00:00
|
|
|
|
|
|
|
endpoint_list = conn.list_endpoints_by_platform_application(
|
|
|
|
platform_application_arn=application_arn
|
2019-10-31 15:44:26 +00:00
|
|
|
)["ListEndpointsByPlatformApplicationResponse"][
|
|
|
|
"ListEndpointsByPlatformApplicationResult"
|
|
|
|
][
|
|
|
|
"Endpoints"
|
|
|
|
]
|
2016-05-02 12:34:51 +00:00
|
|
|
|
|
|
|
endpoint_list.should.have.length_of(1)
|
|
|
|
|
|
|
|
conn.delete_endpoint(endpoint_arn)
|
|
|
|
|
|
|
|
endpoint_list = conn.list_endpoints_by_platform_application(
|
|
|
|
platform_application_arn=application_arn
|
2019-10-31 15:44:26 +00:00
|
|
|
)["ListEndpointsByPlatformApplicationResponse"][
|
|
|
|
"ListEndpointsByPlatformApplicationResult"
|
|
|
|
][
|
|
|
|
"Endpoints"
|
|
|
|
]
|
2016-05-02 12:34:51 +00:00
|
|
|
endpoint_list.should.have.length_of(0)
|
|
|
|
|
|
|
|
|
2021-09-23 11:50:59 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_sns_deprecated
|
2015-03-14 13:06:31 +00:00
|
|
|
def test_publish_to_platform_endpoint():
|
|
|
|
conn = boto.connect_sns()
|
|
|
|
platform_application = conn.create_platform_application(
|
2019-10-31 15:44:26 +00:00
|
|
|
name="my-application", platform="APNS"
|
2015-03-14 13:06:31 +00:00
|
|
|
)
|
2019-10-31 15:44:26 +00:00
|
|
|
application_arn = platform_application["CreatePlatformApplicationResponse"][
|
|
|
|
"CreatePlatformApplicationResult"
|
|
|
|
]["PlatformApplicationArn"]
|
2015-03-14 13:06:31 +00:00
|
|
|
|
|
|
|
endpoint = conn.create_platform_endpoint(
|
|
|
|
platform_application_arn=application_arn,
|
|
|
|
token="some_unique_id",
|
|
|
|
custom_user_data="some user data",
|
2019-10-31 15:44:26 +00:00
|
|
|
attributes={"Enabled": True},
|
2015-03-14 13:06:31 +00:00
|
|
|
)
|
|
|
|
|
2019-10-31 15:44:26 +00:00
|
|
|
endpoint_arn = endpoint["CreatePlatformEndpointResponse"][
|
|
|
|
"CreatePlatformEndpointResult"
|
|
|
|
]["EndpointArn"]
|
2015-03-14 13:06:31 +00:00
|
|
|
|
2019-10-31 15:44:26 +00:00
|
|
|
conn.publish(
|
|
|
|
message="some message", message_structure="json", target_arn=endpoint_arn
|
|
|
|
)
|