diff --git a/moto/route53/models.py b/moto/route53/models.py
index cfa4d3273..52c6620ad 100644
--- a/moto/route53/models.py
+++ b/moto/route53/models.py
@@ -128,10 +128,10 @@ class RecordSet(CloudFormationModel):
def __init__(self, kwargs):
self.name = kwargs.get("Name")
self.type_ = kwargs.get("Type")
- self.ttl = kwargs.get("TTL")
+ self.ttl = kwargs.get("TTL", 0)
self.records = kwargs.get("ResourceRecords", [])
self.set_identifier = kwargs.get("SetIdentifier")
- self.weight = kwargs.get("Weight")
+ self.weight = kwargs.get("Weight", 0)
self.region = kwargs.get("Region")
self.health_check = kwargs.get("HealthCheckId")
self.hosted_zone_name = kwargs.get("HostedZoneName")
@@ -197,55 +197,6 @@ class RecordSet(CloudFormationModel):
def physical_resource_id(self):
return self.name
- def to_xml(self):
- template = Template(
- """
- {{ record_set.name }}
- {{ record_set.type_ }}
- {% if record_set.set_identifier %}
- {{ record_set.set_identifier }}
- {% endif %}
- {% if record_set.weight %}
- {{ record_set.weight }}
- {% endif %}
- {% if record_set.region %}
- {{ record_set.region }}
- {% endif %}
- {% if record_set.ttl %}
- {{ record_set.ttl }}
- {% endif %}
- {% if record_set.failover %}
- {{ record_set.failover }}
- {% endif %}
- {% if record_set.geo_location %}
-
- {% for geo_key in ['ContinentCode','CountryCode','SubdivisionCode'] %}
- {% if record_set.geo_location[geo_key] %}<{{ geo_key }}>{{ record_set.geo_location[geo_key] }}{{ geo_key }}>{% endif %}
- {% endfor %}
-
- {% endif %}
- {% if record_set.alias_target %}
-
- {{ record_set.alias_target['HostedZoneId'] }}
- {{ record_set.alias_target['DNSName'] }}
- {{ record_set.alias_target['EvaluateTargetHealth'] }}
-
- {% else %}
-
- {% for record in record_set.records %}
-
- {{ record|e }}
-
- {% endfor %}
-
- {% endif %}
- {% if record_set.health_check %}
- {{ record_set.health_check }}
- {% endif %}
- """
- )
- return template.render(record_set=self)
-
def delete(self, *args, **kwargs):
"""Not exposed as part of the Route 53 API - used for CloudFormation. args are ignored"""
hosted_zone = route53_backend.get_hosted_zone_by_name(self.hosted_zone_name)
diff --git a/moto/route53/responses.py b/moto/route53/responses.py
index 4b5f4bea7..16866eb61 100644
--- a/moto/route53/responses.py
+++ b/moto/route53/responses.py
@@ -314,11 +314,55 @@ CHANGE_TAGS_FOR_RESOURCE_RESPONSE = """
+LIST_RRSET_RESPONSE = """
+
- {% for record_set in record_sets %}
- {{ record_set.to_xml() }}
- {% endfor %}
+ {% for record in record_sets %}
+
+ {{ record.name }}
+ {{ record.type_ }}
+ {% if record.set_identifier %}
+ {{ record.set_identifier }}
+ {% endif %}
+ {% if record.weight %}
+ {{ record.weight }}
+ {% endif %}
+ {% if record.region %}
+ {{ record.region }}
+ {% endif %}
+ {% if record.ttl %}
+ {{ record.ttl }}
+ {% endif %}
+ {% if record.failover %}
+ {{ record.failover }}
+ {% endif %}
+ {% if record.geo_location %}
+
+ {% for geo_key in ['ContinentCode','CountryCode','SubdivisionCode'] %}
+ {% if record.geo_location[geo_key] %}<{{ geo_key }}>{{ record.geo_location[geo_key] }}{{ geo_key }}>{% endif %}
+ {% endfor %}
+
+ {% endif %}
+ {% if record.alias_target %}
+
+ {{ record.alias_target['HostedZoneId'] }}
+ {{ record.alias_target['DNSName'] }}
+ {{ record.alias_target['EvaluateTargetHealth'] }}
+
+ {% else %}
+
+ {% for resource in record.records %}
+
+
+
+ {% endfor %}
+
+ {% endif %}
+ {% if record.health_check %}
+ {{ record.health_check }}
+ {% endif %}
+
+ {% endfor %}
false
"""
diff --git a/tests/test_route53/test_server.py b/tests/test_route53/test_server.py
new file mode 100644
index 000000000..21ab9e80f
--- /dev/null
+++ b/tests/test_route53/test_server.py
@@ -0,0 +1,29 @@
+import sure # noqa # pylint: disable=unused-import
+import xmltodict
+
+import moto.server as server
+
+
+def test_list_recordset():
+ backend = server.create_backend_app("route53")
+ test_client = backend.test_client()
+
+ # create hosted zone
+ request_data = 'example.com2014-04-01-18:47'
+ res = test_client.post("2013-04-01/hostedzone", data=request_data)
+ body = parse_xml(res.data)
+ zone_id = body["CreateHostedZoneResponse"]["HostedZone"]["Id"].rsplit("/")[-1]
+
+ # change record set
+ # Contains a special character
+ request_data = 'CREATEn.example.comTXTstring1us-east-1val&sth'
+ test_client.post(f"2013-04-01/hostedzone/{zone_id}/rrset/", data=request_data)
+
+ # list record set
+ res = test_client.get(f"2013-04-01/hostedzone/{zone_id}/rrset")
+ # Ampersand should be properly encoded
+ res.data.decode("utf-8").should.contain("")
+
+
+def parse_xml(body):
+ return xmltodict.parse(body, dict_constructor=dict)