OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2011 Blue Pines Technologies LLC, Brad Carleton |
| 2 # www.bluepines.org |
| 3 # Copyright (c) 2012 42 Lines Inc., Jim Browne |
| 4 # |
| 5 # Permission is hereby granted, free of charge, to any person obtaining a |
| 6 # copy of this software and associated documentation files (the |
| 7 # "Software"), to deal in the Software without restriction, including |
| 8 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 9 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 10 # persons to whom the Software is furnished to do so, subject to the fol- |
| 11 # lowing conditions: |
| 12 # |
| 13 # The above copyright notice and this permission notice shall be included |
| 14 # in all copies or substantial portions of the Software. |
| 15 # |
| 16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 18 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 19 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 20 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 22 # IN THE SOFTWARE. |
| 23 # |
| 24 |
| 25 import unittest |
| 26 from boto.route53.connection import Route53Connection |
| 27 from boto.exception import TooManyRecordsException |
| 28 |
| 29 |
| 30 class TestRoute53Zone(unittest.TestCase): |
| 31 @classmethod |
| 32 def setUpClass(self): |
| 33 route53 = Route53Connection() |
| 34 zone = route53.get_zone('example.com') |
| 35 if zone is not None: |
| 36 zone.delete() |
| 37 self.zone = route53.create_zone('example.com') |
| 38 |
| 39 def test_nameservers(self): |
| 40 self.zone.get_nameservers() |
| 41 |
| 42 def test_a(self): |
| 43 self.zone.add_a('example.com', '102.11.23.1', 80) |
| 44 record = self.zone.get_a('example.com') |
| 45 self.assertEquals(record.name, u'example.com.') |
| 46 self.assertEquals(record.resource_records, [u'102.11.23.1']) |
| 47 self.assertEquals(record.ttl, u'80') |
| 48 self.zone.update_a('example.com', '186.143.32.2', '800') |
| 49 record = self.zone.get_a('example.com') |
| 50 self.assertEquals(record.name, u'example.com.') |
| 51 self.assertEquals(record.resource_records, [u'186.143.32.2']) |
| 52 self.assertEquals(record.ttl, u'800') |
| 53 |
| 54 def test_cname(self): |
| 55 self.zone.add_cname('www.example.com', 'webserver.example.com', 200) |
| 56 record = self.zone.get_cname('www.example.com') |
| 57 self.assertEquals(record.name, u'www.example.com.') |
| 58 self.assertEquals(record.resource_records, [u'webserver.example.com.']) |
| 59 self.assertEquals(record.ttl, u'200') |
| 60 self.zone.update_cname('www.example.com', 'web.example.com', 45) |
| 61 record = self.zone.get_cname('www.example.com') |
| 62 self.assertEquals(record.name, u'www.example.com.') |
| 63 self.assertEquals(record.resource_records, [u'web.example.com.']) |
| 64 self.assertEquals(record.ttl, u'45') |
| 65 |
| 66 def test_mx(self): |
| 67 self.zone.add_mx('example.com', |
| 68 ['10 mx1.example.com', '20 mx2.example.com'], |
| 69 1000) |
| 70 record = self.zone.get_mx('example.com') |
| 71 self.assertEquals(set(record.resource_records), |
| 72 set([u'10 mx1.example.com.', |
| 73 u'20 mx2.example.com.'])) |
| 74 self.assertEquals(record.ttl, u'1000') |
| 75 self.zone.update_mx('example.com', |
| 76 ['10 mail1.example.com', '20 mail2.example.com'], |
| 77 50) |
| 78 record = self.zone.get_mx('example.com') |
| 79 self.assertEquals(set(record.resource_records), |
| 80 set([u'10 mail1.example.com.', |
| 81 '20 mail2.example.com.'])) |
| 82 self.assertEquals(record.ttl, u'50') |
| 83 |
| 84 def test_get_records(self): |
| 85 self.zone.get_records() |
| 86 |
| 87 def test_get_nameservers(self): |
| 88 self.zone.get_nameservers() |
| 89 |
| 90 def test_get_zones(self): |
| 91 route53 = Route53Connection() |
| 92 route53.get_zones() |
| 93 |
| 94 def test_identifiers_wrrs(self): |
| 95 self.zone.add_a('wrr.example.com', '1.2.3.4', |
| 96 identifier=('foo', '20')) |
| 97 self.zone.add_a('wrr.example.com', '5.6.7.8', |
| 98 identifier=('bar', '10')) |
| 99 wrrs = self.zone.find_records('wrr.example.com', 'A', all=True) |
| 100 self.assertEquals(len(wrrs), 2) |
| 101 self.zone.delete_a('wrr.example.com', all=True) |
| 102 |
| 103 def test_identifiers_lbrs(self): |
| 104 self.zone.add_a('lbr.example.com', '4.3.2.1', |
| 105 identifier=('baz', 'us-east-1')) |
| 106 self.zone.add_a('lbr.example.com', '8.7.6.5', |
| 107 identifier=('bam', 'us-west-1')) |
| 108 lbrs = self.zone.find_records('lbr.example.com', 'A', all=True) |
| 109 self.assertEquals(len(lbrs), 2) |
| 110 self.zone.delete_a('lbr.example.com', |
| 111 identifier=('bam', 'us-west-1')) |
| 112 self.zone.delete_a('lbr.example.com', |
| 113 identifier=('baz', 'us-east-1')) |
| 114 |
| 115 def test_toomany_exception(self): |
| 116 self.zone.add_a('exception.example.com', '4.3.2.1', |
| 117 identifier=('baz', 'us-east-1')) |
| 118 self.zone.add_a('exception.example.com', '8.7.6.5', |
| 119 identifier=('bam', 'us-west-1')) |
| 120 with self.assertRaises(TooManyRecordsException): |
| 121 lbrs = self.zone.get_a('exception.example.com') |
| 122 self.zone.delete_a('exception.example.com', all=True) |
| 123 |
| 124 @classmethod |
| 125 def tearDownClass(self): |
| 126 self.zone.delete_a('example.com') |
| 127 self.zone.delete_cname('www.example.com') |
| 128 self.zone.delete_mx('example.com') |
| 129 self.zone.delete() |
| 130 |
| 131 if __name__ == '__main__': |
| 132 unittest.main(verbosity=3) |
OLD | NEW |