File: test_server.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (28 lines) | stat: -rw-r--r-- 1,497 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 = '<CreateHostedZoneRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/"><Name>example.com</Name><CallerReference>2014-04-01-18:47</CallerReference></CreateHostedZoneRequest>'
    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 = '<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/"><ChangeBatch><Changes><Change><Action>CREATE</Action><ResourceRecordSet><Name>n.example.com</Name><Type>TXT</Type><SetIdentifier>string</SetIdentifier><Weight>1</Weight><Region>us-east-1</Region><ResourceRecords><ResourceRecord><Value>val&amp;sth</Value></ResourceRecord></ResourceRecords></ResourceRecordSet></Change></Changes></ChangeBatch></ChangeResourceRecordSetsRequest>'
    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
    assert "<Value><![CDATA[val&sth]]></Value>" in res.data.decode("utf-8")


def parse_xml(body):
    return xmltodict.parse(body, dict_constructor=dict)