Fix:SNS Create FIFO Topic (#3533)

* Fix:SNS Create FIFO Topic

* Added more tests

* change regular expression and added tests

* Handling NPE

Co-authored-by: usmanokc <usman@okcredit.in>
This commit is contained in:
usmangani1 2021-01-26 20:34:52 +05:30 committed by GitHub
commit 651998853b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 5 deletions

View file

@ -3,7 +3,7 @@ import boto3
import six
import json
import sure # noqa
# import sure # noqa
from botocore.exceptions import ClientError
from moto import mock_sns
@ -522,6 +522,43 @@ def test_untag_resource_error():
).should.throw(ClientError, "Resource does not exist")
@mock_sns
def test_create_fifo_topic():
conn = boto3.client("sns", region_name="us-east-1")
response = conn.create_topic(
Name="test_topic.fifo", Attributes={"FifoTopic": "true"}
)
assert "TopicArn" in response
try:
conn.create_topic(Name="test_topic", Attributes={"FifoTopic": "true"})
except ClientError as err:
err.response["Error"]["Code"].should.equal("InvalidParameterValue")
err.response["Error"]["Message"].should.equal(
"Fifo Topic names must end with .fifo and must be made up of only uppercase and lowercase ASCII letters, "
"numbers, underscores, and hyphens, and must be between 1 and 256 characters long."
)
try:
conn.create_topic(Name="test_topic.fifo")
except ClientError as err:
err.response["Error"]["Code"].should.equal("InvalidParameterValue")
err.response["Error"]["Message"].should.equal(
"Topic names must be made up of only uppercase and lowercase ASCII letters, numbers, underscores, "
"and hyphens, and must be between 1 and 256 characters long."
)
try:
conn.create_topic(Name="topic.name.fifo", Attributes={"FifoTopic": "true"})
except ClientError as err:
err.response["Error"]["Code"].should.equal("InvalidParameterValue")
err.response["Error"]["Message"].should.equal(
"Fifo Topic names must end with .fifo and must be made up of only uppercase and lowercase ASCII letters, "
"numbers, underscores, and hyphens, and must be between 1 and 256 characters long."
)
@mock_sns
def test_topic_kms_master_key_id_attribute():
client = boto3.client("sns", region_name="us-west-2")