black linting
This commit is contained in:
parent
82825787db
commit
c9b38e25b8
4 changed files with 578 additions and 298 deletions
|
|
@ -21,18 +21,29 @@ from moto import mock_ssm, mock_cloudformation
|
|||
|
||||
|
||||
def _get_yaml_template():
|
||||
template_path = '/'.join(['test_ssm', 'test_templates', 'good.yaml'])
|
||||
resource_path = pkg_resources.resource_string('tests', template_path)
|
||||
template_path = "/".join(["test_ssm", "test_templates", "good.yaml"])
|
||||
resource_path = pkg_resources.resource_string("tests", template_path)
|
||||
return resource_path
|
||||
|
||||
|
||||
def _validate_document_description(doc_name, doc_description, json_doc, expected_document_version,
|
||||
expected_latest_version, expected_default_version, expected_format):
|
||||
def _validate_document_description(
|
||||
doc_name,
|
||||
doc_description,
|
||||
json_doc,
|
||||
expected_document_version,
|
||||
expected_latest_version,
|
||||
expected_default_version,
|
||||
expected_format,
|
||||
):
|
||||
|
||||
if expected_format == "JSON":
|
||||
doc_description["Hash"].should.equal(hashlib.sha256(json.dumps(json_doc).encode('utf-8')).hexdigest())
|
||||
doc_description["Hash"].should.equal(
|
||||
hashlib.sha256(json.dumps(json_doc).encode("utf-8")).hexdigest()
|
||||
)
|
||||
else:
|
||||
doc_description["Hash"].should.equal(hashlib.sha256(yaml.dump(json_doc).encode('utf-8')).hexdigest())
|
||||
doc_description["Hash"].should.equal(
|
||||
hashlib.sha256(yaml.dump(json_doc).encode("utf-8")).hexdigest()
|
||||
)
|
||||
|
||||
doc_description["HashType"].should.equal("Sha256")
|
||||
doc_description["Name"].should.equal(doc_name)
|
||||
|
|
@ -63,7 +74,7 @@ def _validate_document_description(doc_name, doc_description, json_doc, expected
|
|||
doc_description["Parameters"][3]["Name"].should.equal("Parameter4")
|
||||
doc_description["Parameters"][3]["Type"].should.equal("StringList")
|
||||
doc_description["Parameters"][3]["Description"].should.equal("A string list")
|
||||
doc_description["Parameters"][3]["DefaultValue"].should.equal("[\"abc\", \"def\"]")
|
||||
doc_description["Parameters"][3]["DefaultValue"].should.equal('["abc", "def"]')
|
||||
|
||||
doc_description["Parameters"][4]["Name"].should.equal("Parameter5")
|
||||
doc_description["Parameters"][4]["Type"].should.equal("StringMap")
|
||||
|
|
@ -74,22 +85,32 @@ def _validate_document_description(doc_name, doc_description, json_doc, expected
|
|||
if expected_format == "JSON":
|
||||
# We have to replace single quotes from the response to package it back up
|
||||
json.loads(doc_description["Parameters"][4]["DefaultValue"]).should.equal(
|
||||
{'NotificationArn': '$dependency.topicArn',
|
||||
'NotificationEvents': ['Failed'],
|
||||
'NotificationType': 'Command'})
|
||||
{
|
||||
"NotificationArn": "$dependency.topicArn",
|
||||
"NotificationEvents": ["Failed"],
|
||||
"NotificationType": "Command",
|
||||
}
|
||||
)
|
||||
|
||||
json.loads(doc_description["Parameters"][5]["DefaultValue"]).should.equal(
|
||||
[{'DeviceName': '/dev/sda1', 'Ebs': {'VolumeSize': '50'}},
|
||||
{'DeviceName': '/dev/sdm', 'Ebs': {'VolumeSize': '100'}}]
|
||||
[
|
||||
{"DeviceName": "/dev/sda1", "Ebs": {"VolumeSize": "50"}},
|
||||
{"DeviceName": "/dev/sdm", "Ebs": {"VolumeSize": "100"}},
|
||||
]
|
||||
)
|
||||
else:
|
||||
yaml.safe_load(doc_description["Parameters"][4]["DefaultValue"]).should.equal(
|
||||
{'NotificationArn': '$dependency.topicArn',
|
||||
'NotificationEvents': ['Failed'],
|
||||
'NotificationType': 'Command'})
|
||||
{
|
||||
"NotificationArn": "$dependency.topicArn",
|
||||
"NotificationEvents": ["Failed"],
|
||||
"NotificationType": "Command",
|
||||
}
|
||||
)
|
||||
yaml.safe_load(doc_description["Parameters"][5]["DefaultValue"]).should.equal(
|
||||
[{'DeviceName': '/dev/sda1', 'Ebs': {'VolumeSize': '50'}},
|
||||
{'DeviceName': '/dev/sdm', 'Ebs': {'VolumeSize': '100'}}]
|
||||
[
|
||||
{"DeviceName": "/dev/sda1", "Ebs": {"VolumeSize": "50"}},
|
||||
{"DeviceName": "/dev/sdm", "Ebs": {"VolumeSize": "100"}},
|
||||
]
|
||||
)
|
||||
|
||||
doc_description["DocumentType"].should.equal("Command")
|
||||
|
|
@ -98,7 +119,10 @@ def _validate_document_description(doc_name, doc_description, json_doc, expected
|
|||
doc_description["DefaultVersion"].should.equal(expected_default_version)
|
||||
doc_description["DocumentFormat"].should.equal(expected_format)
|
||||
|
||||
def _get_doc_validator(response, version_name, doc_version, json_doc_content, document_format):
|
||||
|
||||
def _get_doc_validator(
|
||||
response, version_name, doc_version, json_doc_content, document_format
|
||||
):
|
||||
response["Name"].should.equal("TestDocument3")
|
||||
if version_name:
|
||||
response["VersionName"].should.equal(version_name)
|
||||
|
|
@ -111,6 +135,7 @@ def _get_doc_validator(response, version_name, doc_version, json_doc_content, do
|
|||
response["DocumentType"].should.equal("Command")
|
||||
response["DocumentFormat"].should.equal(document_format)
|
||||
|
||||
|
||||
# Done
|
||||
@mock_ssm
|
||||
def test_create_document():
|
||||
|
|
@ -120,27 +145,45 @@ def test_create_document():
|
|||
client = boto3.client("ssm", region_name="us-east-1")
|
||||
|
||||
response = client.create_document(
|
||||
Content=yaml.dump(json_doc), Name="TestDocument", DocumentType="Command", DocumentFormat="YAML"
|
||||
Content=yaml.dump(json_doc),
|
||||
Name="TestDocument",
|
||||
DocumentType="Command",
|
||||
DocumentFormat="YAML",
|
||||
)
|
||||
doc_description = response["DocumentDescription"]
|
||||
_validate_document_description("TestDocument", doc_description, json_doc, "1", "1", "1", "YAML")
|
||||
_validate_document_description(
|
||||
"TestDocument", doc_description, json_doc, "1", "1", "1", "YAML"
|
||||
)
|
||||
|
||||
response = client.create_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument2", DocumentType="Command", DocumentFormat="JSON"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument2",
|
||||
DocumentType="Command",
|
||||
DocumentFormat="JSON",
|
||||
)
|
||||
doc_description = response["DocumentDescription"]
|
||||
_validate_document_description("TestDocument2", doc_description, json_doc, "1", "1", "1", "JSON")
|
||||
_validate_document_description(
|
||||
"TestDocument2", doc_description, json_doc, "1", "1", "1", "JSON"
|
||||
)
|
||||
|
||||
response = client.create_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument3", DocumentType="Command", DocumentFormat="JSON",
|
||||
VersionName="Base", TargetType="/AWS::EC2::Instance", Tags=[{'Key': 'testing', 'Value': 'testingValue'}]
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument3",
|
||||
DocumentType="Command",
|
||||
DocumentFormat="JSON",
|
||||
VersionName="Base",
|
||||
TargetType="/AWS::EC2::Instance",
|
||||
Tags=[{"Key": "testing", "Value": "testingValue"}],
|
||||
)
|
||||
doc_description = response["DocumentDescription"]
|
||||
doc_description["VersionName"].should.equal("Base")
|
||||
doc_description["TargetType"].should.equal("/AWS::EC2::Instance")
|
||||
doc_description["Tags"].should.equal([{'Key': 'testing', 'Value': 'testingValue'}])
|
||||
doc_description["Tags"].should.equal([{"Key": "testing", "Value": "testingValue"}])
|
||||
|
||||
_validate_document_description(
|
||||
"TestDocument3", doc_description, json_doc, "1", "1", "1", "JSON"
|
||||
)
|
||||
|
||||
_validate_document_description("TestDocument3", doc_description, json_doc, "1", "1", "1", "JSON")
|
||||
|
||||
# Done
|
||||
@mock_ssm
|
||||
|
|
@ -155,18 +198,26 @@ def test_get_document():
|
|||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("GetDocument")
|
||||
err.response["Error"]["Message"].should.equal("The specified document does not exist.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"The specified document does not exist."
|
||||
)
|
||||
|
||||
client.create_document(
|
||||
Content=yaml.dump(json_doc), Name="TestDocument3", DocumentType="Command", DocumentFormat="YAML",
|
||||
VersionName="Base"
|
||||
Content=yaml.dump(json_doc),
|
||||
Name="TestDocument3",
|
||||
DocumentType="Command",
|
||||
DocumentFormat="YAML",
|
||||
VersionName="Base",
|
||||
)
|
||||
|
||||
new_json_doc = copy.copy(json_doc)
|
||||
new_json_doc['description'] = "a new description"
|
||||
new_json_doc["description"] = "a new description"
|
||||
|
||||
client.update_document(
|
||||
Content=json.dumps(new_json_doc), Name="TestDocument3", DocumentVersion="$LATEST", VersionName="NewBase"
|
||||
Content=json.dumps(new_json_doc),
|
||||
Name="TestDocument3",
|
||||
DocumentVersion="$LATEST",
|
||||
VersionName="NewBase",
|
||||
)
|
||||
|
||||
response = client.get_document(Name="TestDocument3")
|
||||
|
|
@ -190,32 +241,38 @@ def test_get_document():
|
|||
response = client.get_document(Name="TestDocument3", VersionName="NewBase")
|
||||
_get_doc_validator(response, "NewBase", "2", new_json_doc, "JSON")
|
||||
|
||||
response = client.get_document(Name="TestDocument3", VersionName="NewBase", DocumentVersion="2")
|
||||
response = client.get_document(
|
||||
Name="TestDocument3", VersionName="NewBase", DocumentVersion="2"
|
||||
)
|
||||
_get_doc_validator(response, "NewBase", "2", new_json_doc, "JSON")
|
||||
|
||||
try:
|
||||
response = client.get_document(Name="TestDocument3", VersionName="BadName", DocumentVersion="2")
|
||||
response = client.get_document(
|
||||
Name="TestDocument3", VersionName="BadName", DocumentVersion="2"
|
||||
)
|
||||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("GetDocument")
|
||||
err.response["Error"]["Message"].should.equal("The specified document does not exist.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"The specified document does not exist."
|
||||
)
|
||||
|
||||
try:
|
||||
response = client.get_document(Name="TestDocument3", DocumentVersion="3")
|
||||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("GetDocument")
|
||||
err.response["Error"]["Message"].should.equal("The specified document does not exist.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"The specified document does not exist."
|
||||
)
|
||||
|
||||
# Updating default should update normal get
|
||||
client.update_document_default_version(
|
||||
Name="TestDocument3",
|
||||
DocumentVersion="2"
|
||||
)
|
||||
client.update_document_default_version(Name="TestDocument3", DocumentVersion="2")
|
||||
|
||||
response = client.get_document(Name="TestDocument3", DocumentFormat="JSON")
|
||||
_get_doc_validator(response, "NewBase", "2", new_json_doc, "JSON")
|
||||
|
||||
|
||||
@mock_ssm
|
||||
def test_delete_document():
|
||||
template_file = _get_yaml_template()
|
||||
|
|
@ -227,12 +284,18 @@ def test_delete_document():
|
|||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("DeleteDocument")
|
||||
err.response["Error"]["Message"].should.equal("The specified document does not exist.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"The specified document does not exist."
|
||||
)
|
||||
|
||||
# Test simple
|
||||
client.create_document(
|
||||
Content=yaml.dump(json_doc), Name="TestDocument3", DocumentType="Command", DocumentFormat="YAML",
|
||||
VersionName="Base", TargetType="/AWS::EC2::Instance"
|
||||
Content=yaml.dump(json_doc),
|
||||
Name="TestDocument3",
|
||||
DocumentType="Command",
|
||||
DocumentFormat="YAML",
|
||||
VersionName="Base",
|
||||
TargetType="/AWS::EC2::Instance",
|
||||
)
|
||||
client.delete_document(Name="TestDocument3")
|
||||
|
||||
|
|
@ -241,51 +304,68 @@ def test_delete_document():
|
|||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("GetDocument")
|
||||
err.response["Error"]["Message"].should.equal("The specified document does not exist.")
|
||||
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"The specified document does not exist."
|
||||
)
|
||||
|
||||
# Delete default version with other version is bad
|
||||
client.create_document(
|
||||
Content=yaml.dump(json_doc), Name="TestDocument3", DocumentType="Command", DocumentFormat="YAML",
|
||||
VersionName="Base", TargetType="/AWS::EC2::Instance"
|
||||
Content=yaml.dump(json_doc),
|
||||
Name="TestDocument3",
|
||||
DocumentType="Command",
|
||||
DocumentFormat="YAML",
|
||||
VersionName="Base",
|
||||
TargetType="/AWS::EC2::Instance",
|
||||
)
|
||||
|
||||
new_json_doc = copy.copy(json_doc)
|
||||
new_json_doc['description'] = "a new description"
|
||||
new_json_doc["description"] = "a new description"
|
||||
|
||||
client.update_document(
|
||||
Content=json.dumps(new_json_doc), Name="TestDocument3", DocumentVersion="$LATEST", VersionName="NewBase"
|
||||
Content=json.dumps(new_json_doc),
|
||||
Name="TestDocument3",
|
||||
DocumentVersion="$LATEST",
|
||||
VersionName="NewBase",
|
||||
)
|
||||
|
||||
new_json_doc['description'] = "a new description2"
|
||||
new_json_doc["description"] = "a new description2"
|
||||
client.update_document(
|
||||
Content=json.dumps(new_json_doc), Name="TestDocument3", DocumentVersion="$LATEST"
|
||||
Content=json.dumps(new_json_doc),
|
||||
Name="TestDocument3",
|
||||
DocumentVersion="$LATEST",
|
||||
)
|
||||
|
||||
new_json_doc['description'] = "a new description3"
|
||||
new_json_doc["description"] = "a new description3"
|
||||
client.update_document(
|
||||
Content=json.dumps(new_json_doc), Name="TestDocument3", DocumentVersion="$LATEST"
|
||||
Content=json.dumps(new_json_doc),
|
||||
Name="TestDocument3",
|
||||
DocumentVersion="$LATEST",
|
||||
)
|
||||
|
||||
new_json_doc['description'] = "a new description4"
|
||||
new_json_doc["description"] = "a new description4"
|
||||
client.update_document(
|
||||
Content=json.dumps(new_json_doc), Name="TestDocument3", DocumentVersion="$LATEST"
|
||||
Content=json.dumps(new_json_doc),
|
||||
Name="TestDocument3",
|
||||
DocumentVersion="$LATEST",
|
||||
)
|
||||
|
||||
|
||||
try:
|
||||
client.delete_document(Name="TestDocument3", DocumentVersion="1")
|
||||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("DeleteDocument")
|
||||
err.response["Error"]["Message"].should.equal("Default version of the document can't be deleted.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"Default version of the document can't be deleted."
|
||||
)
|
||||
|
||||
try:
|
||||
client.delete_document(Name="TestDocument3", VersionName="Base")
|
||||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("DeleteDocument")
|
||||
err.response["Error"]["Message"].should.equal("Default version of the document can't be deleted.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"Default version of the document can't be deleted."
|
||||
)
|
||||
|
||||
# Make sure no ill side effects
|
||||
response = client.get_document(Name="TestDocument3")
|
||||
|
|
@ -311,24 +391,31 @@ def test_delete_document():
|
|||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("GetDocument")
|
||||
err.response["Error"]["Message"].should.equal("The specified document does not exist.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"The specified document does not exist."
|
||||
)
|
||||
|
||||
try:
|
||||
client.get_document(Name="TestDocument3", DocumentVersion="3")
|
||||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("GetDocument")
|
||||
err.response["Error"]["Message"].should.equal("The specified document does not exist.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"The specified document does not exist."
|
||||
)
|
||||
|
||||
try:
|
||||
client.get_document(Name="TestDocument3", DocumentVersion="4")
|
||||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("GetDocument")
|
||||
err.response["Error"]["Message"].should.equal("The specified document does not exist.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"The specified document does not exist."
|
||||
)
|
||||
|
||||
response = client.list_documents()
|
||||
len(response['DocumentIdentifiers']).should.equal(0)
|
||||
len(response["DocumentIdentifiers"]).should.equal(0)
|
||||
|
||||
|
||||
# Done
|
||||
@mock_ssm
|
||||
|
|
@ -342,46 +429,55 @@ def test_update_document_default_version():
|
|||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("UpdateDocumentDefaultVersion")
|
||||
err.response["Error"]["Message"].should.equal("The specified document does not exist.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"The specified document does not exist."
|
||||
)
|
||||
|
||||
client.create_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument", DocumentType="Command", VersionName="Base"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument",
|
||||
DocumentType="Command",
|
||||
VersionName="Base",
|
||||
)
|
||||
|
||||
json_doc['description'] = "a new description"
|
||||
json_doc["description"] = "a new description"
|
||||
|
||||
client.update_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument", DocumentVersion="$LATEST",
|
||||
DocumentFormat="JSON"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument",
|
||||
DocumentVersion="$LATEST",
|
||||
DocumentFormat="JSON",
|
||||
)
|
||||
|
||||
json_doc['description'] = "a new description2"
|
||||
json_doc["description"] = "a new description2"
|
||||
|
||||
client.update_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument", DocumentVersion="$LATEST"
|
||||
)
|
||||
|
||||
response = client.update_document_default_version(
|
||||
Name="TestDocument",
|
||||
DocumentVersion="2"
|
||||
Name="TestDocument", DocumentVersion="2"
|
||||
)
|
||||
response["Description"]["Name"].should.equal("TestDocument")
|
||||
response["Description"]["DefaultVersion"].should.equal("2")
|
||||
|
||||
json_doc['description'] = "a new description3"
|
||||
json_doc["description"] = "a new description3"
|
||||
|
||||
client.update_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument", DocumentVersion="$LATEST", VersionName="NewBase"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument",
|
||||
DocumentVersion="$LATEST",
|
||||
VersionName="NewBase",
|
||||
)
|
||||
|
||||
response = client.update_document_default_version(
|
||||
Name="TestDocument",
|
||||
DocumentVersion="4"
|
||||
Name="TestDocument", DocumentVersion="4"
|
||||
)
|
||||
response["Description"]["Name"].should.equal("TestDocument")
|
||||
response["Description"]["DefaultVersion"].should.equal("4")
|
||||
response["Description"]["DefaultVersionName"].should.equal("NewBase")
|
||||
|
||||
|
||||
# Done
|
||||
@mock_ssm
|
||||
def test_update_document():
|
||||
|
|
@ -391,54 +487,80 @@ def test_update_document():
|
|||
client = boto3.client("ssm", region_name="us-east-1")
|
||||
|
||||
try:
|
||||
client.update_document(Name="DNE", Content=json.dumps(json_doc), DocumentVersion="1", DocumentFormat="JSON")
|
||||
client.update_document(
|
||||
Name="DNE",
|
||||
Content=json.dumps(json_doc),
|
||||
DocumentVersion="1",
|
||||
DocumentFormat="JSON",
|
||||
)
|
||||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("UpdateDocument")
|
||||
err.response["Error"]["Message"].should.equal("The specified document does not exist.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"The specified document does not exist."
|
||||
)
|
||||
|
||||
client.create_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument", DocumentType="Command", DocumentFormat="JSON",
|
||||
VersionName="Base"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument",
|
||||
DocumentType="Command",
|
||||
DocumentFormat="JSON",
|
||||
VersionName="Base",
|
||||
)
|
||||
|
||||
# Duplicate content throws an error
|
||||
try:
|
||||
client.update_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument", DocumentVersion="1", DocumentFormat="JSON"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument",
|
||||
DocumentVersion="1",
|
||||
DocumentFormat="JSON",
|
||||
)
|
||||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("UpdateDocument")
|
||||
err.response["Error"]["Message"].should.equal("The content of the association document matches another "
|
||||
"document. Change the content of the document and try again.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"The content of the association document matches another "
|
||||
"document. Change the content of the document and try again."
|
||||
)
|
||||
|
||||
json_doc['description'] = "a new description"
|
||||
json_doc["description"] = "a new description"
|
||||
# Duplicate version name
|
||||
try:
|
||||
client.update_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument", DocumentVersion="1", DocumentFormat="JSON",
|
||||
VersionName="Base"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument",
|
||||
DocumentVersion="1",
|
||||
DocumentFormat="JSON",
|
||||
VersionName="Base",
|
||||
)
|
||||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("UpdateDocument")
|
||||
err.response["Error"]["Message"].should.equal("The specified version name is a duplicate.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"The specified version name is a duplicate."
|
||||
)
|
||||
|
||||
response = client.update_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument", VersionName="Base2", DocumentVersion="1",
|
||||
DocumentFormat="JSON"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument",
|
||||
VersionName="Base2",
|
||||
DocumentVersion="1",
|
||||
DocumentFormat="JSON",
|
||||
)
|
||||
response["DocumentDescription"]["Description"].should.equal("a new description")
|
||||
response["DocumentDescription"]["DocumentVersion"].should.equal("2")
|
||||
response["DocumentDescription"]["LatestVersion"].should.equal("2")
|
||||
response["DocumentDescription"]["DefaultVersion"].should.equal("1")
|
||||
|
||||
json_doc['description'] = "a new description2"
|
||||
json_doc["description"] = "a new description2"
|
||||
|
||||
response = client.update_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument", DocumentVersion="$LATEST",
|
||||
DocumentFormat="JSON", VersionName="NewBase"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument",
|
||||
DocumentVersion="$LATEST",
|
||||
DocumentFormat="JSON",
|
||||
VersionName="NewBase",
|
||||
)
|
||||
response["DocumentDescription"]["Description"].should.equal("a new description2")
|
||||
response["DocumentDescription"]["DocumentVersion"].should.equal("3")
|
||||
|
|
@ -446,6 +568,7 @@ def test_update_document():
|
|||
response["DocumentDescription"]["DefaultVersion"].should.equal("1")
|
||||
response["DocumentDescription"]["VersionName"].should.equal("NewBase")
|
||||
|
||||
|
||||
# Done
|
||||
@mock_ssm
|
||||
def test_describe_document():
|
||||
|
|
@ -458,26 +581,38 @@ def test_describe_document():
|
|||
raise RuntimeError("Should fail")
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal("DescribeDocument")
|
||||
err.response["Error"]["Message"].should.equal("The specified document does not exist.")
|
||||
err.response["Error"]["Message"].should.equal(
|
||||
"The specified document does not exist."
|
||||
)
|
||||
|
||||
client.create_document(
|
||||
Content=yaml.dump(json_doc), Name="TestDocument", DocumentType="Command", DocumentFormat="YAML",
|
||||
VersionName="Base", TargetType="/AWS::EC2::Instance", Tags=[{'Key': 'testing', 'Value': 'testingValue'}]
|
||||
Content=yaml.dump(json_doc),
|
||||
Name="TestDocument",
|
||||
DocumentType="Command",
|
||||
DocumentFormat="YAML",
|
||||
VersionName="Base",
|
||||
TargetType="/AWS::EC2::Instance",
|
||||
Tags=[{"Key": "testing", "Value": "testingValue"}],
|
||||
)
|
||||
response = client.describe_document(Name="TestDocument")
|
||||
doc_description=response['Document']
|
||||
_validate_document_description("TestDocument", doc_description, json_doc, "1", "1", "1", "YAML")
|
||||
doc_description = response["Document"]
|
||||
_validate_document_description(
|
||||
"TestDocument", doc_description, json_doc, "1", "1", "1", "YAML"
|
||||
)
|
||||
|
||||
# Adding update to check for issues
|
||||
new_json_doc = copy.copy(json_doc)
|
||||
new_json_doc['description'] = "a new description2"
|
||||
new_json_doc["description"] = "a new description2"
|
||||
|
||||
client.update_document(
|
||||
Content=json.dumps(new_json_doc), Name="TestDocument", DocumentVersion="$LATEST"
|
||||
)
|
||||
response = client.describe_document(Name="TestDocument")
|
||||
doc_description = response['Document']
|
||||
_validate_document_description("TestDocument", doc_description, json_doc, "1", "2", "1", "YAML")
|
||||
doc_description = response["Document"]
|
||||
_validate_document_description(
|
||||
"TestDocument", doc_description, json_doc, "1", "2", "1", "YAML"
|
||||
)
|
||||
|
||||
|
||||
# Done
|
||||
@mock_ssm
|
||||
|
|
@ -488,70 +623,77 @@ def test_list_documents():
|
|||
client = boto3.client("ssm", region_name="us-east-1")
|
||||
|
||||
client.create_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument", DocumentType="Command", DocumentFormat="JSON"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument",
|
||||
DocumentType="Command",
|
||||
DocumentFormat="JSON",
|
||||
)
|
||||
client.create_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument2", DocumentType="Command", DocumentFormat="JSON"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument2",
|
||||
DocumentType="Command",
|
||||
DocumentFormat="JSON",
|
||||
)
|
||||
client.create_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument3", DocumentType="Command", DocumentFormat="JSON"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument3",
|
||||
DocumentType="Command",
|
||||
DocumentFormat="JSON",
|
||||
)
|
||||
|
||||
response = client.list_documents()
|
||||
len(response['DocumentIdentifiers']).should.equal(3)
|
||||
response['DocumentIdentifiers'][0]["Name"].should.equal("TestDocument")
|
||||
response['DocumentIdentifiers'][1]["Name"].should.equal("TestDocument2")
|
||||
response['DocumentIdentifiers'][2]["Name"].should.equal("TestDocument3")
|
||||
response['NextToken'].should.equal("")
|
||||
len(response["DocumentIdentifiers"]).should.equal(3)
|
||||
response["DocumentIdentifiers"][0]["Name"].should.equal("TestDocument")
|
||||
response["DocumentIdentifiers"][1]["Name"].should.equal("TestDocument2")
|
||||
response["DocumentIdentifiers"][2]["Name"].should.equal("TestDocument3")
|
||||
response["NextToken"].should.equal("")
|
||||
|
||||
response = client.list_documents(MaxResults=1)
|
||||
len(response['DocumentIdentifiers']).should.equal(1)
|
||||
response['DocumentIdentifiers'][0]["Name"].should.equal("TestDocument")
|
||||
response['DocumentIdentifiers'][0]["DocumentVersion"].should.equal("1")
|
||||
response['NextToken'].should.equal("1")
|
||||
len(response["DocumentIdentifiers"]).should.equal(1)
|
||||
response["DocumentIdentifiers"][0]["Name"].should.equal("TestDocument")
|
||||
response["DocumentIdentifiers"][0]["DocumentVersion"].should.equal("1")
|
||||
response["NextToken"].should.equal("1")
|
||||
|
||||
response = client.list_documents(MaxResults=1, NextToken=response['NextToken'])
|
||||
len(response['DocumentIdentifiers']).should.equal(1)
|
||||
response['DocumentIdentifiers'][0]["Name"].should.equal("TestDocument2")
|
||||
response['DocumentIdentifiers'][0]["DocumentVersion"].should.equal("1")
|
||||
response['NextToken'].should.equal("2")
|
||||
response = client.list_documents(MaxResults=1, NextToken=response["NextToken"])
|
||||
len(response["DocumentIdentifiers"]).should.equal(1)
|
||||
response["DocumentIdentifiers"][0]["Name"].should.equal("TestDocument2")
|
||||
response["DocumentIdentifiers"][0]["DocumentVersion"].should.equal("1")
|
||||
response["NextToken"].should.equal("2")
|
||||
|
||||
response = client.list_documents(MaxResults=1, NextToken=response['NextToken'])
|
||||
len(response['DocumentIdentifiers']).should.equal(1)
|
||||
response['DocumentIdentifiers'][0]["Name"].should.equal("TestDocument3")
|
||||
response['DocumentIdentifiers'][0]["DocumentVersion"].should.equal("1")
|
||||
response['NextToken'].should.equal("")
|
||||
response = client.list_documents(MaxResults=1, NextToken=response["NextToken"])
|
||||
len(response["DocumentIdentifiers"]).should.equal(1)
|
||||
response["DocumentIdentifiers"][0]["Name"].should.equal("TestDocument3")
|
||||
response["DocumentIdentifiers"][0]["DocumentVersion"].should.equal("1")
|
||||
response["NextToken"].should.equal("")
|
||||
|
||||
# making sure no bad interactions with update
|
||||
json_doc['description'] = "a new description"
|
||||
json_doc["description"] = "a new description"
|
||||
client.update_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument", DocumentVersion="$LATEST",
|
||||
DocumentFormat="JSON"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument",
|
||||
DocumentVersion="$LATEST",
|
||||
DocumentFormat="JSON",
|
||||
)
|
||||
|
||||
client.update_document(
|
||||
Content=json.dumps(json_doc), Name="TestDocument2", DocumentVersion="$LATEST",
|
||||
DocumentFormat="JSON"
|
||||
Content=json.dumps(json_doc),
|
||||
Name="TestDocument2",
|
||||
DocumentVersion="$LATEST",
|
||||
DocumentFormat="JSON",
|
||||
)
|
||||
|
||||
response = client.update_document_default_version(
|
||||
Name="TestDocument",
|
||||
DocumentVersion="2"
|
||||
Name="TestDocument", DocumentVersion="2"
|
||||
)
|
||||
|
||||
response = client.list_documents()
|
||||
len(response['DocumentIdentifiers']).should.equal(3)
|
||||
response['DocumentIdentifiers'][0]["Name"].should.equal("TestDocument")
|
||||
response['DocumentIdentifiers'][0]["DocumentVersion"].should.equal("2")
|
||||
|
||||
response['DocumentIdentifiers'][1]["Name"].should.equal("TestDocument2")
|
||||
response['DocumentIdentifiers'][1]["DocumentVersion"].should.equal("1")
|
||||
|
||||
response['DocumentIdentifiers'][2]["Name"].should.equal("TestDocument3")
|
||||
response['DocumentIdentifiers'][2]["DocumentVersion"].should.equal("1")
|
||||
response['NextToken'].should.equal("")
|
||||
|
||||
|
||||
|
||||
len(response["DocumentIdentifiers"]).should.equal(3)
|
||||
response["DocumentIdentifiers"][0]["Name"].should.equal("TestDocument")
|
||||
response["DocumentIdentifiers"][0]["DocumentVersion"].should.equal("2")
|
||||
|
||||
response["DocumentIdentifiers"][1]["Name"].should.equal("TestDocument2")
|
||||
response["DocumentIdentifiers"][1]["DocumentVersion"].should.equal("1")
|
||||
|
||||
response["DocumentIdentifiers"][2]["Name"].should.equal("TestDocument3")
|
||||
response["DocumentIdentifiers"][2]["DocumentVersion"].should.equal("1")
|
||||
response["NextToken"].should.equal("")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue