class LinodeTests(unittest.TestCase): def setUp(self): LinodeDNSDriver.connectionCls.conn_classes = (None, LinodeMockHttp) LinodeMockHttp.use_param = 'api_action' LinodeMockHttp.type = None self.driver = LinodeDNSDriver(*DNS_PARAMS_LINODE) def assertHasKeys(self, dictionary, keys): for key in keys: self.assertTrue(key in dictionary, 'key "%s" not in dictionary' % (key)) def test_list_record_types(self): record_types = self.driver.list_record_types() self.assertEqual(len(record_types), 7) self.assertTrue(RecordType.A in record_types) def test_list_zones_success(self): zones = self.driver.list_zones() self.assertEqual(len(zones), 2) zone = zones[0] self.assertEqual(zone.id, '5093') self.assertEqual(zone.type, 'master') self.assertEqual(zone.domain, 'linode.com') self.assertEqual(zone.ttl, None) self.assertHasKeys(zone.extra, ['description', 'SOA_Email', 'status']) def test_list_records_success(self): zone = self.driver.list_zones()[0] records = self.driver.list_records(zone=zone) self.assertEqual(len(records), 2) record = records[0] self.assertEqual(record.id, '28536') self.assertEqual(record.name, 'www') self.assertEqual(record.type, RecordType.A) self.assertEqual(record.data, '75.127.96.245') self.assertHasKeys(record.extra, ['protocol', 'ttl_sec', 'port', 'weight']) def test_list_records_zone_does_not_exist(self): zone = self.driver.list_zones()[0] LinodeMockHttp.type = 'ZONE_DOES_NOT_EXIST' try: self.driver.list_records(zone=zone) except ZoneDoesNotExistError: e = sys.exc_info()[1] self.assertEqual(e.zone_id, zone.id) else: self.fail('Exception was not thrown') def test_get_zone_success(self): LinodeMockHttp.type = 'GET_ZONE' zone = self.driver.get_zone(zone_id='5093') self.assertEqual(zone.id, '5093') self.assertEqual(zone.type, 'master') self.assertEqual(zone.domain, 'linode.com') self.assertEqual(zone.ttl, None) self.assertHasKeys(zone.extra, ['description', 'SOA_Email', 'status']) def test_get_zone_does_not_exist(self): LinodeMockHttp.type = 'GET_ZONE_DOES_NOT_EXIST' try: self.driver.get_zone(zone_id='4444') except ZoneDoesNotExistError: e = sys.exc_info()[1] self.assertEqual(e.zone_id, '4444') else: self.fail('Exception was not thrown') def test_get_record_success(self): LinodeMockHttp.type = 'GET_RECORD' record = self.driver.get_record(zone_id='1234', record_id='28536') self.assertEqual(record.id, '28536') self.assertEqual(record.name, 'www') self.assertEqual(record.type, RecordType.A) self.assertEqual(record.data, '75.127.96.245') self.assertHasKeys(record.extra, ['protocol', 'ttl_sec', 'port', 'weight']) def test_get_record_zone_does_not_exist(self): LinodeMockHttp.type = 'GET_RECORD_ZONE_DOES_NOT_EXIST' try: self.driver.get_record(zone_id='444', record_id='28536') except ZoneDoesNotExistError: pass else: self.fail('Exception was not thrown') def test_get_record_record_does_not_exist(self): LinodeMockHttp.type = 'GET_RECORD_RECORD_DOES_NOT_EXIST' try: self.driver.get_record(zone_id='4441', record_id='28536') except RecordDoesNotExistError: pass else: self.fail('Exception was not thrown') def test_create_zone_success(self): zone = self.driver.create_zone(domain='foo.bar.com', type='master', ttl=None, extra=None) self.assertEqual(zone.id, '5123') self.assertEqual(zone.domain, 'foo.bar.com') def test_create_zone_validaton_error(self): LinodeMockHttp.type = 'VALIDATION_ERROR' try: self.driver.create_zone(domain='foo.bar.com', type='master', ttl=None, extra=None) except LinodeException: pass else: self.fail('Exception was not thrown') def test_update_zone_success(self): zone = self.driver.list_zones()[0] updated_zone = self.driver.update_zone( zone=zone, domain='libcloud.org', ttl=10, extra={'SOA_Email': '*****@*****.**'}) self.assertEqual(zone.extra['SOA_Email'], '*****@*****.**') self.assertEqual(updated_zone.id, zone.id) self.assertEqual(updated_zone.domain, 'libcloud.org') self.assertEqual(updated_zone.type, zone.type) self.assertEqual(updated_zone.ttl, 10) self.assertEqual(updated_zone.extra['SOA_Email'], '*****@*****.**') self.assertEqual(updated_zone.extra['status'], zone.extra['status']) self.assertEqual(updated_zone.extra['description'], zone.extra['description']) def test_create_record_success(self): zone = self.driver.list_zones()[0] record = self.driver.create_record(name='www', zone=zone, type=RecordType.A, data='127.0.0.1') self.assertEqual(record.id, '28537') self.assertEqual(record.name, 'www') self.assertEqual(record.zone, zone) self.assertEqual(record.type, RecordType.A) self.assertEqual(record.data, '127.0.0.1') def test_update_record_success(self): zone = self.driver.list_zones()[0] record = self.driver.list_records(zone=zone)[0] updated_record = self.driver.update_record(record=record, name='www', type=RecordType.AAAA, data='::1') self.assertEqual(record.data, '75.127.96.245') self.assertEqual(updated_record.id, record.id) self.assertEqual(updated_record.name, 'www') self.assertEqual(updated_record.zone, record.zone) self.assertEqual(updated_record.type, RecordType.AAAA) self.assertEqual(updated_record.data, '::1') def test_delete_zone_success(self): zone = self.driver.list_zones()[0] status = self.driver.delete_zone(zone=zone) self.assertTrue(status) def test_delete_zone_does_not_exist(self): zone = self.driver.list_zones()[0] LinodeMockHttp.type = 'ZONE_DOES_NOT_EXIST' try: self.driver.delete_zone(zone=zone) except ZoneDoesNotExistError: e = sys.exc_info()[1] self.assertEqual(e.zone_id, zone.id) else: self.fail('Exception was not thrown') def test_delete_record_success(self): zone = self.driver.list_zones()[0] record = self.driver.list_records(zone=zone)[0] status = self.driver.delete_record(record=record) self.assertTrue(status) def test_delete_record_does_not_exist(self): zone = self.driver.list_zones()[0] record = self.driver.list_records(zone=zone)[0] LinodeMockHttp.type = 'RECORD_DOES_NOT_EXIST' try: self.driver.delete_record(record=record) except RecordDoesNotExistError: e = sys.exc_info()[1] self.assertEqual(e.record_id, record.id) else: self.fail('Exception was not thrown')
class LinodeTests(unittest.TestCase): def setUp(self): LinodeDNSDriver.connectionCls.conn_class = LinodeMockHttp LinodeMockHttp.use_param = 'api_action' LinodeMockHttp.type = None self.driver = LinodeDNSDriver(*DNS_PARAMS_LINODE) def assertHasKeys(self, dictionary, keys): for key in keys: self.assertTrue(key in dictionary, 'key "%s" not in dictionary' % (key)) def test_list_record_types(self): record_types = self.driver.list_record_types() self.assertEqual(len(record_types), 7) self.assertTrue(RecordType.A in record_types) def test_list_zones_success(self): zones = self.driver.list_zones() self.assertEqual(len(zones), 2) zone = zones[0] self.assertEqual(zone.id, '5093') self.assertEqual(zone.type, 'master') self.assertEqual(zone.domain, 'linode.com') self.assertEqual(zone.ttl, None) self.assertHasKeys(zone.extra, ['description', 'SOA_Email', 'status']) def test_list_records_success(self): zone = self.driver.list_zones()[0] records = self.driver.list_records(zone=zone) self.assertEqual(len(records), 2) arecord = records[0] self.assertEqual(arecord.id, '3585100') self.assertEqual(arecord.name, 'mc') self.assertEqual(arecord.type, RecordType.A) self.assertEqual(arecord.data, '127.0.0.1') self.assertHasKeys(arecord.extra, ['protocol', 'ttl_sec', 'port', 'weight']) def test_list_records_zone_does_not_exist(self): zone = self.driver.list_zones()[0] LinodeMockHttp.type = 'ZONE_DOES_NOT_EXIST' try: self.driver.list_records(zone=zone) except ZoneDoesNotExistError: e = sys.exc_info()[1] self.assertEqual(e.zone_id, zone.id) else: self.fail('Exception was not thrown') def test_get_zone_success(self): LinodeMockHttp.type = 'GET_ZONE' zone = self.driver.get_zone(zone_id='5093') self.assertEqual(zone.id, '5093') self.assertEqual(zone.type, 'master') self.assertEqual(zone.domain, 'linode.com') self.assertEqual(zone.ttl, None) self.assertHasKeys(zone.extra, ['description', 'SOA_Email', 'status']) def test_get_zone_does_not_exist(self): LinodeMockHttp.type = 'GET_ZONE_DOES_NOT_EXIST' try: self.driver.get_zone(zone_id='4444') except ZoneDoesNotExistError: e = sys.exc_info()[1] self.assertEqual(e.zone_id, '4444') else: self.fail('Exception was not thrown') def test_get_record_success(self): LinodeMockHttp.type = 'GET_RECORD' record = self.driver.get_record(zone_id='1234', record_id='3585100') self.assertEqual(record.id, '3585100') self.assertEqual(record.name, 'www') self.assertEqual(record.type, RecordType.A) self.assertEqual(record.data, '127.0.0.1') self.assertHasKeys(record.extra, ['protocol', 'ttl_sec', 'port', 'weight']) def test_get_record_zone_does_not_exist(self): LinodeMockHttp.type = 'GET_RECORD_ZONE_DOES_NOT_EXIST' try: self.driver.get_record(zone_id='444', record_id='3585100') except ZoneDoesNotExistError: pass else: self.fail('Exception was not thrown') def test_get_record_record_does_not_exist(self): LinodeMockHttp.type = 'GET_RECORD_RECORD_DOES_NOT_EXIST' try: self.driver.get_record(zone_id='4441', record_id='3585100') except RecordDoesNotExistError: pass else: self.fail('Exception was not thrown') def test_create_zone_success(self): zone = self.driver.create_zone(domain='foo.bar.com', type='master', ttl=None, extra=None) self.assertEqual(zone.id, '5094') self.assertEqual(zone.domain, 'foo.bar.com') def test_create_zone_validaton_error(self): LinodeMockHttp.type = 'VALIDATION_ERROR' try: self.driver.create_zone(domain='foo.bar.com', type='master', ttl=None, extra=None) except LinodeException: pass else: self.fail('Exception was not thrown') def test_update_zone_success(self): zone = self.driver.list_zones()[0] updated_zone = self.driver.update_zone(zone=zone, domain='libcloud.org', ttl=10, extra={'SOA_Email': '*****@*****.**'}) self.assertEqual(zone.extra['SOA_Email'], '*****@*****.**') self.assertEqual(updated_zone.id, zone.id) self.assertEqual(updated_zone.domain, 'libcloud.org') self.assertEqual(updated_zone.type, zone.type) self.assertEqual(updated_zone.ttl, 10) self.assertEqual(updated_zone.extra['SOA_Email'], '*****@*****.**') self.assertEqual(updated_zone.extra['status'], zone.extra['status']) self.assertEqual(updated_zone.extra['description'], zone.extra['description']) def test_create_record_success(self): zone = self.driver.list_zones()[0] record = self.driver.create_record(name='www', zone=zone, type=RecordType.A, data='127.0.0.1') self.assertEqual(record.id, '3585100') self.assertEqual(record.name, 'www') self.assertEqual(record.zone, zone) self.assertEqual(record.type, RecordType.A) self.assertEqual(record.data, '127.0.0.1') def test_update_record_success(self): zone = self.driver.list_zones()[0] record = self.driver.list_records(zone=zone)[0] updated_record = self.driver.update_record(record=record, name='www', type=RecordType.AAAA, data='::1') self.assertEqual(record.data, '127.0.0.1') self.assertEqual(updated_record.id, record.id) self.assertEqual(updated_record.name, 'www') self.assertEqual(updated_record.zone, record.zone) self.assertEqual(updated_record.type, RecordType.AAAA) self.assertEqual(updated_record.data, '::1') def test_delete_zone_success(self): zone = self.driver.list_zones()[0] status = self.driver.delete_zone(zone=zone) self.assertTrue(status) def test_delete_zone_does_not_exist(self): zone = self.driver.list_zones()[0] LinodeMockHttp.type = 'ZONE_DOES_NOT_EXIST' try: self.driver.delete_zone(zone=zone) except ZoneDoesNotExistError: e = sys.exc_info()[1] self.assertEqual(e.zone_id, zone.id) else: self.fail('Exception was not thrown') def test_delete_record_success(self): zone = self.driver.list_zones()[0] record = self.driver.list_records(zone=zone)[0] status = self.driver.delete_record(record=record) self.assertTrue(status) def test_delete_record_does_not_exist(self): zone = self.driver.list_zones()[0] record = self.driver.list_records(zone=zone)[0] LinodeMockHttp.type = 'RECORD_DOES_NOT_EXIST' try: self.driver.delete_record(record=record) except RecordDoesNotExistError: e = sys.exc_info()[1] self.assertEqual(e.record_id, record.id) else: self.fail('Exception was not thrown')
class LinodeTests(unittest.TestCase): def setUp(self): LinodeDNSDriverV3.connectionCls.conn_class = LinodeMockHttp LinodeMockHttp.use_param = "api_action" LinodeMockHttp.type = None self.driver = LinodeDNSDriver(*DNS_PARAMS_LINODE, **DNS_KEYWORD_PARAMS_LINODE) def assertHasKeys(self, dictionary, keys): for key in keys: self.assertTrue(key in dictionary, 'key "%s" not in dictionary' % (key)) def test_list_record_types(self): record_types = self.driver.list_record_types() self.assertEqual(len(record_types), 7) self.assertTrue(RecordType.A in record_types) def test_list_zones_success(self): zones = self.driver.list_zones() self.assertEqual(len(zones), 2) zone = zones[0] self.assertEqual(zone.id, "5093") self.assertEqual(zone.type, "master") self.assertEqual(zone.domain, "linode.com") self.assertIsNone(zone.ttl) self.assertHasKeys(zone.extra, ["description", "SOA_Email", "status"]) def test_list_records_success(self): zone = self.driver.list_zones()[0] records = self.driver.list_records(zone=zone) self.assertEqual(len(records), 2) arecord = records[0] self.assertEqual(arecord.id, "3585100") self.assertEqual(arecord.name, "mc") self.assertEqual(arecord.type, RecordType.A) self.assertEqual(arecord.data, "127.0.0.1") self.assertHasKeys(arecord.extra, ["protocol", "ttl_sec", "port", "weight"]) srvrecord = records[1] self.assertEqual(srvrecord.id, "3585141") self.assertEqual(srvrecord.name, "_minecraft._udp") self.assertEqual(srvrecord.type, RecordType.SRV) self.assertEqual(srvrecord.data, "mc.linode.com") self.assertHasKeys( srvrecord.extra, ["protocol", "ttl_sec", "port", "priority", "weight"]) def test_list_records_zone_does_not_exist(self): zone = self.driver.list_zones()[0] LinodeMockHttp.type = "ZONE_DOES_NOT_EXIST" try: self.driver.list_records(zone=zone) except ZoneDoesNotExistError as e: self.assertEqual(e.zone_id, zone.id) else: self.fail("Exception was not thrown") def test_get_zone_success(self): LinodeMockHttp.type = "GET_ZONE" zone = self.driver.get_zone(zone_id="5093") self.assertEqual(zone.id, "5093") self.assertEqual(zone.type, "master") self.assertEqual(zone.domain, "linode.com") self.assertIsNone(zone.ttl) self.assertHasKeys(zone.extra, ["description", "SOA_Email", "status"]) def test_get_zone_does_not_exist(self): LinodeMockHttp.type = "GET_ZONE_DOES_NOT_EXIST" try: self.driver.get_zone(zone_id="4444") except ZoneDoesNotExistError as e: self.assertEqual(e.zone_id, "4444") else: self.fail("Exception was not thrown") def test_get_record_success(self): LinodeMockHttp.type = "GET_RECORD" record = self.driver.get_record(zone_id="1234", record_id="3585100") self.assertEqual(record.id, "3585100") self.assertEqual(record.name, "www") self.assertEqual(record.type, RecordType.A) self.assertEqual(record.data, "127.0.0.1") self.assertHasKeys(record.extra, ["protocol", "ttl_sec", "port", "weight"]) def test_get_record_zone_does_not_exist(self): LinodeMockHttp.type = "GET_RECORD_ZONE_DOES_NOT_EXIST" try: self.driver.get_record(zone_id="444", record_id="3585100") except ZoneDoesNotExistError: pass else: self.fail("Exception was not thrown") def test_get_record_record_does_not_exist(self): LinodeMockHttp.type = "GET_RECORD_RECORD_DOES_NOT_EXIST" try: self.driver.get_record(zone_id="4441", record_id="3585100") except RecordDoesNotExistError: pass else: self.fail("Exception was not thrown") def test_create_zone_success(self): zone = self.driver.create_zone(domain="foo.bar.com", type="master", ttl=None, extra=None) self.assertEqual(zone.id, "5094") self.assertEqual(zone.domain, "foo.bar.com") def test_create_zone_validaton_error(self): LinodeMockHttp.type = "VALIDATION_ERROR" try: self.driver.create_zone(domain="foo.bar.com", type="master", ttl=None, extra=None) except LinodeException: pass else: self.fail("Exception was not thrown") def test_update_zone_success(self): zone = self.driver.list_zones()[0] updated_zone = self.driver.update_zone( zone=zone, domain="libcloud.org", ttl=10, extra={"SOA_Email": "*****@*****.**"}, ) self.assertEqual(zone.extra["SOA_Email"], "*****@*****.**") self.assertEqual(updated_zone.id, zone.id) self.assertEqual(updated_zone.domain, "libcloud.org") self.assertEqual(updated_zone.type, zone.type) self.assertEqual(updated_zone.ttl, 10) self.assertEqual(updated_zone.extra["SOA_Email"], "*****@*****.**") self.assertEqual(updated_zone.extra["status"], zone.extra["status"]) self.assertEqual(updated_zone.extra["description"], zone.extra["description"]) def test_create_record_success(self): zone = self.driver.list_zones()[0] record = self.driver.create_record(name="www", zone=zone, type=RecordType.A, data="127.0.0.1") self.assertEqual(record.id, "3585100") self.assertEqual(record.name, "www") self.assertEqual(record.zone, zone) self.assertEqual(record.type, RecordType.A) self.assertEqual(record.data, "127.0.0.1") def test_update_record_success(self): zone = self.driver.list_zones()[0] record = self.driver.list_records(zone=zone)[0] updated_record = self.driver.update_record(record=record, name="www", type=RecordType.AAAA, data="::1") self.assertEqual(record.data, "127.0.0.1") self.assertEqual(updated_record.id, record.id) self.assertEqual(updated_record.name, "www") self.assertEqual(updated_record.zone, record.zone) self.assertEqual(updated_record.type, RecordType.AAAA) self.assertEqual(updated_record.data, "::1") def test_delete_zone_success(self): zone = self.driver.list_zones()[0] status = self.driver.delete_zone(zone=zone) self.assertTrue(status) def test_delete_zone_does_not_exist(self): zone = self.driver.list_zones()[0] LinodeMockHttp.type = "ZONE_DOES_NOT_EXIST" try: self.driver.delete_zone(zone=zone) except ZoneDoesNotExistError as e: self.assertEqual(e.zone_id, zone.id) else: self.fail("Exception was not thrown") def test_delete_record_success(self): zone = self.driver.list_zones()[0] record = self.driver.list_records(zone=zone)[0] status = self.driver.delete_record(record=record) self.assertTrue(status) def test_delete_record_does_not_exist(self): zone = self.driver.list_zones()[0] record = self.driver.list_records(zone=zone)[0] LinodeMockHttp.type = "RECORD_DOES_NOT_EXIST" try: self.driver.delete_record(record=record) except RecordDoesNotExistError as e: self.assertEqual(e.record_id, record.id) else: self.fail("Exception was not thrown")
class LinodeTests(unittest.TestCase): def setUp(self): LinodeDNSDriverV4.connectionCls.conn_class = LinodeMockHttpV4 LinodeMockHttpV4.type = None self.driver = LinodeDNSDriver(*DNS_PARAMS_LINODE) def test_correct_class_is_used(self): self.assertIsInstance(self.driver, LinodeDNSDriverV4) def test_unknown_api_version(self): self.assertRaises(NotImplementedError, LinodeDNSDriver, "foo", api_version="2.0") def test_list_zones(self): zones = self.driver.list_zones() self.assertEqual(len(zones), 3) zone = zones[0] self.assertEqual(zone.id, "123") self.assertEqual(zone.domain, "test.com") self.assertEqual(zone.ttl, 300) self.assertEqual(zone.extra["soa_email"], "*****@*****.**") def test_list_records(self): zone = self.driver.list_zones()[0] records = self.driver.list_records(zone) self.assertEqual(len(records), 6) record = records[0] self.assertEqual(record.id, "123") self.assertEqual(record.data, "mail.test.com") self.assertEqual(record.ttl, 300) def test_get_zone(self): zone = self.driver.get_zone("123") self.assertEqual(zone.id, "123") self.assertEqual(zone.domain, "test.com") self.assertEqual(zone.extra["soa_email"], "*****@*****.**") def test_get_zone_not_found(self): LinodeMockHttpV4.type = "ZONE_DOES_NOT_EXIST" with self.assertRaises(Exception): self.driver.get_zone("123") def test_get_record_A_RECORD(self): LinodeMockHttpV4.type = "A_RECORD" record = self.driver.get_record("123", "123") self.assertEqual(record.id, "123") self.assertEqual(record.name, "test.example.com") self.assertEqual(record.type, "A") def test_get_record_MX_RECORD(self): LinodeMockHttpV4.type = "MX_RECORD" record = self.driver.get_record("123", "123") self.assertEqual(record.id, "123") self.assertEqual(record.data, "mail.example.com") self.assertEqual(record.type, "MX") def test_create_zone(self): domain = "example.com" ttl = 300 extra = {"soa_email": "*****@*****.**"} zone = self.driver.create_zone(domain=domain, ttl=ttl, extra=extra) self.assertEqual(zone.ttl, 300) self.assertEqual(zone.domain, "example.com") self.assertEqual(zone.extra["soa_email"], "*****@*****.**") def test_create_record(self): zone = self.driver.list_zones()[0] name = "test" type = RecordType.A data = "200.150.100.50" record = self.driver.create_record(name, zone, type, data) self.assertEqual(record.id, "123") self.assertEqual(record.name, name) self.assertEqual(record.type, "A") self.assertEqual(record.data, data) def test_update_zone(self): zone = self.driver.list_zones()[0] domain = "example.com" ttl = 300 extra = {"description": "Testing", "soa_email": "*****@*****.**"} updated_zone = self.driver.update_zone(zone, domain, ttl=ttl, extra=extra) self.assertEqual(updated_zone.domain, domain) self.assertEqual(updated_zone.ttl, ttl) self.assertEqual(updated_zone.extra["soa_email"], extra["soa_email"]) self.assertEqual(updated_zone.extra["description"], extra["description"]) def test_update_record(self): LinodeMockHttpV4.type = "A_RECORD" record = self.driver.get_record("123", "123") name = "test" data = "200.150.100.50" extra = {"ttl_sec": 3600} updated = self.driver.update_record(record, name=name, data=data, extra=extra) self.assertEqual(updated.name, name) self.assertEqual(updated.ttl, extra["ttl_sec"]) self.assertEqual(updated.data, data) def test_delete_zone(self): zone = self.driver.list_zones()[0] self.assertTrue(self.driver.delete_zone(zone)) def test_delete_record(self): zone = self.driver.list_zones()[0] record = self.driver.list_records(zone)[0] self.assertTrue(self.driver.delete_record(record))
class LinodeTests(unittest.TestCase): def setUp(self): LinodeDNSDriverV4.connectionCls.conn_class = LinodeMockHttpV4 LinodeMockHttpV4.type = None self.driver = LinodeDNSDriver(*DNS_PARAMS_LINODE) def test_correct_class_is_used(self): self.assertIsInstance(self.driver, LinodeDNSDriverV4) def test_unknown_api_version(self): self.assertRaises(NotImplementedError, LinodeDNSDriver, 'foo', api_version='2.0') def test_list_zones(self): zones = self.driver.list_zones() self.assertEqual(len(zones), 3) zone = zones[0] self.assertEqual(zone.id, '123') self.assertEqual(zone.domain, 'test.com') self.assertEqual(zone.ttl, 300) self.assertEqual(zone.extra['soa_email'], '*****@*****.**') def test_list_records(self): zone = self.driver.list_zones()[0] records = self.driver.list_records(zone) self.assertEqual(len(records), 6) record = records[0] self.assertEqual(record.id, '123') self.assertEqual(record.data, 'mail.test.com') self.assertEqual(record.ttl, 300) def test_get_zone(self): zone = self.driver.get_zone('123') self.assertEqual(zone.id, '123') self.assertEqual(zone.domain, 'test.com') self.assertEqual(zone.extra['soa_email'], '*****@*****.**') def test_get_zone_not_found(self): LinodeMockHttpV4.type = 'ZONE_DOES_NOT_EXIST' with self.assertRaises(Exception): self.driver.get_zone('123') def test_get_record_A_RECORD(self): LinodeMockHttpV4.type = 'A_RECORD' record = self.driver.get_record('123', '123') self.assertEqual(record.id, '123') self.assertEqual(record.name, 'test.example.com') self.assertEqual(record.type, 'A') def test_get_record_MX_RECORD(self): LinodeMockHttpV4.type = 'MX_RECORD' record = self.driver.get_record('123', '123') self.assertEqual(record.id, '123') self.assertEqual(record.data, 'mail.example.com') self.assertEqual(record.type, 'MX') def test_create_zone(self): domain = 'example.com' ttl = 300 extra = { 'soa_email': '*****@*****.**' } zone = self.driver.create_zone(domain=domain, ttl=ttl, extra=extra) self.assertEqual(zone.ttl, 300) self.assertEqual(zone.domain, 'example.com') self.assertEqual(zone.extra['soa_email'], '*****@*****.**') def test_create_record(self): zone = self.driver.list_zones()[0] name = 'test' type = RecordType.A data = '200.150.100.50' record = self.driver.create_record(name, zone, type, data) self.assertEqual(record.id, '123') self.assertEqual(record.name, name) self.assertEqual(record.type, 'A') self.assertEqual(record.data, data) def test_update_zone(self): zone = self.driver.list_zones()[0] domain = 'example.com' ttl = 300 extra = { 'description': 'Testing', 'soa_email': '*****@*****.**' } updated_zone = self.driver.update_zone(zone, domain, ttl=ttl, extra=extra) self.assertEqual(updated_zone.domain, domain) self.assertEqual(updated_zone.ttl, ttl) self.assertEqual(updated_zone.extra['soa_email'], extra['soa_email']) self.assertEqual(updated_zone.extra['description'], extra['description']) def test_update_record(self): LinodeMockHttpV4.type = 'A_RECORD' record = self.driver.get_record('123', '123') name = 'test' data = '200.150.100.50' extra = { 'ttl_sec': 3600 } updated = self.driver.update_record(record, name=name, data=data, extra=extra) self.assertEqual(updated.name, name) self.assertEqual(updated.ttl, extra['ttl_sec']) self.assertEqual(updated.data, data) def test_delete_zone(self): zone = self.driver.list_zones()[0] self.assertTrue(self.driver.delete_zone(zone)) def test_delete_record(self): zone = self.driver.list_zones()[0] record = self.driver.list_records(zone)[0] self.assertTrue(self.driver.delete_record(record))