Exemplo n.º 1
0
class GandiTests(unittest.TestCase):

    def setUp(self):
        GandiDNSDriver.connectionCls.conn_class = GandiMockHttp
        GandiMockHttp.type = None
        self.driver = GandiDNSDriver(*DNS_GANDI)

    def test_list_record_types(self):
        record_types = self.driver.list_record_types()
        self.assertEqual(len(record_types), 10)
        self.assertTrue(RecordType.A in record_types)

    def test_list_zones(self):
        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 5)

        zone = zones[0]
        self.assertEqual(zone.id, '47234')
        self.assertEqual(zone.type, 'master')
        self.assertEqual(zone.domain, 't.com')

    def test_list_records(self):
        zone = self.driver.list_zones()[0]
        records = self.driver.list_records(zone=zone)
        self.assertEqual(len(records), 4)

        record = records[1]
        self.assertEqual(record.name, 'www')
        self.assertEqual(record.id, 'A:www')
        self.assertEqual(record.type, RecordType.A)
        self.assertEqual(record.data, '208.111.35.173')

        record = records[3]
        self.assertEqual(record.name, '')
        self.assertEqual(record.id, 'MX:')
        self.assertEqual(record.type, RecordType.MX)
        self.assertEqual(record.data, 'aspmx.l.google.com')
        self.assertEqual(record.extra['priority'], 15)
        self.assertEqual(record.extra['ttl'], 86400)

    def test_get_zone(self):
        zone = self.driver.get_zone(zone_id='47234')
        self.assertEqual(zone.id, '47234')
        self.assertEqual(zone.type, 'master')
        self.assertEqual(zone.domain, 't.com')

    def test_get_record(self):
        record = self.driver.get_record(zone_id='47234',
                                        record_id='CNAME:t.com')
        self.assertEqual(record.name, 'wibble')
        self.assertEqual(record.type, RecordType.CNAME)
        self.assertEqual(record.data, 't.com')

    def test_list_records_zone_does_not_exist(self):
        zone = self.driver.list_zones()[0]

        GandiMockHttp.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_does_not_exist(self):
        GandiMockHttp.type = 'ZONE_DOES_NOT_EXIST'

        try:
            self.driver.get_zone(zone_id='47234')
        except ZoneDoesNotExistError:
            e = sys.exc_info()[1]
            self.assertEqual(e.zone_id, '47234')
        else:
            self.fail('Exception was not thrown')

    def test_get_record_zone_does_not_exist(self):
        GandiMockHttp.type = 'ZONE_DOES_NOT_EXIST'

        try:
            self.driver.get_record(zone_id='4444', record_id='CNAME:t.com')
        except ZoneDoesNotExistError:
            pass
        else:
            self.fail('Exception was not thrown')

    def test_get_record_record_does_not_exist(self):
        GandiMockHttp.type = 'RECORD_DOES_NOT_EXIST'

        try:
            self.driver.get_record(zone_id='47234',
                                   record_id='CNAME:t.com')
        except RecordDoesNotExistError:
            pass
        else:
            self.fail('Exception was not thrown')

    def test_create_zone(self):
        zone = self.driver.create_zone(domain='t.com', type='master',
                                       ttl=None, extra=None)
        self.assertEqual(zone.id, '47234')
        self.assertEqual(zone.domain, 't.com')

    def test_update_zone(self):
        zone = self.driver.get_zone(zone_id='47234')
        zone = self.driver.update_zone(zone, domain='t.com')
        self.assertEqual(zone.id, '47234')
        self.assertEqual(zone.type, 'master')
        self.assertEqual(zone.domain, 't.com')

    def test_create_record(self):
        zone = self.driver.list_zones()[0]
        record = self.driver.create_record(
            name='www', zone=zone,
            type=RecordType.A, data='127.0.0.1',
            extra={'ttl': 30}
        )

        self.assertEqual(record.id, 'A:www')
        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(self):
        zone = self.driver.list_zones()[0]
        record = self.driver.list_records(zone=zone)[1]

        params = {
            'record': record,
            'name': 'www',
            'type': RecordType.A,
            'data': '127.0.0.1',
            'extra': {'ttl': 30}}
        updated_record = self.driver.update_record(**params)

        self.assertEqual(record.data, '208.111.35.173')

        self.assertEqual(updated_record.id, 'A:www')
        self.assertEqual(updated_record.name, 'www')
        self.assertEqual(updated_record.zone, record.zone)
        self.assertEqual(updated_record.type, RecordType.A)
        self.assertEqual(updated_record.data, '127.0.0.1')

    def test_delete_zone(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]

        GandiMockHttp.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(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]
        GandiMockHttp.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')
Exemplo n.º 2
0
class GandiTests(unittest.TestCase):
    def setUp(self):
        GandiDNSDriver.connectionCls.conn_classes = (GandiMockHttp, GandiMockHttp)
        GandiMockHttp.type = None
        self.driver = GandiDNSDriver(*DNS_GANDI)

    def test_list_record_types(self):
        record_types = self.driver.list_record_types()
        self.assertEqual(len(record_types), 10)
        self.assertTrue(RecordType.A in record_types)

    def test_list_zones(self):
        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 5)

        zone = zones[0]
        self.assertEqual(zone.id, "47234")
        self.assertEqual(zone.type, "master")
        self.assertEqual(zone.domain, "t.com")

    def test_list_records(self):
        zone = self.driver.list_zones()[0]
        records = self.driver.list_records(zone=zone)
        self.assertEqual(len(records), 3)

        record = records[1]
        self.assertEqual(record.name, "www")
        self.assertEqual(record.id, "A:www")
        self.assertEqual(record.type, RecordType.A)
        self.assertEqual(record.data, "208.111.35.173")

    def test_get_zone(self):
        zone = self.driver.get_zone(zone_id="47234")
        self.assertEqual(zone.id, "47234")
        self.assertEqual(zone.type, "master")
        self.assertEqual(zone.domain, "t.com")

    def test_get_record(self):
        record = self.driver.get_record(zone_id="47234", record_id="CNAME:t.com")
        self.assertEqual(record.name, "wibble")
        self.assertEqual(record.type, RecordType.CNAME)
        self.assertEqual(record.data, "t.com")

    def test_list_records_zone_does_not_exist(self):
        zone = self.driver.list_zones()[0]

        GandiMockHttp.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_does_not_exist(self):
        GandiMockHttp.type = "ZONE_DOES_NOT_EXIST"

        try:
            self.driver.get_zone(zone_id="47234")
        except ZoneDoesNotExistError:
            e = sys.exc_info()[1]
            self.assertEqual(e.zone_id, "47234")
        else:
            self.fail("Exception was not thrown")

    def test_get_record_zone_does_not_exist(self):
        GandiMockHttp.type = "ZONE_DOES_NOT_EXIST"

        try:
            self.driver.get_record(zone_id="4444", record_id="CNAME:t.com")
        except ZoneDoesNotExistError:
            pass
        else:
            self.fail("Exception was not thrown")

    def test_get_record_record_does_not_exist(self):
        GandiMockHttp.type = "RECORD_DOES_NOT_EXIST"

        try:
            self.driver.get_record(zone_id="47234", record_id="CNAME:t.com")
        except RecordDoesNotExistError:
            pass
        else:
            self.fail("Exception was not thrown")

    def test_create_zone(self):
        zone = self.driver.create_zone(domain="t.com", type="master", ttl=None, extra=None)
        self.assertEqual(zone.id, "47234")
        self.assertEqual(zone.domain, "t.com")

    def test_update_zone(self):
        zone = self.driver.get_zone(zone_id="47234")
        zone = self.driver.update_zone(zone, domain="t.com")
        self.assertEqual(zone.id, "47234")
        self.assertEqual(zone.type, "master")
        self.assertEqual(zone.domain, "t.com")

    def test_create_record(self):
        zone = self.driver.list_zones()[0]
        record = self.driver.create_record(
            name="www", zone=zone, type=RecordType.A, data="127.0.0.1", extra={"ttl": 30}
        )

        self.assertEqual(record.id, "A:www")
        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(self):
        zone = self.driver.list_zones()[0]
        record = self.driver.list_records(zone=zone)[1]

        params = {"record": record, "name": "www", "type": RecordType.A, "data": "127.0.0.1", "extra": {"ttl": 30}}
        updated_record = self.driver.update_record(**params)

        self.assertEqual(record.data, "208.111.35.173")

        self.assertEqual(updated_record.id, "A:www")
        self.assertEqual(updated_record.name, "www")
        self.assertEqual(updated_record.zone, record.zone)
        self.assertEqual(updated_record.type, RecordType.A)
        self.assertEqual(updated_record.data, "127.0.0.1")

    def test_delete_zone(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]

        GandiMockHttp.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(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]
        GandiMockHttp.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")
Exemplo n.º 3
0
class GandiTests(unittest.TestCase):
    def setUp(self):
        GandiDNSDriver.connectionCls.conn_classes = (GandiMockHttp,
                                                     GandiMockHttp)
        GandiMockHttp.type = None
        self.driver = GandiDNSDriver(*DNS_GANDI)

    def test_list_record_types(self):
        record_types = self.driver.list_record_types()
        self.assertEqual(len(record_types), 10)
        self.assertTrue(RecordType.A in record_types)

    def test_list_zones(self):
        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 5)

        zone = zones[0]
        self.assertEqual(zone.id, '47234')
        self.assertEqual(zone.type, 'master')
        self.assertEqual(zone.domain, 't.com')

    def test_list_records(self):
        zone = self.driver.list_zones()[0]
        records = self.driver.list_records(zone=zone)
        self.assertEqual(len(records), 3)

        record = records[1]
        self.assertEqual(record.name, 'www')
        self.assertEqual(record.id, 'A:www')
        self.assertEqual(record.type, RecordType.A)
        self.assertEqual(record.data, '208.111.35.173')

    def test_get_zone(self):
        zone = self.driver.get_zone(zone_id='47234')
        self.assertEqual(zone.id, '47234')
        self.assertEqual(zone.type, 'master')
        self.assertEqual(zone.domain, 't.com')

    def test_get_record(self):
        record = self.driver.get_record(zone_id='47234',
                                        record_id='CNAME:t.com')
        self.assertEqual(record.name, 'wibble')
        self.assertEqual(record.type, RecordType.CNAME)
        self.assertEqual(record.data, 't.com')

    def test_list_records_zone_does_not_exist(self):
        zone = self.driver.list_zones()[0]

        GandiMockHttp.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_does_not_exist(self):
        GandiMockHttp.type = 'ZONE_DOES_NOT_EXIST'

        try:
            self.driver.get_zone(zone_id='47234')
        except ZoneDoesNotExistError:
            e = sys.exc_info()[1]
            self.assertEqual(e.zone_id, '47234')
        else:
            self.fail('Exception was not thrown')

    def test_get_record_zone_does_not_exist(self):
        GandiMockHttp.type = 'ZONE_DOES_NOT_EXIST'

        try:
            self.driver.get_record(zone_id='4444', record_id='CNAME:t.com')
        except ZoneDoesNotExistError:
            pass
        else:
            self.fail('Exception was not thrown')

    def test_get_record_record_does_not_exist(self):
        GandiMockHttp.type = 'RECORD_DOES_NOT_EXIST'

        try:
            self.driver.get_record(zone_id='47234', record_id='CNAME:t.com')
        except RecordDoesNotExistError:
            pass
        else:
            self.fail('Exception was not thrown')

    def test_create_zone(self):
        zone = self.driver.create_zone(domain='t.com',
                                       type='master',
                                       ttl=None,
                                       extra=None)
        self.assertEqual(zone.id, '47234')
        self.assertEqual(zone.domain, 't.com')

    def test_update_zone(self):
        zone = self.driver.get_zone(zone_id='47234')
        zone = self.driver.update_zone(zone, domain='t.com')
        self.assertEqual(zone.id, '47234')
        self.assertEqual(zone.type, 'master')
        self.assertEqual(zone.domain, 't.com')

    def test_create_record(self):
        zone = self.driver.list_zones()[0]
        record = self.driver.create_record(name='www',
                                           zone=zone,
                                           type=RecordType.A,
                                           data='127.0.0.1',
                                           extra={'ttl': 30})

        self.assertEqual(record.id, 'A:www')
        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(self):
        zone = self.driver.list_zones()[0]
        record = self.driver.list_records(zone=zone)[1]

        params = {
            'record': record,
            'name': 'www',
            'type': RecordType.A,
            'data': '127.0.0.1',
            'extra': {
                'ttl': 30
            }
        }
        updated_record = self.driver.update_record(**params)

        self.assertEqual(record.data, '208.111.35.173')

        self.assertEqual(updated_record.id, 'A:www')
        self.assertEqual(updated_record.name, 'www')
        self.assertEqual(updated_record.zone, record.zone)
        self.assertEqual(updated_record.type, RecordType.A)
        self.assertEqual(updated_record.data, '127.0.0.1')

    def test_delete_zone(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]

        GandiMockHttp.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(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]
        GandiMockHttp.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')
Exemplo n.º 4
0
class GandiTests(unittest.TestCase):
    def setUp(self):
        GandiDNSDriver.connectionCls.conn_class = GandiMockHttp
        GandiMockHttp.type = None
        self.driver = GandiDNSDriver(*DNS_GANDI)

    def test_list_record_types(self):
        record_types = self.driver.list_record_types()
        self.assertEqual(len(record_types), 10)
        self.assertTrue(RecordType.A in record_types)

    def test_list_zones(self):
        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 5)

        zone = zones[0]
        self.assertEqual(zone.id, "47234")
        self.assertEqual(zone.type, "master")
        self.assertEqual(zone.domain, "t.com")

    def test_list_records(self):
        zone = self.driver.list_zones()[0]
        records = self.driver.list_records(zone=zone)
        self.assertEqual(len(records), 4)

        record = records[1]
        self.assertEqual(record.name, "www")
        self.assertEqual(record.id, "A:www")
        self.assertEqual(record.type, RecordType.A)
        self.assertEqual(record.data, "208.111.35.173")

        record = records[3]
        self.assertEqual(record.name, "")
        self.assertEqual(record.id, "MX:")
        self.assertEqual(record.type, RecordType.MX)
        self.assertEqual(record.data, "aspmx.l.google.com")
        self.assertEqual(record.extra["priority"], 15)
        self.assertEqual(record.extra["ttl"], 86400)

    def test_get_zone(self):
        zone = self.driver.get_zone(zone_id="47234")
        self.assertEqual(zone.id, "47234")
        self.assertEqual(zone.type, "master")
        self.assertEqual(zone.domain, "t.com")

    def test_get_record(self):
        record = self.driver.get_record(zone_id="47234",
                                        record_id="CNAME:t.com")
        self.assertEqual(record.name, "wibble")
        self.assertEqual(record.type, RecordType.CNAME)
        self.assertEqual(record.data, "t.com")

    def test_list_records_zone_does_not_exist(self):
        zone = self.driver.list_zones()[0]

        GandiMockHttp.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_does_not_exist(self):
        GandiMockHttp.type = "ZONE_DOES_NOT_EXIST"

        try:
            self.driver.get_zone(zone_id="47234")
        except ZoneDoesNotExistError as e:
            self.assertEqual(e.zone_id, "47234")
        else:
            self.fail("Exception was not thrown")

    def test_get_record_zone_does_not_exist(self):
        GandiMockHttp.type = "ZONE_DOES_NOT_EXIST"

        try:
            self.driver.get_record(zone_id="4444", record_id="CNAME:t.com")
        except ZoneDoesNotExistError:
            pass
        else:
            self.fail("Exception was not thrown")

    def test_get_record_record_does_not_exist(self):
        GandiMockHttp.type = "RECORD_DOES_NOT_EXIST"

        try:
            self.driver.get_record(zone_id="47234", record_id="CNAME:t.com")
        except RecordDoesNotExistError:
            pass
        else:
            self.fail("Exception was not thrown")

    def test_create_zone(self):
        zone = self.driver.create_zone(domain="t.com",
                                       type="master",
                                       ttl=None,
                                       extra=None)
        self.assertEqual(zone.id, "47234")
        self.assertEqual(zone.domain, "t.com")

    def test_update_zone(self):
        zone = self.driver.get_zone(zone_id="47234")
        zone = self.driver.update_zone(zone, domain="t.com")
        self.assertEqual(zone.id, "47234")
        self.assertEqual(zone.type, "master")
        self.assertEqual(zone.domain, "t.com")

    def test_create_record(self):
        zone = self.driver.list_zones()[0]
        record = self.driver.create_record(
            name="www",
            zone=zone,
            type=RecordType.A,
            data="127.0.0.1",
            extra={"ttl": 30},
        )

        self.assertEqual(record.id, "A:www")
        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(self):
        zone = self.driver.list_zones()[0]
        record = self.driver.list_records(zone=zone)[1]

        params = {
            "record": record,
            "name": "www",
            "type": RecordType.A,
            "data": "127.0.0.1",
            "extra": {
                "ttl": 30
            },
        }
        updated_record = self.driver.update_record(**params)

        self.assertEqual(record.data, "208.111.35.173")

        self.assertEqual(updated_record.id, "A:www")
        self.assertEqual(updated_record.name, "www")
        self.assertEqual(updated_record.zone, record.zone)
        self.assertEqual(updated_record.type, RecordType.A)
        self.assertEqual(updated_record.data, "127.0.0.1")

    def test_delete_zone(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]

        GandiMockHttp.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(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]
        GandiMockHttp.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")