Skip to content

Commit

Permalink
Include resource records commit unit test for Route 53
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-Ming Zen committed May 2, 2014
1 parent ff129c2 commit 8cf6ceb
Showing 1 changed file with 121 additions and 5 deletions.
126 changes: 121 additions & 5 deletions tests/unit/route53/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# IN THE SOFTWARE.
#
import mock
import re
import xml.dom.minidom

from boto.exception import BotoServerError
from boto.route53.connection import Route53Connection
Expand All @@ -32,7 +34,6 @@
from tests.unit import unittest
from tests.unit import AWSMockServiceTestCase


@attr(route53=True)
class TestRoute53Connection(AWSMockServiceTestCase):
connection_class = Route53Connection
Expand Down Expand Up @@ -87,7 +88,7 @@ def _wrapper(*args, **kwargs):
# Unpatch.
self.service_connection._retry_handler = orig_retry


@attr(route53=True)
class TestCreateZoneRoute53(AWSMockServiceTestCase):
connection_class = Route53Connection

Expand Down Expand Up @@ -137,7 +138,7 @@ def test_create_hosted_zone(self):
self.assertEqual(response['CreateHostedZoneResponse']['DelegationSet']['NameServers'],
['ns-100.awsdns-01.com', 'ns-1000.awsdns-01.co.uk', 'ns-1000.awsdns-01.org', 'ns-900.awsdns-01.net'])


@attr(route53=True)
class TestGetZoneRoute53(AWSMockServiceTestCase):
connection_class = Route53Connection

Expand Down Expand Up @@ -194,7 +195,7 @@ def test_get_zone(self):
self.assertTrue(isinstance(response, Zone))
self.assertEqual(response.name, "example.com.")


@attr(route53=True)
class TestGetHostedZoneRoute53(AWSMockServiceTestCase):
connection_class = Route53Connection

Expand Down Expand Up @@ -231,7 +232,7 @@ def test_list_zones(self):
self.assertEqual(response['GetHostedZoneResponse']['DelegationSet']['NameServers'],
['ns-1000.awsdns-40.org', 'ns-200.awsdns-30.com', 'ns-900.awsdns-50.net', 'ns-1000.awsdns-00.co.uk'])


@attr(route53=True)
class TestGetAllRRSetsRoute53(AWSMockServiceTestCase):
connection_class = Route53Connection

Expand Down Expand Up @@ -345,4 +346,119 @@ def test_get_all_rr_sets(self):
self.assertEqual(failover_record.identifier, 'failover-primary')
self.assertEqual(failover_record.failover, 'PRIMARY')
self.assertEqual(failover_record.ttl, '60')

@attr(route53=True)
class TestChangeResourceRecordSetsRoute53(AWSMockServiceTestCase):
connection_class = Route53Connection

def setUp(self):
super(TestChangeResourceRecordSetsRoute53, self).setUp()

def default_body(self):
return """
<ChangeResourceRecordSetsResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
<ChangeInfo>
<Id>/change/C1111111111111</Id>
<Status>PENDING</Status>
<SubmittedAt>2014-05-05T10:11:12.123Z</SubmittedAt>
</ChangeInfo>
</ChangeResourceRecordSetsResponse>
"""

def test_record_commit(self):
rrsets = ResourceRecordSets(self.service_connection)
rrsets.add_change_record('CREATE', Record('vanilla.example.com', 'A', 60, ['1.2.3.4']))
rrsets.add_change_record('CREATE', Record('alias.example.com', 'AAAA', alias_hosted_zone_id='Z123OTHER', alias_dns_name='target.other', alias_evaluate_target_health=True))
rrsets.add_change_record('CREATE', Record('wrr.example.com', 'CNAME', 60, ['cname.target'], weight=10, identifier='weight-1'))
rrsets.add_change_record('CREATE', Record('lbr.example.com', 'TXT', 60, ['text record'], region='us-west-2', identifier='region-1'))
rrsets.add_change_record('CREATE', Record('failover.example.com', 'A', 60, ['2.2.2.2'], health_check='hc-1234', failover='PRIMARY', identifier='primary'))

changes_xml = rrsets.to_xml()

# the whitespacing doesn't match exactly, so we'll pretty print and drop all new lines
# not the best, but
actual_xml = re.sub(r"\s*[\r\n]+", "\n", xml.dom.minidom.parseString(changes_xml).toprettyxml())
expected_xml = re.sub(r"\s*[\r\n]+", "\n", xml.dom.minidom.parseString("""
<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
<ChangeBatch>
<Comment>None</Comment>
<Changes>
<Change>
<Action>CREATE</Action>
<ResourceRecordSet>
<Name>vanilla.example.com</Name>
<Type>A</Type>
<TTL>60</TTL>
<ResourceRecords>
<ResourceRecord>
<Value>1.2.3.4</Value>
</ResourceRecord>
</ResourceRecords>
</ResourceRecordSet>
</Change>
<Change>
<Action>CREATE</Action>
<ResourceRecordSet>
<Name>alias.example.com</Name>
<Type>AAAA</Type>
<AliasTarget>
<HostedZoneId>Z123OTHER</HostedZoneId>
<DNSName>target.other</DNSName>
<EvaluateTargetHealth>true</EvaluateTargetHealth>
</AliasTarget>
</ResourceRecordSet>
</Change>
<Change>
<Action>CREATE</Action>
<ResourceRecordSet>
<Name>wrr.example.com</Name>
<Type>CNAME</Type>
<SetIdentifier>weight-1</SetIdentifier>
<Weight>10</Weight>
<TTL>60</TTL>
<ResourceRecords>
<ResourceRecord>
<Value>cname.target</Value>
</ResourceRecord>
</ResourceRecords>
</ResourceRecordSet>
</Change>
<Change>
<Action>CREATE</Action>
<ResourceRecordSet>
<Name>lbr.example.com</Name>
<Type>TXT</Type>
<SetIdentifier>region-1</SetIdentifier>
<Region>us-west-2</Region>
<TTL>60</TTL>
<ResourceRecords>
<ResourceRecord>
<Value>text record</Value>
</ResourceRecord>
</ResourceRecords>
</ResourceRecordSet>
</Change>
<Change>
<Action>CREATE</Action>
<ResourceRecordSet>
<Name>failover.example.com</Name>
<Type>A</Type>
<SetIdentifier>primary</SetIdentifier>
<Failover>PRIMARY</Failover>
<TTL>60</TTL>
<ResourceRecords>
<ResourceRecord>
<Value>2.2.2.2</Value>
</ResourceRecord>
</ResourceRecords>
<HealthCheckId>hc-1234</HealthCheckId>
</ResourceRecordSet>
</Change>
</Changes>
</ChangeBatch>
</ChangeResourceRecordSetsRequest>
""").toprettyxml())

# Note: the alias XML should not include the TTL, even if it's specified in the object model
self.assertEqual(actual_xml, expected_xml)

0 comments on commit 8cf6ceb

Please sign in to comment.