Techdebt: Replace sure with regular assertions in Route53 (#6497)

This commit is contained in:
Bert Blommers 2023-07-08 21:53:09 +00:00 committed by GitHub
parent 39313ffc5b
commit cd906cea56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 373 additions and 422 deletions

View File

@ -1,5 +1,4 @@
import copy import copy
import sure # noqa # pylint: disable=unused-import
from moto.route53.models import ChangeList from moto.route53.models import ChangeList
@ -25,10 +24,10 @@ def test_last_dot_in_name_is_ignored():
change_list.append(change1) change_list.append(change1)
change_list.append(change2) change_list.append(change2)
change_list.should.contain(change1) assert change1 in change_list
change_list.should.contain(change1_alt) assert change1_alt in change_list
change_list.should.contain(change2) assert change2 in change_list
change_list.should.contain(change2_alt) assert change2_alt in change_list
def test_last_dot_is_not_stored(): def test_last_dot_is_not_stored():
@ -44,7 +43,7 @@ def test_last_dot_is_not_stored():
change_list = ChangeList() change_list = ChangeList()
change_list.append(change1) change_list.append(change1)
change_list[0]["ResourceRecordSet"]["Name"].should.equal("test.google.com") assert change_list[0]["ResourceRecordSet"]["Name"] == "test.google.com"
def test_optional_fields(): def test_optional_fields():
@ -55,4 +54,4 @@ def test_optional_fields():
change_list = ChangeList() change_list = ChangeList()
change_list.append(change) change_list.append(change)
change_list.should.equal([change]) assert change_list == [change]

View File

@ -1,12 +1,10 @@
import boto3 import boto3
from botocore.exceptions import ClientError
import sure # noqa # pylint: disable=unused-import
import botocore import botocore
import pytest import pytest
import requests import requests
from botocore.exceptions import ClientError
from moto import mock_ec2, mock_route53, settings from moto import mock_ec2, mock_route53, settings
@ -17,17 +15,17 @@ def test_create_hosted_zone():
Name="testdns.aws.com.", CallerReference=str(hash("foo")) Name="testdns.aws.com.", CallerReference=str(hash("foo"))
) )
firstzone = response["HostedZone"] firstzone = response["HostedZone"]
firstzone.should.have.key("Id").match(r"/hostedzone/[A-Z0-9]+") assert "/hostedzone/" in firstzone["Id"]
firstzone.should.have.key("Name").equal("testdns.aws.com.") assert firstzone["Name"] == "testdns.aws.com."
firstzone.should.have.key("Config").equal({"PrivateZone": False}) assert firstzone["Config"] == {"PrivateZone": False}
firstzone.should.have.key("ResourceRecordSetCount").equal(2) assert firstzone["ResourceRecordSetCount"] == 2
delegation = response["DelegationSet"] delegation = response["DelegationSet"]
delegation.should.have.key("NameServers").length_of(4) assert len(delegation["NameServers"]) == 4
delegation["NameServers"].should.contain("ns-2048.awsdns-64.com") assert "ns-2048.awsdns-64.com" in delegation["NameServers"]
delegation["NameServers"].should.contain("ns-2049.awsdns-65.net") assert "ns-2049.awsdns-65.net" in delegation["NameServers"]
delegation["NameServers"].should.contain("ns-2050.awsdns-66.org") assert "ns-2050.awsdns-66.org" in delegation["NameServers"]
delegation["NameServers"].should.contain("ns-2051.awsdns-67.co.uk") assert "ns-2051.awsdns-67.co.uk" in delegation["NameServers"]
location = response["Location"] location = response["Location"]
if not settings.TEST_SERVER_MODE: if not settings.TEST_SERVER_MODE:
@ -39,7 +37,7 @@ def test_list_hosted_zones():
conn = boto3.client("route53", region_name="us-east-1") conn = boto3.client("route53", region_name="us-east-1")
res = conn.list_hosted_zones()["HostedZones"] res = conn.list_hosted_zones()["HostedZones"]
res.should.have.length_of(0) assert len(res) == 0
zone1 = conn.create_hosted_zone( zone1 = conn.create_hosted_zone(
Name="testdns1.aws.com.", CallerReference=str(hash("foo")) Name="testdns1.aws.com.", CallerReference=str(hash("foo"))
@ -49,10 +47,10 @@ def test_list_hosted_zones():
)["HostedZone"] )["HostedZone"]
res = conn.list_hosted_zones()["HostedZones"] res = conn.list_hosted_zones()["HostedZones"]
res.should.have.length_of(2) assert len(res) == 2
res.should.contain(zone1) assert zone1 in res
res.should.contain(zone2) assert zone2 in res
@mock_route53 @mock_route53
@ -67,7 +65,7 @@ def test_delete_hosted_zone():
conn.delete_hosted_zone(Id=zone1["Id"]) conn.delete_hosted_zone(Id=zone1["Id"])
res = conn.list_hosted_zones()["HostedZones"] res = conn.list_hosted_zones()["HostedZones"]
res.should.have.length_of(1) assert len(res) == 1
@mock_route53 @mock_route53
@ -97,9 +95,10 @@ def test_delete_hosted_zone_with_change_sets():
with pytest.raises(ClientError) as exc: with pytest.raises(ClientError) as exc:
conn.delete_hosted_zone(Id=zone_id) conn.delete_hosted_zone(Id=zone_id)
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("HostedZoneNotEmpty") assert err["Code"] == "HostedZoneNotEmpty"
err["Message"].should.equal( assert (
"The hosted zone contains resource records that are not SOA or NS records." err["Message"]
== "The hosted zone contains resource records that are not SOA or NS records."
) )
@ -107,9 +106,7 @@ def test_delete_hosted_zone_with_change_sets():
def test_get_hosted_zone_count_no_zones(): def test_get_hosted_zone_count_no_zones():
conn = boto3.client("route53", region_name="us-east-1") conn = boto3.client("route53", region_name="us-east-1")
zone_count = conn.get_hosted_zone_count() zone_count = conn.get_hosted_zone_count()
zone_count.should.have.key("HostedZoneCount") assert zone_count["HostedZoneCount"] == 0
isinstance(zone_count["HostedZoneCount"], int).should.be.true
zone_count["HostedZoneCount"].should.be.equal(0)
@mock_route53 @mock_route53
@ -123,9 +120,7 @@ def test_get_hosted_zone_count_one_zone():
HostedZoneConfig=dict(PrivateZone=False, Comment=f"test {zone} com"), HostedZoneConfig=dict(PrivateZone=False, Comment=f"test {zone} com"),
) )
zone_count = conn.get_hosted_zone_count() zone_count = conn.get_hosted_zone_count()
zone_count.should.have.key("HostedZoneCount") assert zone_count["HostedZoneCount"] == 1
isinstance(zone_count["HostedZoneCount"], int).should.be.true
zone_count["HostedZoneCount"].should.be.equal(1)
@mock_route53 @mock_route53
@ -148,10 +143,7 @@ def test_get_hosted_zone_count_many_zones():
HostedZoneConfig=dict(PrivateZone=False, Comment=f"test {zone} com"), HostedZoneConfig=dict(PrivateZone=False, Comment=f"test {zone} com"),
) )
zone_count = conn.get_hosted_zone_count() zone_count = conn.get_hosted_zone_count()
zone_count.should.have.key("HostedZoneCount") assert zone_count["HostedZoneCount"] == len(zone_indexes)
isinstance(zone_count["HostedZoneCount"], int).should.be.true
zone_count["HostedZoneCount"].shouldnt.be.equal(0)
zone_count["HostedZoneCount"].should.be.equal(len(zone_indexes))
@mock_route53 @mock_route53
@ -162,8 +154,8 @@ def test_get_unknown_hosted_zone():
conn.get_hosted_zone(Id="unknown") conn.get_hosted_zone(Id="unknown")
err = ex.value.response["Error"] err = ex.value.response["Error"]
err["Code"].should.equal("NoSuchHostedZone") assert err["Code"] == "NoSuchHostedZone"
err["Message"].should.equal("No hosted zone found with ID: unknown") assert err["Message"] == "No hosted zone found with ID: unknown"
@mock_route53 @mock_route53
@ -177,7 +169,7 @@ def test_update_hosted_zone_comment():
conn.update_hosted_zone_comment(Id=zone_id, Comment="yolo") conn.update_hosted_zone_comment(Id=zone_id, Comment="yolo")
resp = conn.get_hosted_zone(Id=zone_id)["HostedZone"] resp = conn.get_hosted_zone(Id=zone_id)["HostedZone"]
resp["Config"].should.have.key("Comment").equals("yolo") assert resp["Config"]["Comment"] == "yolo"
@mock_route53 @mock_route53
@ -188,8 +180,8 @@ def test_list_resource_record_set_unknown_zone():
conn.list_resource_record_sets(HostedZoneId="abcd") conn.list_resource_record_sets(HostedZoneId="abcd")
err = ex.value.response["Error"] err = ex.value.response["Error"]
err["Code"].should.equal("NoSuchHostedZone") assert err["Code"] == "NoSuchHostedZone"
err["Message"].should.equal("No hosted zone found with ID: abcd") assert err["Message"] == "No hosted zone found with ID: abcd"
@mock_route53 @mock_route53
@ -203,8 +195,8 @@ def test_list_resource_record_set_unknown_type():
conn.list_resource_record_sets(HostedZoneId=zone["Id"], StartRecordType="A") conn.list_resource_record_sets(HostedZoneId=zone["Id"], StartRecordType="A")
err = ex.value.response["Error"] err = ex.value.response["Error"]
err["Code"].should.equal("400") assert err["Code"] == "400"
err["Message"].should.equal("Bad Request") assert err["Message"] == "Bad Request"
@mock_route53 @mock_route53
@ -249,8 +241,8 @@ def test_use_health_check_in_resource_record_set():
record_sets = conn.list_resource_record_sets(HostedZoneId=zone_id)[ record_sets = conn.list_resource_record_sets(HostedZoneId=zone_id)[
"ResourceRecordSets" "ResourceRecordSets"
] ]
record_sets[2]["Name"].should.equal("foo.bar.testdns.aws.com.") assert record_sets[2]["Name"] == "foo.bar.testdns.aws.com."
record_sets[2]["HealthCheckId"].should.equal(check_id) assert record_sets[2]["HealthCheckId"] == check_id
@mock_route53 @mock_route53
@ -265,10 +257,10 @@ def test_hosted_zone_comment_preserved():
zone_id = firstzone["HostedZone"]["Id"] zone_id = firstzone["HostedZone"]["Id"]
hosted_zone = conn.get_hosted_zone(Id=zone_id) hosted_zone = conn.get_hosted_zone(Id=zone_id)
hosted_zone["HostedZone"]["Config"]["Comment"].should.equal("test comment") assert hosted_zone["HostedZone"]["Config"]["Comment"] == "test comment"
hosted_zones = conn.list_hosted_zones() hosted_zones = conn.list_hosted_zones()
hosted_zones["HostedZones"][0]["Config"]["Comment"].should.equal("test comment") assert hosted_zones["HostedZones"][0]["Config"]["Comment"] == "test comment"
@mock_route53 @mock_route53
@ -301,7 +293,7 @@ def test_deleting_weighted_route():
cnames = conn.list_resource_record_sets( cnames = conn.list_resource_record_sets(
HostedZoneId=zone_id, StartRecordName="cname", StartRecordType="CNAME" HostedZoneId=zone_id, StartRecordName="cname", StartRecordType="CNAME"
)["ResourceRecordSets"] )["ResourceRecordSets"]
cnames.should.have.length_of(4) assert len(cnames) == 4
conn.change_resource_record_sets( conn.change_resource_record_sets(
HostedZoneId=zone_id, HostedZoneId=zone_id,
@ -323,9 +315,9 @@ def test_deleting_weighted_route():
cnames = conn.list_resource_record_sets( cnames = conn.list_resource_record_sets(
HostedZoneId=zone_id, StartRecordName="cname", StartRecordType="CNAME" HostedZoneId=zone_id, StartRecordName="cname", StartRecordType="CNAME"
)["ResourceRecordSets"] )["ResourceRecordSets"]
cnames.should.have.length_of(3) assert len(cnames) == 3
cnames[-1]["Name"].should.equal("cname.testdns.aws.com.") assert cnames[-1]["Name"] == "cname.testdns.aws.com."
cnames[-1]["SetIdentifier"].should.equal("success-test-bar") assert cnames[-1]["SetIdentifier"] == "success-test-bar"
@mock_route53 @mock_route53
@ -362,13 +354,13 @@ def test_deleting_latency_route():
cnames = conn.list_resource_record_sets( cnames = conn.list_resource_record_sets(
HostedZoneId=zone_id, StartRecordName="cname", StartRecordType="CNAME" HostedZoneId=zone_id, StartRecordName="cname", StartRecordType="CNAME"
)["ResourceRecordSets"] )["ResourceRecordSets"]
cnames.should.have.length_of(4) assert len(cnames) == 4
foo_cname = [ foo_cname = [
cname cname
for cname in cnames for cname in cnames
if cname.get("SetIdentifier") and cname["SetIdentifier"] == "success-test-foo" if cname.get("SetIdentifier") and cname["SetIdentifier"] == "success-test-foo"
][0] ][0]
foo_cname["Region"].should.equal("us-west-2") assert foo_cname["Region"] == "us-west-2"
conn.change_resource_record_sets( conn.change_resource_record_sets(
HostedZoneId=zone_id, HostedZoneId=zone_id,
@ -390,9 +382,9 @@ def test_deleting_latency_route():
cnames = conn.list_resource_record_sets( cnames = conn.list_resource_record_sets(
HostedZoneId=zone_id, StartRecordName="cname", StartRecordType="CNAME" HostedZoneId=zone_id, StartRecordName="cname", StartRecordType="CNAME"
)["ResourceRecordSets"] )["ResourceRecordSets"]
cnames.should.have.length_of(3) assert len(cnames) == 3
cnames[-1]["SetIdentifier"].should.equal("success-test-bar") assert cnames[-1]["SetIdentifier"] == "success-test-bar"
cnames[-1]["Region"].should.equal("us-west-1") assert cnames[-1]["Region"] == "us-west-1"
@mock_route53 @mock_route53
@ -416,7 +408,7 @@ def test_list_or_change_tags_for_resource_request():
response = conn.list_tags_for_resource( response = conn.list_tags_for_resource(
ResourceType="healthcheck", ResourceId=healthcheck_id ResourceType="healthcheck", ResourceId=healthcheck_id
) )
response["ResourceTagSet"]["Tags"].should.equal([]) assert response["ResourceTagSet"]["Tags"] == []
tag1 = {"Key": "Deploy", "Value": "True"} tag1 = {"Key": "Deploy", "Value": "True"}
tag2 = {"Key": "Name", "Value": "UnitTest"} tag2 = {"Key": "Name", "Value": "UnitTest"}
@ -430,13 +422,13 @@ def test_list_or_change_tags_for_resource_request():
response = conn.list_tags_for_resource( response = conn.list_tags_for_resource(
ResourceType="healthcheck", ResourceId=healthcheck_id ResourceType="healthcheck", ResourceId=healthcheck_id
) )
response.should.contain("ResourceTagSet") assert "ResourceTagSet" in response
# Validate that each key was added # Validate that each key was added
response["ResourceTagSet"]["Tags"].should.contain(tag1) assert tag1 in response["ResourceTagSet"]["Tags"]
response["ResourceTagSet"]["Tags"].should.contain(tag2) assert tag2 in response["ResourceTagSet"]["Tags"]
len(response["ResourceTagSet"]["Tags"]).should.equal(2) assert len(response["ResourceTagSet"]["Tags"]) == 2
# Try to remove the tags # Try to remove the tags
conn.change_tags_for_resource( conn.change_tags_for_resource(
@ -449,9 +441,9 @@ def test_list_or_change_tags_for_resource_request():
response = conn.list_tags_for_resource( response = conn.list_tags_for_resource(
ResourceType="healthcheck", ResourceId=healthcheck_id ResourceType="healthcheck", ResourceId=healthcheck_id
) )
response.should.contain("ResourceTagSet") assert "ResourceTagSet" in response
response["ResourceTagSet"]["Tags"].should_not.contain(tag1) assert tag1 not in response["ResourceTagSet"]["Tags"]
response["ResourceTagSet"]["Tags"].should.contain(tag2) assert tag2 in response["ResourceTagSet"]["Tags"]
# Remove the second tag # Remove the second tag
conn.change_tags_for_resource( conn.change_tags_for_resource(
@ -463,7 +455,7 @@ def test_list_or_change_tags_for_resource_request():
response = conn.list_tags_for_resource( response = conn.list_tags_for_resource(
ResourceType="healthcheck", ResourceId=healthcheck_id ResourceType="healthcheck", ResourceId=healthcheck_id
) )
response["ResourceTagSet"]["Tags"].should_not.contain(tag2) assert tag2 not in response["ResourceTagSet"]["Tags"]
# Re-add the tags # Re-add the tags
conn.change_tags_for_resource( conn.change_tags_for_resource(
@ -480,7 +472,7 @@ def test_list_or_change_tags_for_resource_request():
response = conn.list_tags_for_resource( response = conn.list_tags_for_resource(
ResourceType="healthcheck", ResourceId=healthcheck_id ResourceType="healthcheck", ResourceId=healthcheck_id
) )
response["ResourceTagSet"]["Tags"].should.equal([]) assert response["ResourceTagSet"]["Tags"] == []
@mock_ec2 @mock_ec2
@ -500,11 +492,9 @@ def test_list_hosted_zones_by_name():
) )
zone_b = conn.list_hosted_zones_by_name(DNSName="test.b.com.") zone_b = conn.list_hosted_zones_by_name(DNSName="test.b.com.")
len(zone_b["HostedZones"]).should.equal(1) assert len(zone_b["HostedZones"]) == 1
zone_b["HostedZones"][0]["Name"].should.equal("test.b.com.") assert zone_b["HostedZones"][0]["Name"] == "test.b.com."
zone_b["HostedZones"][0].should.have.key("Config") assert zone_b["HostedZones"][0]["Config"]["PrivateZone"]
zone_b["HostedZones"][0]["Config"].should.have.key("PrivateZone")
zone_b["HostedZones"][0]["Config"]["PrivateZone"].should.be.equal(True)
# We declared this a a private hosted zone above, so let's make # We declared this a a private hosted zone above, so let's make
# sure it really is! # sure it really is!
@ -512,22 +502,14 @@ def test_list_hosted_zones_by_name():
b_hosted_zone = conn.get_hosted_zone(Id=zone_b_id) b_hosted_zone = conn.get_hosted_zone(Id=zone_b_id)
# Pull the HostedZone block out and test it. # Pull the HostedZone block out and test it.
b_hosted_zone.should.have.key("HostedZone")
b_hz = b_hosted_zone["HostedZone"] b_hz = b_hosted_zone["HostedZone"]
b_hz.should.have.key("Config") assert b_hz["Config"]["PrivateZone"]
b_hz["Config"].should.have.key("PrivateZone")
b_hz["Config"]["PrivateZone"].should.be.equal(True)
# Check for the VPCs block since this *should* be a VPC-Private Zone # Check for the VPCs block since this *should* be a VPC-Private Zone
b_hosted_zone.should.have.key("VPCs") assert len(b_hosted_zone["VPCs"]) == 1
b_hosted_zone["VPCs"].should.have.length_of(1)
b_hz_vpcs = b_hosted_zone["VPCs"][0] b_hz_vpcs = b_hosted_zone["VPCs"][0]
b_hz_vpcs.should.have.key("VPCId") assert b_hz_vpcs["VPCId"] == vpc_id
b_hz_vpcs.should.have.key("VPCRegion") assert b_hz_vpcs["VPCRegion"] == region
b_hz_vpcs["VPCId"].should_not.equal("")
b_hz_vpcs["VPCRegion"].should_not.equal("")
b_hz_vpcs["VPCId"].should.be.equal(vpc_id)
b_hz_vpcs["VPCRegion"].should.be.equal(region)
# Now create other zones and test them. # Now create other zones and test them.
conn.create_hosted_zone( conn.create_hosted_zone(
@ -543,23 +525,19 @@ def test_list_hosted_zones_by_name():
# Now makes sure the other zones we created above are NOT private... # Now makes sure the other zones we created above are NOT private...
zones = conn.list_hosted_zones_by_name(DNSName="test.a.org.") zones = conn.list_hosted_zones_by_name(DNSName="test.a.org.")
len(zones["HostedZones"]).should.equal(2) assert len(zones["HostedZones"]) == 2
zones["HostedZones"][0]["Name"].should.equal("test.a.org.") assert zones["HostedZones"][0]["Name"] == "test.a.org."
zones["HostedZones"][0].should.have.key("Config") assert zones["HostedZones"][0]["Config"]["PrivateZone"] is False
zones["HostedZones"][0]["Config"].should.have.key("PrivateZone")
zones["HostedZones"][0]["Config"]["PrivateZone"].should.be.equal(False)
zones["HostedZones"][1]["Name"].should.equal("test.a.org.") assert zones["HostedZones"][1]["Name"] == "test.a.org."
zones["HostedZones"][1].should.have.key("Config") assert zones["HostedZones"][1]["Config"]["PrivateZone"] is False
zones["HostedZones"][1]["Config"].should.have.key("PrivateZone")
zones["HostedZones"][1]["Config"]["PrivateZone"].should.be.equal(False)
# test sort order # test sort order
zones = conn.list_hosted_zones_by_name() zones = conn.list_hosted_zones_by_name()
len(zones["HostedZones"]).should.equal(3) assert len(zones["HostedZones"]) == 3
zones["HostedZones"][0]["Name"].should.equal("test.b.com.") assert zones["HostedZones"][0]["Name"] == "test.b.com."
zones["HostedZones"][1]["Name"].should.equal("test.a.org.") assert zones["HostedZones"][1]["Name"] == "test.a.org."
zones["HostedZones"][2]["Name"].should.equal("test.a.org.") assert zones["HostedZones"][2]["Name"] == "test.a.org."
@mock_route53 @mock_route53
@ -588,26 +566,25 @@ def test_list_hosted_zones_by_dns_name():
# test lookup # test lookup
zones = conn.list_hosted_zones_by_name(DNSName="test.b.com.") zones = conn.list_hosted_zones_by_name(DNSName="test.b.com.")
len(zones["HostedZones"]).should.equal(1) assert len(zones["HostedZones"]) == 1
zones["DNSName"].should.equal("test.b.com.") assert zones["DNSName"] == "test.b.com."
zones = conn.list_hosted_zones_by_name(DNSName="test.a.org.") zones = conn.list_hosted_zones_by_name(DNSName="test.a.org.")
len(zones["HostedZones"]).should.equal(2) assert len(zones["HostedZones"]) == 2
zones["DNSName"].should.equal("test.a.org.") assert zones["DNSName"] == "test.a.org."
zones["DNSName"].should.equal("test.a.org.")
zones = conn.list_hosted_zones_by_name(DNSName="my.test.net.") zones = conn.list_hosted_zones_by_name(DNSName="my.test.net.")
len(zones["HostedZones"]).should.equal(1) assert len(zones["HostedZones"]) == 1
zones["DNSName"].should.equal("my.test.net.") assert zones["DNSName"] == "my.test.net."
zones = conn.list_hosted_zones_by_name(DNSName="my.test.net") zones = conn.list_hosted_zones_by_name(DNSName="my.test.net")
len(zones["HostedZones"]).should.equal(1) assert len(zones["HostedZones"]) == 1
zones["DNSName"].should.equal("my.test.net.") assert zones["DNSName"] == "my.test.net."
# test sort order # test sort order
zones = conn.list_hosted_zones_by_name() zones = conn.list_hosted_zones_by_name()
len(zones["HostedZones"]).should.equal(4) assert len(zones["HostedZones"]) == 4
zones["HostedZones"][0]["Name"].should.equal("test.b.com.") assert zones["HostedZones"][0]["Name"] == "test.b.com."
zones["HostedZones"][1]["Name"].should.equal("my.test.net.") assert zones["HostedZones"][1]["Name"] == "my.test.net."
zones["HostedZones"][2]["Name"].should.equal("test.a.org.") assert zones["HostedZones"][2]["Name"] == "test.a.org."
zones["HostedZones"][3]["Name"].should.equal("test.a.org.") assert zones["HostedZones"][3]["Name"] == "test.a.org."
@mock_route53 @mock_route53
@ -620,8 +597,8 @@ def test_change_resource_record_sets_crud_valid():
) )
zones = conn.list_hosted_zones_by_name(DNSName="db.") zones = conn.list_hosted_zones_by_name(DNSName="db.")
len(zones["HostedZones"]).should.equal(1) assert len(zones["HostedZones"]) == 1
zones["HostedZones"][0]["Name"].should.equal("db.") assert zones["HostedZones"][0]["Name"] == "db."
hosted_zone_id = zones["HostedZones"][0]["Id"] hosted_zone_id = zones["HostedZones"][0]["Id"]
# Create A Record. # Create A Record.
@ -644,12 +621,12 @@ def test_change_resource_record_sets_crud_valid():
) )
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
len(response["ResourceRecordSets"]).should.equal(3) assert len(response["ResourceRecordSets"]) == 3
a_record_detail = response["ResourceRecordSets"][2] a_record_detail = response["ResourceRecordSets"][2]
a_record_detail["Name"].should.equal("prod.redis.db.") assert a_record_detail["Name"] == "prod.redis.db."
a_record_detail["Type"].should.equal("A") assert a_record_detail["Type"] == "A"
a_record_detail["TTL"].should.equal(10) assert a_record_detail["TTL"] == 10
a_record_detail["ResourceRecords"].should.equal([{"Value": "127.0.0.1"}]) assert a_record_detail["ResourceRecords"] == [{"Value": "127.0.0.1"}]
# Update A Record. # Update A Record.
cname_record_endpoint_payload = { cname_record_endpoint_payload = {
@ -671,12 +648,12 @@ def test_change_resource_record_sets_crud_valid():
) )
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
len(response["ResourceRecordSets"]).should.equal(3) assert len(response["ResourceRecordSets"]) == 3
cname_record_detail = response["ResourceRecordSets"][2] cname_record_detail = response["ResourceRecordSets"][2]
cname_record_detail["Name"].should.equal("prod.redis.db.") assert cname_record_detail["Name"] == "prod.redis.db."
cname_record_detail["Type"].should.equal("A") assert cname_record_detail["Type"] == "A"
cname_record_detail["TTL"].should.equal(60) assert cname_record_detail["TTL"] == 60
cname_record_detail["ResourceRecords"].should.equal([{"Value": "192.168.1.1"}]) assert cname_record_detail["ResourceRecords"] == [{"Value": "192.168.1.1"}]
# Update to add Alias. # Update to add Alias.
cname_alias_record_endpoint_payload = { cname_alias_record_endpoint_payload = {
@ -703,17 +680,15 @@ def test_change_resource_record_sets_crud_valid():
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
cname_alias_record_detail = response["ResourceRecordSets"][2] cname_alias_record_detail = response["ResourceRecordSets"][2]
cname_alias_record_detail["Name"].should.equal("prod.redis.db.") assert cname_alias_record_detail["Name"] == "prod.redis.db."
cname_alias_record_detail["Type"].should.equal("A") assert cname_alias_record_detail["Type"] == "A"
cname_alias_record_detail["TTL"].should.equal(60) assert cname_alias_record_detail["TTL"] == 60
cname_alias_record_detail["AliasTarget"].should.equal( assert cname_alias_record_detail["AliasTarget"] == {
{
"HostedZoneId": hosted_zone_id, "HostedZoneId": hosted_zone_id,
"DNSName": "prod.redis.alias.", "DNSName": "prod.redis.alias.",
"EvaluateTargetHealth": False, "EvaluateTargetHealth": False,
} }
) assert "ResourceRecords" not in cname_alias_record_detail
cname_alias_record_detail.should_not.contain("ResourceRecords")
# Delete record. # Delete record.
delete_payload = { delete_payload = {
@ -734,7 +709,7 @@ def test_change_resource_record_sets_crud_valid():
HostedZoneId=hosted_zone_id, ChangeBatch=delete_payload HostedZoneId=hosted_zone_id, ChangeBatch=delete_payload
) )
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
len(response["ResourceRecordSets"]).should.equal(2) assert len(response["ResourceRecordSets"]) == 2
@mock_route53 @mock_route53
@ -747,8 +722,8 @@ def test_change_resource_record_sets_crud_valid_with_special_xml_chars():
) )
zones = conn.list_hosted_zones_by_name(DNSName="db.") zones = conn.list_hosted_zones_by_name(DNSName="db.")
len(zones["HostedZones"]).should.equal(1) assert len(zones["HostedZones"]) == 1
zones["HostedZones"][0]["Name"].should.equal("db.") assert zones["HostedZones"][0]["Name"] == "db."
hosted_zone_id = zones["HostedZones"][0]["Id"] hosted_zone_id = zones["HostedZones"][0]["Id"]
# Create TXT Record. # Create TXT Record.
@ -771,12 +746,12 @@ def test_change_resource_record_sets_crud_valid_with_special_xml_chars():
) )
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
len(response["ResourceRecordSets"]).should.equal(3) assert len(response["ResourceRecordSets"]) == 3
a_record_detail = response["ResourceRecordSets"][2] a_record_detail = response["ResourceRecordSets"][2]
a_record_detail["Name"].should.equal("prod.redis.db.") assert a_record_detail["Name"] == "prod.redis.db."
a_record_detail["Type"].should.equal("TXT") assert a_record_detail["Type"] == "TXT"
a_record_detail["TTL"].should.equal(10) assert a_record_detail["TTL"] == 10
a_record_detail["ResourceRecords"].should.equal([{"Value": "SomeInitialValue"}]) assert a_record_detail["ResourceRecords"] == [{"Value": "SomeInitialValue"}]
# Update TXT Record with XML Special Character &. # Update TXT Record with XML Special Character &.
txt_record_with_special_char_endpoint_payload = { txt_record_with_special_char_endpoint_payload = {
@ -799,14 +774,14 @@ def test_change_resource_record_sets_crud_valid_with_special_xml_chars():
) )
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
len(response["ResourceRecordSets"]).should.equal(3) assert len(response["ResourceRecordSets"]) == 3
cname_record_detail = response["ResourceRecordSets"][2] cname_record_detail = response["ResourceRecordSets"][2]
cname_record_detail["Name"].should.equal("prod.redis.db.") assert cname_record_detail["Name"] == "prod.redis.db."
cname_record_detail["Type"].should.equal("TXT") assert cname_record_detail["Type"] == "TXT"
cname_record_detail["TTL"].should.equal(60) assert cname_record_detail["TTL"] == 60
cname_record_detail["ResourceRecords"].should.equal( assert cname_record_detail["ResourceRecords"] == [
[{"Value": "SomeInitialValue&NewValue"}] {"Value": "SomeInitialValue&NewValue"}
) ]
# Delete record. # Delete record.
delete_payload = { delete_payload = {
@ -827,7 +802,7 @@ def test_change_resource_record_sets_crud_valid_with_special_xml_chars():
HostedZoneId=hosted_zone_id, ChangeBatch=delete_payload HostedZoneId=hosted_zone_id, ChangeBatch=delete_payload
) )
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
len(response["ResourceRecordSets"]).should.equal(2) assert len(response["ResourceRecordSets"]) == 2
@mock_route53 @mock_route53
@ -875,9 +850,10 @@ def test_change_resource_record_set__delete_should_match_create():
}, },
) )
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("InvalidInput") assert err["Code"] == "InvalidInput"
err["Message"].should.equal( assert (
"Invalid request: Expected exactly one of [AliasTarget, all of [TTL, and ResourceRecords], or TrafficPolicyInstanceId], but found none in Change with [Action=DELETE, Name=example.com, Type=A, SetIdentifier=null]" err["Message"]
== "Invalid request: Expected exactly one of [AliasTarget, all of [TTL, and ResourceRecords], or TrafficPolicyInstanceId], but found none in Change with [Action=DELETE, Name=example.com, Type=A, SetIdentifier=null]"
) )
@ -988,9 +964,9 @@ def test_change_weighted_resource_record_sets():
for record in response["ResourceRecordSets"]: for record in response["ResourceRecordSets"]:
if record.get("SetIdentifier"): if record.get("SetIdentifier"):
if record["SetIdentifier"] == "test1": if record["SetIdentifier"] == "test1":
record["Weight"].should.equal(90) assert record["Weight"] == 90
if record["SetIdentifier"] == "test2": if record["SetIdentifier"] == "test2":
record["Weight"].should.equal(10) assert record["Weight"] == 10
@mock_route53 @mock_route53
@ -1021,7 +997,7 @@ def test_failover_record_sets():
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
record = response["ResourceRecordSets"][2] record = response["ResourceRecordSets"][2]
record["Failover"].should.equal("PRIMARY") assert record["Failover"] == "PRIMARY"
@mock_route53 @mock_route53
@ -1062,8 +1038,8 @@ def test_geolocation_record_sets():
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
rrs = response["ResourceRecordSets"] rrs = response["ResourceRecordSets"]
rrs[2]["GeoLocation"].should.equal({"ContinentCode": "EU"}) assert rrs[2]["GeoLocation"] == {"ContinentCode": "EU"}
rrs[3]["GeoLocation"].should.equal({"CountryCode": "US", "SubdivisionCode": "NY"}) assert rrs[3]["GeoLocation"] == {"CountryCode": "US", "SubdivisionCode": "NY"}
@mock_route53 @mock_route53
@ -1076,8 +1052,8 @@ def test_change_resource_record_invalid():
) )
zones = conn.list_hosted_zones_by_name(DNSName="db.") zones = conn.list_hosted_zones_by_name(DNSName="db.")
len(zones["HostedZones"]).should.equal(1) assert len(zones["HostedZones"]) == 1
zones["HostedZones"][0]["Name"].should.equal("db.") assert zones["HostedZones"][0]["Name"] == "db."
hosted_zone_id = zones["HostedZones"][0]["Id"] hosted_zone_id = zones["HostedZones"][0]["Id"]
invalid_a_record_payload = { invalid_a_record_payload = {
@ -1101,7 +1077,7 @@ def test_change_resource_record_invalid():
) )
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
len(response["ResourceRecordSets"]).should.equal(2) assert len(response["ResourceRecordSets"]) == 2
invalid_cname_record_payload = { invalid_cname_record_payload = {
"Comment": "this should also fail", "Comment": "this should also fail",
@ -1124,7 +1100,7 @@ def test_change_resource_record_invalid():
) )
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
len(response["ResourceRecordSets"]).should.equal(2) assert len(response["ResourceRecordSets"]) == 2
@mock_route53 @mock_route53
@ -1137,8 +1113,8 @@ def test_change_resource_record_invalid_action_value():
) )
zones = conn.list_hosted_zones_by_name(DNSName="db.") zones = conn.list_hosted_zones_by_name(DNSName="db.")
len(zones["HostedZones"]).should.equal(1) assert len(zones["HostedZones"]) == 1
zones["HostedZones"][0]["Name"].should.equal("db.") assert zones["HostedZones"][0]["Name"] == "db."
hosted_zone_id = zones["HostedZones"][0]["Id"] hosted_zone_id = zones["HostedZones"][0]["Id"]
invalid_a_record_payload = { invalid_a_record_payload = {
@ -1162,14 +1138,14 @@ def test_change_resource_record_invalid_action_value():
) )
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("InvalidInput") assert err["Code"] == "InvalidInput"
err["Message"].should.equal( assert (
"Invalid XML ; cvc-enumeration-valid: Value 'INVALID_ACTION' is not facet-valid" err["Message"]
" with respect to enumeration '[CREATE, DELETE, UPSERT]'. It must be a value from the enumeration." == "Invalid XML ; cvc-enumeration-valid: Value 'INVALID_ACTION' is not facet-valid with respect to enumeration '[CREATE, DELETE, UPSERT]'. It must be a value from the enumeration."
) )
response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id) response = conn.list_resource_record_sets(HostedZoneId=hosted_zone_id)
len(response["ResourceRecordSets"]).should.equal(2) assert len(response["ResourceRecordSets"]) == 2
@mock_route53 @mock_route53
@ -1201,9 +1177,10 @@ def test_change_resource_record_set_create__should_fail_when_record_already_exis
client.change_resource_record_sets(HostedZoneId=zone_id, ChangeBatch=changes) client.change_resource_record_sets(HostedZoneId=zone_id, ChangeBatch=changes)
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("InvalidChangeBatch") assert err["Code"] == "InvalidChangeBatch"
err["Message"].should.equal( assert (
"Tried to create resource record set [name='test.cname.local.', type='CNAME'] but it already exists" err["Message"]
== "Tried to create resource record set [name='test.cname.local.', type='CNAME'] but it already exists"
) )
@ -1232,8 +1209,8 @@ def test_change_resource_record_set__should_create_record_when_using_upsert():
response = route53_client.list_resource_record_sets(HostedZoneId=hosted_zone["Id"]) response = route53_client.list_resource_record_sets(HostedZoneId=hosted_zone["Id"])
# The 1st and 2nd records are NS and SOA records, respectively. # The 1st and 2nd records are NS and SOA records, respectively.
len(response["ResourceRecordSets"]).should.equal(3) assert len(response["ResourceRecordSets"]) == 3
response["ResourceRecordSets"][2].should.equal(resource_record) assert response["ResourceRecordSets"][2] == resource_record
# a subsequest UPSERT with the same ChangeBatch should succeed as well # a subsequest UPSERT with the same ChangeBatch should succeed as well
route53_client.change_resource_record_sets( route53_client.change_resource_record_sets(
@ -1245,8 +1222,8 @@ def test_change_resource_record_set__should_create_record_when_using_upsert():
response = route53_client.list_resource_record_sets(HostedZoneId=hosted_zone["Id"]) response = route53_client.list_resource_record_sets(HostedZoneId=hosted_zone["Id"])
# The 1st and 2nd records are NS and SOA records, respectively. # The 1st and 2nd records are NS and SOA records, respectively.
len(response["ResourceRecordSets"]).should.equal(3) assert len(response["ResourceRecordSets"]) == 3
response["ResourceRecordSets"][2].should.equal(resource_record) assert response["ResourceRecordSets"][2] == resource_record
@mock_route53 @mock_route53
@ -1297,14 +1274,14 @@ def test_list_resource_record_sets_name_type_filters():
StartRecordName=all_records[start_with][1], StartRecordName=all_records[start_with][1],
) )
response["IsTruncated"].should.equal(False) assert response["IsTruncated"] is False
returned_records = [ returned_records = [
(record["Type"], record["Name"]) for record in response["ResourceRecordSets"] (record["Type"], record["Name"]) for record in response["ResourceRecordSets"]
] ]
len(returned_records).should.equal(len(all_records) - start_with) assert len(returned_records) == len(all_records) - start_with
for desired_record in all_records[start_with:]: for desired_record in all_records[start_with:]:
returned_records.should.contain(desired_record) assert desired_record in returned_records
@mock_route53 @mock_route53
@ -1314,8 +1291,8 @@ def test_get_change():
change_id = "123456" change_id = "123456"
response = conn.get_change(Id=change_id) response = conn.get_change(Id=change_id)
response["ChangeInfo"]["Id"].should.equal(change_id) assert response["ChangeInfo"]["Id"] == change_id
response["ChangeInfo"]["Status"].should.equal("INSYNC") assert response["ChangeInfo"]["Status"] == "INSYNC"
@mock_route53 @mock_route53
@ -1328,8 +1305,8 @@ def test_change_resource_record_sets_records_limit():
) )
zones = conn.list_hosted_zones_by_name(DNSName="db.") zones = conn.list_hosted_zones_by_name(DNSName="db.")
len(zones["HostedZones"]).should.equal(1) assert len(zones["HostedZones"]) == 1
zones["HostedZones"][0]["Name"].should.equal("db.") assert zones["HostedZones"][0]["Name"] == "db."
hosted_zone_id = zones["HostedZones"][0]["Id"] hosted_zone_id = zones["HostedZones"][0]["Id"]
# Changes creating exactly 1,000 resource records. # Changes creating exactly 1,000 resource records.
@ -1382,7 +1359,7 @@ def test_change_resource_record_sets_records_limit():
ChangeBatch=create_1001_resource_records_payload, ChangeBatch=create_1001_resource_records_payload,
) )
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("InvalidChangeBatch") assert err["Code"] == "InvalidChangeBatch"
# Changes upserting exactly 500 resource records. # Changes upserting exactly 500 resource records.
changes = [] changes = []
@ -1434,8 +1411,8 @@ def test_change_resource_record_sets_records_limit():
HostedZoneId=hosted_zone_id, ChangeBatch=upsert_501_resource_records_payload HostedZoneId=hosted_zone_id, ChangeBatch=upsert_501_resource_records_payload
) )
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("InvalidChangeBatch") assert err["Code"] == "InvalidChangeBatch"
err["Message"].should.equal("Number of records limit of 1000 exceeded.") assert err["Message"] == "Number of records limit of 1000 exceeded."
@mock_route53 @mock_route53
@ -1448,8 +1425,8 @@ def test_list_resource_recordset_pagination():
) )
zones = conn.list_hosted_zones_by_name(DNSName="db.") zones = conn.list_hosted_zones_by_name(DNSName="db.")
len(zones["HostedZones"]).should.equal(1) assert len(zones["HostedZones"]) == 1
zones["HostedZones"][0]["Name"].should.equal("db.") assert zones["HostedZones"][0]["Name"] == "db."
hosted_zone_id = zones["HostedZones"][0]["Id"] hosted_zone_id = zones["HostedZones"][0]["Id"]
# Create A Record. # Create A Record.
@ -1475,33 +1452,33 @@ def test_list_resource_recordset_pagination():
response = conn.list_resource_record_sets( response = conn.list_resource_record_sets(
HostedZoneId=hosted_zone_id, MaxItems="100" HostedZoneId=hosted_zone_id, MaxItems="100"
) )
response.should.have.key("ResourceRecordSets").length_of(100) assert len(response["ResourceRecordSets"]) == 100
response.should.have.key("IsTruncated").equals(True) assert response["IsTruncated"]
response.should.have.key("MaxItems").equals("100") assert response["MaxItems"] == "100"
response.should.have.key("NextRecordName").equals("env187.redis.db.") assert response["NextRecordName"] == "env187.redis.db."
response.should.have.key("NextRecordType").equals("A") assert response["NextRecordType"] == "A"
response = conn.list_resource_record_sets( response = conn.list_resource_record_sets(
HostedZoneId=hosted_zone_id, HostedZoneId=hosted_zone_id,
StartRecordName=response["NextRecordName"], StartRecordName=response["NextRecordName"],
StartRecordType=response["NextRecordType"], StartRecordType=response["NextRecordType"],
) )
response.should.have.key("ResourceRecordSets").length_of(300) assert len(response["ResourceRecordSets"]) == 300
response.should.have.key("IsTruncated").equals(True) assert response["IsTruncated"] is True
response.should.have.key("MaxItems").equals("300") assert response["MaxItems"] == "300"
response.should.have.key("NextRecordName").equals("env457.redis.db.") assert response["NextRecordName"] == "env457.redis.db."
response.should.have.key("NextRecordType").equals("A") assert response["NextRecordType"] == "A"
response = conn.list_resource_record_sets( response = conn.list_resource_record_sets(
HostedZoneId=hosted_zone_id, HostedZoneId=hosted_zone_id,
StartRecordName=response["NextRecordName"], StartRecordName=response["NextRecordName"],
StartRecordType=response["NextRecordType"], StartRecordType=response["NextRecordType"],
) )
response.should.have.key("ResourceRecordSets").length_of(102) assert len(response["ResourceRecordSets"]) == 102
response.should.have.key("IsTruncated").equals(False) assert response["IsTruncated"] is False
response.should.have.key("MaxItems").equals("300") assert response["MaxItems"] == "300"
response.shouldnt.have.key("NextRecordName") assert "NextRecordName" not in response
response.shouldnt.have.key("NextRecordType") assert "NextRecordType" not in response
@mock_route53 @mock_route53
@ -1512,4 +1489,4 @@ def test_get_dns_sec():
Name="testdns.aws.com.", CallerReference=str(hash("foo")) Name="testdns.aws.com.", CallerReference=str(hash("foo"))
)["HostedZone"]["Id"] )["HostedZone"]["Id"]
dns_sec = client.get_dnssec(HostedZoneId=hosted_zone_id) dns_sec = client.get_dnssec(HostedZoneId=hosted_zone_id)
dns_sec.should.have.key("Status").equals({"ServeSignature": "NOT_SIGNING"}) assert dns_sec["Status"] == {"ServeSignature": "NOT_SIGNING"}

View File

@ -1,6 +1,5 @@
import boto3 import boto3
import json import json
import sure # noqa # pylint: disable=unused-import
from copy import deepcopy from copy import deepcopy
from moto import mock_cloudformation, mock_ec2, mock_route53 from moto import mock_cloudformation, mock_ec2, mock_route53
@ -55,8 +54,8 @@ def test_create_stack_hosted_zone_by_id():
# then a hosted zone should exist # then a hosted zone should exist
zone = conn.list_hosted_zones()["HostedZones"][0] zone = conn.list_hosted_zones()["HostedZones"][0]
zone.should.have.key("Name").equal("foo.bar.baz") assert zone["Name"] == "foo.bar.baz"
zone.should.have.key("ResourceRecordSetCount").equal(2) assert zone["ResourceRecordSetCount"] == 2
# when adding a record set to this zone # when adding a record set to this zone
cf_conn.create_stack( cf_conn.create_stack(
@ -67,9 +66,9 @@ def test_create_stack_hosted_zone_by_id():
# then the hosted zone should have a record # then the hosted zone should have a record
updated_zone = conn.list_hosted_zones()["HostedZones"][0] updated_zone = conn.list_hosted_zones()["HostedZones"][0]
updated_zone.should.have.key("Id").equal(zone["Id"]) assert updated_zone["Id"] == zone["Id"]
updated_zone.should.have.key("Name").equal("foo.bar.baz") assert updated_zone["Name"] == "foo.bar.baz"
updated_zone.should.have.key("ResourceRecordSetCount").equal(3) assert updated_zone["ResourceRecordSetCount"] == 3
@mock_cloudformation @mock_cloudformation
@ -82,33 +81,33 @@ def test_route53_roundrobin():
cf.create_stack(StackName="test_stack", TemplateBody=template_json) cf.create_stack(StackName="test_stack", TemplateBody=template_json)
zones = route53.list_hosted_zones()["HostedZones"] zones = route53.list_hosted_zones()["HostedZones"]
zones.should.have.length_of(1) assert len(zones) == 1
zone_id = zones[0]["Id"].split("/")[2] zone_id = zones[0]["Id"].split("/")[2]
rrsets = route53.list_resource_record_sets(HostedZoneId=zone_id)[ rrsets = route53.list_resource_record_sets(HostedZoneId=zone_id)[
"ResourceRecordSets" "ResourceRecordSets"
] ]
rrsets.should.have.length_of(4) assert len(rrsets) == 4
record_set1 = rrsets[2] record_set1 = rrsets[2]
record_set1["Name"].should.equal("test_stack.us-west-1.my_zone.") assert record_set1["Name"] == "test_stack.us-west-1.my_zone."
record_set1["SetIdentifier"].should.equal("test_stack AWS") assert record_set1["SetIdentifier"] == "test_stack AWS"
record_set1["Type"].should.equal("CNAME") assert record_set1["Type"] == "CNAME"
record_set1["TTL"].should.equal(900) assert record_set1["TTL"] == 900
record_set1["Weight"].should.equal(3) assert record_set1["Weight"] == 3
record_set1["ResourceRecords"][0]["Value"].should.equal("aws.amazon.com") assert record_set1["ResourceRecords"][0]["Value"] == "aws.amazon.com"
record_set2 = rrsets[3] record_set2 = rrsets[3]
record_set2["Name"].should.equal("test_stack.us-west-1.my_zone.") assert record_set2["Name"] == "test_stack.us-west-1.my_zone."
record_set2["SetIdentifier"].should.equal("test_stack Amazon") assert record_set2["SetIdentifier"] == "test_stack Amazon"
record_set2["Type"].should.equal("CNAME") assert record_set2["Type"] == "CNAME"
record_set2["TTL"].should.equal(900) assert record_set2["TTL"] == 900
record_set2["Weight"].should.equal(1) assert record_set2["Weight"] == 1
record_set2["ResourceRecords"][0]["Value"].should.equal("www.amazon.com") assert record_set2["ResourceRecords"][0]["Value"] == "www.amazon.com"
stack = cf.describe_stacks(StackName="test_stack")["Stacks"][0] stack = cf.describe_stacks(StackName="test_stack")["Stacks"][0]
output = stack["Outputs"][0] output = stack["Outputs"][0]
output["OutputKey"].should.equal("DomainName") assert output["OutputKey"] == "DomainName"
output["OutputValue"].should.equal(f"arn:aws:route53:::hostedzone/{zone_id}") assert output["OutputValue"] == f"arn:aws:route53:::hostedzone/{zone_id}"
@mock_cloudformation @mock_cloudformation
@ -127,21 +126,21 @@ def test_route53_ec2_instance_with_public_ip():
] ]
zones = route53.list_hosted_zones()["HostedZones"] zones = route53.list_hosted_zones()["HostedZones"]
zones.should.have.length_of(1) assert len(zones) == 1
zone_id = zones[0]["Id"].split("/")[2] zone_id = zones[0]["Id"].split("/")[2]
rrsets = route53.list_resource_record_sets(HostedZoneId=zone_id)[ rrsets = route53.list_resource_record_sets(HostedZoneId=zone_id)[
"ResourceRecordSets" "ResourceRecordSets"
] ]
rrsets.should.have.length_of(3) assert len(rrsets) == 3
record_set = rrsets[2] record_set = rrsets[2]
record_set["Name"].should.equal(f"{instance_id}.us-west-1.my_zone.") assert record_set["Name"] == f"{instance_id}.us-west-1.my_zone."
record_set.shouldnt.have.key("SetIdentifier") assert record_set["Type"] == "A"
record_set["Type"].should.equal("A") assert record_set["TTL"] == 900
record_set["TTL"].should.equal(900) assert record_set["ResourceRecords"][0]["Value"] == "10.0.0.25"
record_set.shouldnt.have.key("Weight") assert "SetIdentifier" not in record_set
record_set["ResourceRecords"][0]["Value"].should.equal("10.0.0.25") assert "Weight" not in record_set
@mock_cloudformation @mock_cloudformation
@ -154,27 +153,27 @@ def test_route53_associate_health_check():
cf.create_stack(StackName="test_stack", TemplateBody=template_json) cf.create_stack(StackName="test_stack", TemplateBody=template_json)
checks = route53.list_health_checks()["HealthChecks"] checks = route53.list_health_checks()["HealthChecks"]
checks.should.have.length_of(1) assert len(checks) == 1
check = checks[0] check = checks[0]
health_check_id = check["Id"] health_check_id = check["Id"]
config = check["HealthCheckConfig"] config = check["HealthCheckConfig"]
config["FailureThreshold"].should.equal(3) assert config["FailureThreshold"] == 3
config["IPAddress"].should.equal("10.0.0.4") assert config["IPAddress"] == "10.0.0.4"
config["Port"].should.equal(80) assert config["Port"] == 80
config["RequestInterval"].should.equal(10) assert config["RequestInterval"] == 10
config["ResourcePath"].should.equal("/") assert config["ResourcePath"] == "/"
config["Type"].should.equal("HTTP") assert config["Type"] == "HTTP"
zones = route53.list_hosted_zones()["HostedZones"] zones = route53.list_hosted_zones()["HostedZones"]
zones.should.have.length_of(1) assert len(zones) == 1
zone_id = zones[0]["Id"].split("/")[2] zone_id = zones[0]["Id"].split("/")[2]
rrsets = route53.list_resource_record_sets(HostedZoneId=zone_id)[ rrsets = route53.list_resource_record_sets(HostedZoneId=zone_id)[
"ResourceRecordSets" "ResourceRecordSets"
] ]
rrsets.should.have.length_of(3) assert len(rrsets) == 3
record_set = rrsets[0] record_set = rrsets[0]
record_set["HealthCheckId"].should.equal(health_check_id) assert record_set["HealthCheckId"] == health_check_id
@mock_cloudformation @mock_cloudformation
@ -187,7 +186,7 @@ def test_route53_with_update():
cf.create_stack(StackName="test_stack", TemplateBody=template_json) cf.create_stack(StackName="test_stack", TemplateBody=template_json)
zones = route53.list_hosted_zones()["HostedZones"] zones = route53.list_hosted_zones()["HostedZones"]
zones.should.have.length_of(1) assert len(zones) == 1
zone_id = zones[0]["Id"] zone_id = zones[0]["Id"]
zone_id = zone_id.split("/") zone_id = zone_id.split("/")
zone_id = zone_id[2] zone_id = zone_id[2]
@ -195,10 +194,10 @@ def test_route53_with_update():
rrsets = route53.list_resource_record_sets(HostedZoneId=zone_id)[ rrsets = route53.list_resource_record_sets(HostedZoneId=zone_id)[
"ResourceRecordSets" "ResourceRecordSets"
] ]
rrsets.should.have.length_of(3) assert len(rrsets) == 3
record_set = rrsets[0] record_set = rrsets[0]
record_set["ResourceRecords"][0]["Value"].should.equal("my.example.com") assert record_set["ResourceRecords"][0]["Value"] == "my.example.com"
# # given # # given
template = deepcopy(route53_health_check.template) template = deepcopy(route53_health_check.template)
@ -212,22 +211,21 @@ def test_route53_with_update():
# # then # # then
zones = route53.list_hosted_zones()["HostedZones"] zones = route53.list_hosted_zones()["HostedZones"]
zones.should.have.length_of(1) assert len(zones) == 1
zone_id = zones[0]["Id"].split("/")[2] zone_id = zones[0]["Id"].split("/")[2]
rrsets = route53.list_resource_record_sets(HostedZoneId=zone_id)[ rrsets = route53.list_resource_record_sets(HostedZoneId=zone_id)[
"ResourceRecordSets" "ResourceRecordSets"
] ]
rrsets.should.have.length_of(3) assert len(rrsets) == 3
record_set = rrsets[0] record_set = rrsets[0]
record_set["ResourceRecords"][0]["Value"].should.equal("my_other.example.com") assert record_set["ResourceRecords"][0]["Value"] == "my_other.example.com"
@mock_cloudformation @mock_cloudformation
@mock_route53 @mock_route53
def test_delete_route53_recordset(): def test_delete_route53_recordset():
cf = boto3.client("cloudformation", region_name="us-west-1") cf = boto3.client("cloudformation", region_name="us-west-1")
# given a stack with a record set # given a stack with a record set

View File

@ -10,8 +10,8 @@ def test_list_reusable_delegation_set():
client = boto3.client("route53", region_name="us-east-1") client = boto3.client("route53", region_name="us-east-1")
resp = client.list_reusable_delegation_sets() resp = client.list_reusable_delegation_sets()
resp.should.have.key("DelegationSets").equals([]) assert resp["DelegationSets"] == []
resp.should.have.key("IsTruncated").equals(False) assert resp["IsTruncated"] is False
@mock_route53 @mock_route53
@ -20,13 +20,11 @@ def test_create_reusable_delegation_set():
resp = client.create_reusable_delegation_set(CallerReference="r3f3r3nc3") resp = client.create_reusable_delegation_set(CallerReference="r3f3r3nc3")
headers = resp["ResponseMetadata"]["HTTPHeaders"] headers = resp["ResponseMetadata"]["HTTPHeaders"]
headers.should.have.key("location") assert "location" in headers
resp.should.have.key("DelegationSet") assert "Id" in resp["DelegationSet"]
assert resp["DelegationSet"]["CallerReference"] == "r3f3r3nc3"
resp["DelegationSet"].should.have.key("Id") assert len(resp["DelegationSet"]["NameServers"]) == 4
resp["DelegationSet"].should.have.key("CallerReference").equals("r3f3r3nc3")
resp["DelegationSet"].should.have.key("NameServers").length_of(4)
@mock_route53 @mock_route53
@ -42,7 +40,7 @@ def test_create_reusable_delegation_set_from_hosted_zone():
CallerReference="r3f3r3nc3", HostedZoneId=hosted_zone_id CallerReference="r3f3r3nc3", HostedZoneId=hosted_zone_id
) )
set(resp["DelegationSet"]["NameServers"]).should.equal(hosted_zone_name_servers) assert set(resp["DelegationSet"]["NameServers"]) == hosted_zone_name_servers
@mock_route53 @mock_route53
@ -54,9 +52,7 @@ def test_create_reusable_delegation_set_from_hosted_zone_with_delegationsetid():
DelegationSetId="customdelegationsetid", DelegationSetId="customdelegationsetid",
) )
response.should.have.key("DelegationSet") assert response["DelegationSet"]["Id"] == "customdelegationsetid"
response["DelegationSet"].should.have.key("Id").equals("customdelegationsetid")
response["DelegationSet"].should.have.key("NameServers")
hosted_zone_id = response["HostedZone"]["Id"] hosted_zone_id = response["HostedZone"]["Id"]
hosted_zone_name_servers = set(response["DelegationSet"]["NameServers"]) hosted_zone_name_servers = set(response["DelegationSet"]["NameServers"])
@ -65,8 +61,8 @@ def test_create_reusable_delegation_set_from_hosted_zone_with_delegationsetid():
CallerReference="r3f3r3nc3", HostedZoneId=hosted_zone_id CallerReference="r3f3r3nc3", HostedZoneId=hosted_zone_id
) )
resp["DelegationSet"].should.have.key("Id").shouldnt.equal("customdelegationsetid") assert resp["DelegationSet"]["Id"] != "customdelegationsetid"
set(resp["DelegationSet"]["NameServers"]).should.equal(hosted_zone_name_servers) assert set(resp["DelegationSet"]["NameServers"]) == hosted_zone_name_servers
@mock_route53 @mock_route53
@ -78,11 +74,11 @@ def test_get_reusable_delegation_set():
resp = client.get_reusable_delegation_set(Id=ds_id) resp = client.get_reusable_delegation_set(Id=ds_id)
resp.should.have.key("DelegationSet") assert "DelegationSet" in resp
resp["DelegationSet"].should.have.key("Id").equals(ds_id) assert resp["DelegationSet"]["Id"] == ds_id
resp["DelegationSet"].should.have.key("CallerReference").equals("r3f3r3nc3") assert resp["DelegationSet"]["CallerReference"] == "r3f3r3nc3"
resp["DelegationSet"].should.have.key("NameServers").length_of(4) assert len(resp["DelegationSet"]["NameServers"]) == 4
@mock_route53 @mock_route53
@ -92,8 +88,8 @@ def test_get_reusable_delegation_set_unknown():
with pytest.raises(ClientError) as exc: with pytest.raises(ClientError) as exc:
client.get_reusable_delegation_set(Id="unknown") client.get_reusable_delegation_set(Id="unknown")
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("NoSuchDelegationSet") assert err["Code"] == "NoSuchDelegationSet"
err["Message"].should.equal("unknown") assert err["Message"] == "unknown"
@mock_route53 @mock_route53
@ -103,8 +99,8 @@ def test_list_reusable_delegation_sets():
client.create_reusable_delegation_set(CallerReference="r3f3r3nc4") client.create_reusable_delegation_set(CallerReference="r3f3r3nc4")
resp = client.list_reusable_delegation_sets() resp = client.list_reusable_delegation_sets()
resp.should.have.key("DelegationSets").length_of(2) assert len(resp["DelegationSets"]) == 2
resp.should.have.key("IsTruncated").equals(False) assert resp["IsTruncated"] is False
@mock_route53 @mock_route53
@ -116,4 +112,4 @@ def test_delete_reusable_delegation_set():
client.delete_reusable_delegation_set(Id=ds_id) client.delete_reusable_delegation_set(Id=ds_id)
client.list_reusable_delegation_sets()["DelegationSets"].should.have.length_of(0) assert len(client.list_reusable_delegation_sets()["DelegationSets"]) == 0

View File

@ -1,6 +1,5 @@
import boto3 import boto3
import pytest import pytest
import sure # noqa # pylint: disable=unused-import
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
from moto import mock_route53 from moto import mock_route53
@ -21,30 +20,28 @@ def test_create_health_check():
"FailureThreshold": 2, "FailureThreshold": 2,
}, },
) )
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(201) assert response["ResponseMetadata"]["HTTPStatusCode"] == 201
# #
check = response["HealthCheck"] check = response["HealthCheck"]
check.should.have.key("Id") assert "Id" in check
check.should.have.key("CallerReference").being.equal( assert check["CallerReference"] == "test-route53-health-HealthCheck-asdf"
"test-route53-health-HealthCheck-asdf" assert "HealthCheckConfig" in check
)
check.should.have.key("HealthCheckConfig")
# #
config = check["HealthCheckConfig"] config = check["HealthCheckConfig"]
config.should.have.key("IPAddress").being.equal("93.184.216.34") assert config["IPAddress"] == "93.184.216.34"
config.should.have.key("Port").being.equal(80) assert config["Port"] == 80
config.should.have.key("Type").being.equal("HTTP") assert config["Type"] == "HTTP"
config.should.have.key("ResourcePath").being.equal("/") assert config["ResourcePath"] == "/"
config.should.have.key("FullyQualifiedDomainName").being.equal("example.com") assert config["FullyQualifiedDomainName"] == "example.com"
config.should.have.key("RequestInterval").being.equal(10) assert config["RequestInterval"] == 10
config.should.have.key("FailureThreshold").being.equal(2) assert config["FailureThreshold"] == 2
config.should.have.key("MeasureLatency").being.equal(False) assert config["MeasureLatency"] is False
config.should.have.key("Inverted").being.equal(False) assert config["Inverted"] is False
config.should.have.key("Disabled").being.equal(False) assert config["Disabled"] is False
config.should.have.key("EnableSNI").being.equal(False) assert config["EnableSNI"] is False
config.shouldnt.have.key("ChildHealthChecks") assert "ChildHealthChecks" not in config
config.shouldnt.have.key("HealthThreshold") assert "HealthThreshold" not in config
@mock_route53 @mock_route53
@ -68,21 +65,19 @@ def test_create_health_check_with_additional_options():
"EnableSNI": True, "EnableSNI": True,
}, },
) )
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(201) assert response["ResponseMetadata"]["HTTPStatusCode"] == 201
# #
check = response["HealthCheck"] check = response["HealthCheck"]
check.should.have.key("CallerReference").being.equal( assert check["CallerReference"] == "test-route53-health-HealthCheck-asdf"
"test-route53-health-HealthCheck-asdf" assert check["HealthCheckVersion"] == 1
) assert "HealthCheckConfig" in check
check.should.have.key("HealthCheckVersion").equal(1)
check.should.have.key("HealthCheckConfig")
# #
config = check["HealthCheckConfig"] config = check["HealthCheckConfig"]
check["HealthCheckConfig"].should.have.key("SearchString").equal("a good response") assert check["HealthCheckConfig"]["SearchString"] == "a good response"
config.should.have.key("MeasureLatency").being.equal(True) assert config["MeasureLatency"] is True
config.should.have.key("Inverted").being.equal(True) assert config["Inverted"] is True
config.should.have.key("Disabled").being.equal(True) assert config["Disabled"] is True
config.should.have.key("EnableSNI").being.equal(True) assert config["EnableSNI"] is True
@mock_route53 @mock_route53
@ -100,24 +95,22 @@ def test_create_calculated_health_check():
) )
check = response["HealthCheck"] check = response["HealthCheck"]
check.should.have.key("Id") assert "Id" in check
check.should.have.key("CallerReference").being.equal( assert check["CallerReference"] == "test-route53-health-HealthCheck-ZHV123"
"test-route53-health-HealthCheck-ZHV123"
)
# #
config = check["HealthCheckConfig"] config = check["HealthCheckConfig"]
config.should.have.key("Type").being.equal("CALCULATED") assert config["Type"] == "CALCULATED"
config.should.have.key("Inverted").being.equal(False) assert config["Inverted"] is False
config.should.have.key("Disabled").being.equal(False) assert config["Disabled"] is False
config.should.have.key("HealthThreshold").being.equal(1) assert config["HealthThreshold"] == 1
# #
config.shouldnt.have.key("IPAddress") assert "IPAddress" not in config
config.shouldnt.have.key("Port") assert "Port" not in config
config.shouldnt.have.key("ResourcePath") assert "ResourcePath" not in config
config.shouldnt.have.key("FullyQualifiedDomainName") assert "FullyQualifiedDomainName" not in config
config.shouldnt.have.key("RequestInterval") assert "RequestInterval" not in config
config.shouldnt.have.key("FailureThreshold") assert "FailureThreshold" not in config
config.shouldnt.have.key("MeasureLatency") assert "MeasureLatency" not in config
@mock_route53 @mock_route53
@ -159,19 +152,18 @@ def test_create_calculated_health_check_with_children():
) )
check = parent["HealthCheck"] check = parent["HealthCheck"]
check.should.have.key("Id") assert "Id" in check
check.should.have.key("CallerReference").being.equal( assert check["CallerReference"] == "test-route53-health-HealthCheck-parent"
"test-route53-health-HealthCheck-parent"
)
# #
config = check["HealthCheckConfig"] config = check["HealthCheckConfig"]
config.should.have.key("Type").being.equal("CALCULATED") assert config["Type"] == "CALCULATED"
config.should.have.key("Inverted").being.equal(False) assert config["Inverted"] is False
config.should.have.key("Disabled").being.equal(False) assert config["Disabled"] is False
config.should.have.key("HealthThreshold").being.equal(1) assert config["HealthThreshold"] == 1
config.should.have.key("ChildHealthChecks").being.equal( assert config["ChildHealthChecks"] == [
[child1["HealthCheck"]["Id"], child2["HealthCheck"]["Id"]] child1["HealthCheck"]["Id"],
) child2["HealthCheck"]["Id"],
]
@mock_route53 @mock_route53
@ -189,9 +181,9 @@ def test_get_health_check():
)["HealthCheck"]["Id"] )["HealthCheck"]["Id"]
resp = client.get_health_check(HealthCheckId=hc_id)["HealthCheck"] resp = client.get_health_check(HealthCheckId=hc_id)["HealthCheck"]
resp.should.have.key("Id").equals(hc_id) assert resp["Id"] == hc_id
resp.should.have.key("CallerReference").equals("callref") assert resp["CallerReference"] == "callref"
resp.should.have.key("HealthCheckVersion").equals(1) assert resp["HealthCheckVersion"] == 1
@mock_route53 @mock_route53
@ -201,15 +193,15 @@ def test_get_unknown_health_check():
with pytest.raises(ClientError) as exc: with pytest.raises(ClientError) as exc:
client.get_health_check(HealthCheckId="unknown") client.get_health_check(HealthCheckId="unknown")
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("NoSuchHealthCheck") assert err["Code"] == "NoSuchHealthCheck"
err["Message"].should.equal("A health check with id unknown does not exist.") assert err["Message"] == "A health check with id unknown does not exist."
@mock_route53 @mock_route53
def test_list_health_checks(): def test_list_health_checks():
conn = boto3.client("route53", region_name="us-east-1") conn = boto3.client("route53", region_name="us-east-1")
conn.list_health_checks()["HealthChecks"].should.have.length_of(0) assert len(conn.list_health_checks()["HealthChecks"]) == 0
check = conn.create_health_check( check = conn.create_health_check(
CallerReference="?", CallerReference="?",
@ -225,16 +217,14 @@ def test_list_health_checks():
}, },
)["HealthCheck"] )["HealthCheck"]
checks = conn.list_health_checks()["HealthChecks"] assert conn.list_health_checks()["HealthChecks"] == [check]
checks.should.have.length_of(1)
checks.should.contain(check)
@mock_route53 @mock_route53
def test_delete_health_checks(): def test_delete_health_checks():
conn = boto3.client("route53", region_name="us-east-1") conn = boto3.client("route53", region_name="us-east-1")
conn.list_health_checks()["HealthChecks"].should.have.length_of(0) assert len(conn.list_health_checks()["HealthChecks"]) == 0
check = conn.create_health_check( check = conn.create_health_check(
CallerReference="?", CallerReference="?",
@ -253,7 +243,7 @@ def test_delete_health_checks():
conn.delete_health_check(HealthCheckId=check["Id"]) conn.delete_health_check(HealthCheckId=check["Id"])
checks = conn.list_health_checks()["HealthChecks"] checks = conn.list_health_checks()["HealthChecks"]
checks.should.have.length_of(0) assert len(checks) == 0
@mock_route53 @mock_route53
@ -288,14 +278,14 @@ def test_update_health_check():
config = client.get_health_check(HealthCheckId=hc_id)["HealthCheck"][ config = client.get_health_check(HealthCheckId=hc_id)["HealthCheck"][
"HealthCheckConfig" "HealthCheckConfig"
] ]
config.should.have.key("Type").equals("CALCULATED") assert config["Type"] == "CALCULATED"
config.should.have.key("ResourcePath").equals("rp") assert config["ResourcePath"] == "rp"
config.should.have.key("FullyQualifiedDomainName").equals("example.com") assert config["FullyQualifiedDomainName"] == "example.com"
config.should.have.key("SearchString").equals("search") assert config["SearchString"] == "search"
config.should.have.key("Inverted").equals(False) assert config["Inverted"] is False
config.should.have.key("Disabled").equals(False) assert config["Disabled"] is False
config.should.have.key("ChildHealthChecks").equals(["child"]) assert config["ChildHealthChecks"] == ["child"]
config.should.have.key("Regions").equals(["us-east-1", "us-east-2", "us-west-1"]) assert config["Regions"] == ["us-east-1", "us-east-2", "us-west-1"]
@mock_route53 @mock_route53
@ -313,19 +303,20 @@ def test_health_check_status():
)["HealthCheck"]["Id"] )["HealthCheck"]["Id"]
resp = client.get_health_check_status(HealthCheckId=hc_id) resp = client.get_health_check_status(HealthCheckId=hc_id)
resp["HealthCheckObservations"].should.have.length_of(1) assert len(resp["HealthCheckObservations"]) == 1
observation = resp["HealthCheckObservations"][0] observation = resp["HealthCheckObservations"][0]
observation.should.have.key("Region").being.equals("us-east-1") assert observation["Region"] == "us-east-1"
observation.should.have.key("IPAddress").being.equals("127.0.13.37") assert observation["IPAddress"] == "127.0.13.37"
observation.should.have.key("StatusReport") assert "StatusReport" in observation
observation["StatusReport"].should.have.key("Status").being.equals( assert (
"Success: HTTP Status Code: 200. Resolved IP: 127.0.13.37. OK" observation["StatusReport"]["Status"]
== "Success: HTTP Status Code: 200. Resolved IP: 127.0.13.37. OK"
) )
with pytest.raises(ClientError) as exc: with pytest.raises(ClientError) as exc:
client.get_health_check_status(HealthCheckId="bad-id") client.get_health_check_status(HealthCheckId="bad-id")
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("NoSuchHealthCheck") assert err["Code"] == "NoSuchHealthCheck"
err["Message"].should.equal("A health check with id bad-id does not exist.") assert err["Message"] == "A health check with id bad-id does not exist."

View File

@ -1,5 +1,4 @@
import boto3 import boto3
import sure # noqa # pylint: disable=unused-import
import pytest import pytest
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
@ -25,20 +24,18 @@ def test_hosted_zone_private_zone_preserved():
zone_id = new_zone["HostedZone"]["Id"].split("/")[-1] zone_id = new_zone["HostedZone"]["Id"].split("/")[-1]
hosted_zone = conn.get_hosted_zone(Id=zone_id) hosted_zone = conn.get_hosted_zone(Id=zone_id)
hosted_zone["HostedZone"]["Config"]["PrivateZone"].should.equal(True) assert hosted_zone["HostedZone"]["Config"]["PrivateZone"]
hosted_zone.should.have.key("VPCs")
hosted_zone["VPCs"].should.have.length_of(1) assert len(hosted_zone["VPCs"]) == 1
hosted_zone["VPCs"][0].should.have.key("VPCId") assert hosted_zone["VPCs"][0]["VPCId"] == vpc_id
hosted_zone["VPCs"][0].should.have.key("VPCRegion") assert hosted_zone["VPCs"][0]["VPCRegion"] == region
hosted_zone["VPCs"][0]["VPCId"].should.be.equal(vpc_id)
hosted_zone["VPCs"][0]["VPCRegion"].should.be.equal(region)
hosted_zones = conn.list_hosted_zones() hosted_zones = conn.list_hosted_zones()
hosted_zones["HostedZones"][0]["Config"]["PrivateZone"].should.equal(True) assert hosted_zones["HostedZones"][0]["Config"]["PrivateZone"]
hosted_zones = conn.list_hosted_zones_by_name(DNSName="testdns.aws.com.") hosted_zones = conn.list_hosted_zones_by_name(DNSName="testdns.aws.com.")
hosted_zones["HostedZones"].should.have.length_of(1) assert len(hosted_zones["HostedZones"]) == 1
hosted_zones["HostedZones"][0]["Config"]["PrivateZone"].should.equal(True) assert hosted_zones["HostedZones"][0]["Config"]["PrivateZone"]
# create_hosted_zone statements with PrivateZone=True, # create_hosted_zone statements with PrivateZone=True,
# but without a _valid_ vpc-id should NOT fail. # but without a _valid_ vpc-id should NOT fail.
@ -51,19 +48,19 @@ def test_hosted_zone_private_zone_preserved():
zone_id = no_vpc_zone["HostedZone"]["Id"].split("/")[-1] zone_id = no_vpc_zone["HostedZone"]["Id"].split("/")[-1]
hosted_zone = conn.get_hosted_zone(Id=zone_id) hosted_zone = conn.get_hosted_zone(Id=zone_id)
hosted_zone["HostedZone"]["Config"]["PrivateZone"].should.equal(True) assert hosted_zone["HostedZone"]["Config"]["PrivateZone"]
hosted_zone.should.have.key("VPCs")
hosted_zone["VPCs"].should.have.length_of(0) assert len(hosted_zone["VPCs"]) == 0
hosted_zones = conn.list_hosted_zones() hosted_zones = conn.list_hosted_zones()
hosted_zones["HostedZones"].should.have.length_of(2) assert len(hosted_zones["HostedZones"]) == 2
hosted_zones["HostedZones"][0]["Config"]["PrivateZone"].should.equal(True) assert hosted_zones["HostedZones"][0]["Config"]["PrivateZone"]
hosted_zones["HostedZones"][1]["Config"]["PrivateZone"].should.equal(True) assert hosted_zones["HostedZones"][1]["Config"]["PrivateZone"]
hosted_zones = conn.list_hosted_zones_by_name(DNSName=zone2_name) hosted_zones = conn.list_hosted_zones_by_name(DNSName=zone2_name)
hosted_zones["HostedZones"].should.have.length_of(1) assert len(hosted_zones["HostedZones"]) == 1
hosted_zones["HostedZones"][0]["Config"]["PrivateZone"].should.equal(True) assert hosted_zones["HostedZones"][0]["Config"]["PrivateZone"]
hosted_zones["HostedZones"][0]["Name"].should.equal(zone2_name) assert hosted_zones["HostedZones"][0]["Name"] == zone2_name
@mock_ec2 @mock_ec2
@ -88,19 +85,15 @@ def test_list_hosted_zones_by_vpc_with_multiple_vpcs():
# List the zones associated with this vpc # List the zones associated with this vpc
response = conn.list_hosted_zones_by_vpc(VPCId=vpc_id, VPCRegion=region) response = conn.list_hosted_zones_by_vpc(VPCId=vpc_id, VPCRegion=region)
response.should.have.key("ResponseMetadata") assert len(response["HostedZoneSummaries"]) == 3
response.should.have.key("HostedZoneSummaries")
response["HostedZoneSummaries"].should.have.length_of(3)
# Loop through all zone summaries and verify they match what was created # Loop through all zone summaries and verify they match what was created
for summary in response["HostedZoneSummaries"]: for summary in response["HostedZoneSummaries"]:
# use the zone name as the index # use the zone name as the index
index = summary["Name"].split(".")[1] index = summary["Name"].split(".")[1]
zone_id = zones[index]["HostedZone"]["Id"].split("/")[2] zone_id = zones[index]["HostedZone"]["Id"].split("/")[2]
summary.should.have.key("HostedZoneId") assert summary["HostedZoneId"] == zone_id
summary["HostedZoneId"].should.equal(zone_id) assert summary["Name"] == zones[index]["HostedZone"]["Name"]
summary.should.have.key("Name")
summary["Name"].should.equal(zones[index]["HostedZone"]["Name"])
@mock_ec2 @mock_ec2
@ -121,13 +114,10 @@ def test_list_hosted_zones_by_vpc():
zone_id = zone_b["HostedZone"]["Id"].split("/")[2] zone_id = zone_b["HostedZone"]["Id"].split("/")[2]
response = conn.list_hosted_zones_by_vpc(VPCId=vpc_id, VPCRegion=region) response = conn.list_hosted_zones_by_vpc(VPCId=vpc_id, VPCRegion=region)
response.should.have.key("ResponseMetadata") assert len(response["HostedZoneSummaries"]) == 1
response.should.have.key("HostedZoneSummaries") returned_zone = response["HostedZoneSummaries"][0]
response["HostedZoneSummaries"].should.have.length_of(1) assert returned_zone["HostedZoneId"] == zone_id
response["HostedZoneSummaries"][0].should.have.key("HostedZoneId") assert returned_zone["Name"] == zone_b["HostedZone"]["Name"]
retured_zone = response["HostedZoneSummaries"][0]
retured_zone["HostedZoneId"].should.equal(zone_id)
retured_zone["Name"].should.equal(zone_b["HostedZone"]["Name"])
@mock_ec2 @mock_ec2
@ -148,8 +138,7 @@ def test_route53_associate_vpc():
VPC={"VPCId": vpc_id, "VPCRegion": "us-east-1"}, VPC={"VPCId": vpc_id, "VPCRegion": "us-east-1"},
Comment="yolo", Comment="yolo",
) )
resp.should.have.key("ChangeInfo") assert resp["ChangeInfo"]["Comment"] == "yolo"
resp["ChangeInfo"].should.have.key("Comment").equals("yolo")
@mock_ec2 @mock_ec2
@ -171,9 +160,10 @@ def test_route53_associate_vpc_with_public_Zone():
Comment="yolo", Comment="yolo",
) )
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("PublicZoneVPCAssociation") assert err["Code"] == "PublicZoneVPCAssociation"
err["Message"].should.equal( assert (
"You're trying to associate a VPC with a public hosted zone. Amazon Route 53 doesn't support associating a VPC with a public hosted zone." err["Message"]
== "You're trying to associate a VPC with a public hosted zone. Amazon Route 53 doesn't support associating a VPC with a public hosted zone."
) )
@ -200,15 +190,15 @@ def test_route53_associate_and_disassociate_vpc():
) )
zone_vpcs = conn.get_hosted_zone(Id=zone_id)["VPCs"] zone_vpcs = conn.get_hosted_zone(Id=zone_id)["VPCs"]
zone_vpcs.should.have.length_of(2) assert len(zone_vpcs) == 2
zone_vpcs.should.contain({"VPCRegion": region, "VPCId": vpc_id1}) assert {"VPCRegion": region, "VPCId": vpc_id1} in zone_vpcs
zone_vpcs.should.contain({"VPCRegion": region, "VPCId": vpc_id2}) assert {"VPCRegion": region, "VPCId": vpc_id2} in zone_vpcs
conn.disassociate_vpc_from_hosted_zone(HostedZoneId=zone_id, VPC={"VPCId": vpc_id1}) conn.disassociate_vpc_from_hosted_zone(HostedZoneId=zone_id, VPC={"VPCId": vpc_id1})
zone_vpcs = conn.get_hosted_zone(Id=zone_id)["VPCs"] zone_vpcs = conn.get_hosted_zone(Id=zone_id)["VPCs"]
zone_vpcs.should.have.length_of(1) assert len(zone_vpcs) == 1
zone_vpcs.should.contain({"VPCRegion": region, "VPCId": vpc_id2}) assert {"VPCRegion": region, "VPCId": vpc_id2} in zone_vpcs
@mock_ec2 @mock_ec2
@ -230,7 +220,8 @@ def test_route53_disassociate_last_vpc():
HostedZoneId=zone_id, VPC={"VPCId": vpc_id} HostedZoneId=zone_id, VPC={"VPCId": vpc_id}
) )
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("LastVPCAssociation") assert err["Code"] == "LastVPCAssociation"
err["Message"].should.equal( assert (
"The VPC that you're trying to disassociate from the private hosted zone is the last VPC that is associated with the hosted zone. Amazon Route 53 doesn't support disassociating the last VPC from a hosted zone." err["Message"]
== "The VPC that you're trying to disassociate from the private hosted zone is the last VPC that is associated with the hosted zone. Amazon Route 53 doesn't support disassociating the last VPC from a hosted zone."
) )

View File

@ -1,4 +1,3 @@
import sure # noqa # pylint: disable=unused-import
import xmltodict import xmltodict
import moto.server as server import moto.server as server
@ -22,7 +21,7 @@ def test_list_recordset():
# list record set # list record set
res = test_client.get(f"2013-04-01/hostedzone/{zone_id}/rrset") res = test_client.get(f"2013-04-01/hostedzone/{zone_id}/rrset")
# Ampersand should be properly encoded # Ampersand should be properly encoded
res.data.decode("utf-8").should.contain("<Value><![CDATA[val&sth]]></Value>") assert "<Value><![CDATA[val&sth]]></Value>" in res.data.decode("utf-8")
def parse_xml(body): def parse_xml(body):

View File

@ -858,20 +858,20 @@ def test_associate_resolver_endpoint_ip_address():
# create resolver # create resolver
random_num = mock_random.get_random_hex(10) random_num = mock_random.get_random_hex(10)
resolver = create_test_endpoint(client, ec2_client, name=f"A-{random_num}") resolver = create_test_endpoint(client, ec2_client, name=f"A-{random_num}")
resolver.should.have.key("IpAddressCount").equals(2) assert resolver["IpAddressCount"] == 2
# associate # associate
resp = client.associate_resolver_endpoint_ip_address( resp = client.associate_resolver_endpoint_ip_address(
IpAddress={"Ip": "10.0.2.126", "SubnetId": subnet["SubnetId"]}, IpAddress={"Ip": "10.0.2.126", "SubnetId": subnet["SubnetId"]},
ResolverEndpointId=resolver["Id"], ResolverEndpointId=resolver["Id"],
)["ResolverEndpoint"] )["ResolverEndpoint"]
resp.should.have.key("Id").equals(resolver["Id"]) assert resp["Id"] == resolver["Id"]
resp.should.have.key("IpAddressCount").equals(3) assert resp["IpAddressCount"] == 3
resp.should.have.key("SecurityGroupIds").should.have.length_of(1) assert len(resp["SecurityGroupIds"]) == 1
# verify ENI was created # verify ENI was created
enis = ec2_client.describe_network_interfaces()["NetworkInterfaces"] enis = ec2_client.describe_network_interfaces()["NetworkInterfaces"]
ip_addresses = [eni["PrivateIpAddress"] for eni in enis] ip_addresses = [eni["PrivateIpAddress"] for eni in enis]
ip_addresses.should.contain("10.0.2.126") assert "10.0.2.126" in ip_addresses
@mock_route53resolver @mock_route53resolver
@ -882,8 +882,8 @@ def test_associate_resolver_endpoint_ip_address__invalid_resolver():
IpAddress={"Ip": "notapplicable"}, ResolverEndpointId="unknown" IpAddress={"Ip": "notapplicable"}, ResolverEndpointId="unknown"
) )
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("ResourceNotFoundException") assert err["Code"] == "ResourceNotFoundException"
err["Message"].should.equal("Resolver endpoint with ID 'unknown' does not exist") assert err["Message"] == "Resolver endpoint with ID 'unknown' does not exist"
@mock_ec2 @mock_ec2
@ -912,7 +912,7 @@ def test_disassociate_resolver_endpoint_ip_address__using_ip():
) )
# One ENI was deleted # One ENI was deleted
enis_after = ec2_client.describe_network_interfaces()["NetworkInterfaces"] enis_after = ec2_client.describe_network_interfaces()["NetworkInterfaces"]
(len(enis_after) + 1).should.equal(len(enis_before)) assert (len(enis_after) + 1) == len(enis_before)
@mock_ec2 @mock_ec2
@ -943,7 +943,7 @@ def test_disassociate_resolver_endpoint_ip_address__using_ipid_and_subnet():
ResolverEndpointId=resolver["Id"], ResolverEndpointId=resolver["Id"],
IpAddress={"SubnetId": subnet_id, "IpId": ip_id}, IpAddress={"SubnetId": subnet_id, "IpId": ip_id},
)["ResolverEndpoint"] )["ResolverEndpoint"]
resp.should.have.key("IpAddressCount").equals(2) assert resp["IpAddressCount"] == 2
@mock_ec2 @mock_ec2
@ -970,7 +970,8 @@ def test_disassociate_resolver_endpoint_ip_address__using_subnet_alone():
ResolverEndpointId=resolver["Id"], IpAddress={"SubnetId": subnet_id} ResolverEndpointId=resolver["Id"], IpAddress={"SubnetId": subnet_id}
) )
err = exc.value.response["Error"] err = exc.value.response["Error"]
err["Code"].should.equal("InvalidRequestException") assert err["Code"] == "InvalidRequestException"
err["Message"].should.equal( assert (
"[RSLVR-00503] Need to specify either the IP ID or both subnet and IP address in order to remove IP address." err["Message"]
== "[RSLVR-00503] Need to specify either the IP ID or both subnet and IP address in order to remove IP address."
) )

View File

@ -1,9 +1,8 @@
"""Unit tests for route53resolver rule-related APIs.""" """Unit tests for route53resolver rule-related APIs."""
from botocore.exceptions import ClientError
from datetime import datetime, timezone from datetime import datetime, timezone
import boto3 import boto3
from botocore.exceptions import ClientError
import pytest import pytest
from moto import mock_route53resolver from moto import mock_route53resolver