コード例 #1
0
ファイル: test_softlayer.py プロジェクト: TamerB/simple-paas
class SoftLayerTests(unittest.TestCase):

    def setUp(self):
        SoftLayerDNSDriver.connectionCls.conn_classes = (
            SoftLayerDNSMockHttp, SoftLayerDNSMockHttp)
        SoftLayerDNSMockHttp.type = None
        self.driver = SoftLayerDNSDriver(*SOFTLAYER_PARAMS)

    def test_create_zone(self):
        zone = self.driver.create_zone(domain='bar.com')
        self.assertEqual(zone.id, '123')
        self.assertEqual(zone.domain, 'bar.com')

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

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

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

    def test_get_zone_does_not_exist(self):
        SoftLayerDNSMockHttp.type = 'ZONE_DOES_NOT_EXIST'

        with self.assertRaises(ZoneDoesNotExistError):
            self.driver.get_zone(zone_id='333')

    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]

        SoftLayerDNSMockHttp.type = 'ZONE_DOES_NOT_EXIST'

        with self.assertRaises(ZoneDoesNotExistError):
            self.driver.delete_zone(zone=zone)

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

        records = zone.list_records()

        self.assertEqual(records[0].id, '50772366')
        self.assertEqual(records[0].type, RecordType.SOA)
        self.assertEqual(records[0].data, 'ns1.softlayer.com.')
        self.assertEqual(
            records[0].extra,
            {
                'mxPriority': '',
                'expire': 604800,
                'retry': 300,
                'refresh': 3600,
                'ttl': 86400
            }
        )
        self.assertEqual(records[1].id, '50772367')
        self.assertEqual(records[1].type, RecordType.NS)
        self.assertEqual(records[1].data, 'ns1.softlayer.com.')

        self.assertEqual(records[2].id, '50772368')
        self.assertEqual(records[2].type, RecordType.NS)
        self.assertEqual(records[2].data, 'ns2.softlayer.com.')

        self.assertEqual(records[3].id, '50772365')
        self.assertEqual(records[3].type, RecordType.A)
        self.assertEqual(records[3].data, '127.0.0.1')

    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_get_record(self):
        record = self.driver.get_record(zone_id='123', record_id='50772366')

        self.assertEqual(record.id, '50772366')
        self.assertEqual(record.type, RecordType.SOA)
        self.assertEqual(record.data, 'ns1.softlayer.com.')

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

        with self.assertRaises(RecordDoesNotExistError):
            self.driver.get_record(zone_id='123',
                                   record_id='1')

    def test_delete_record(self):
        record = self.driver.get_record(zone_id='123', record_id='50772366')
        status = self.driver.delete_record(record=record)
        self.assertTrue(status)

    def test_delete_record_does_not_exist(self):
        record = self.driver.get_record(zone_id='123', record_id='50772366')

        SoftLayerDNSMockHttp.type = 'RECORD_DOES_NOT_EXIST'

        with self.assertRaises(RecordDoesNotExistError):
            self.driver.delete_record(record=record)

    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, '50772870')
        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]

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

        self.assertEqual(record.data, 'ns1.softlayer.com.')

        self.assertEqual(updated_record.id, '123')
        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, '1.1.1.1')
コード例 #2
0
class SoftLayerTests(unittest.TestCase):
    def setUp(self):
        SoftLayerDNSDriver.connectionCls.conn_class = SoftLayerDNSMockHttp
        SoftLayerDNSMockHttp.type = None
        self.driver = SoftLayerDNSDriver(*SOFTLAYER_PARAMS)

    def test_create_zone(self):
        zone = self.driver.create_zone(domain="bar.com")
        self.assertEqual(zone.id, "123")
        self.assertEqual(zone.domain, "bar.com")

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

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

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

    def test_get_zone_does_not_exist(self):
        SoftLayerDNSMockHttp.type = "ZONE_DOES_NOT_EXIST"

        with self.assertRaises(ZoneDoesNotExistError):
            self.driver.get_zone(zone_id="333")

    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]

        SoftLayerDNSMockHttp.type = "ZONE_DOES_NOT_EXIST"

        with self.assertRaises(ZoneDoesNotExistError):
            self.driver.delete_zone(zone=zone)

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

        records = zone.list_records()

        self.assertEqual(records[0].id, "50772366")
        self.assertEqual(records[0].type, RecordType.SOA)
        self.assertEqual(records[0].data, "ns1.softlayer.com.")
        self.assertEqual(
            records[0].extra,
            {
                "mxPriority": "",
                "expire": 604800,
                "retry": 300,
                "refresh": 3600,
                "ttl": 86400,
            },
        )
        self.assertEqual(records[1].id, "50772367")
        self.assertEqual(records[1].type, RecordType.NS)
        self.assertEqual(records[1].data, "ns1.softlayer.com.")

        self.assertEqual(records[2].id, "50772368")
        self.assertEqual(records[2].type, RecordType.NS)
        self.assertEqual(records[2].data, "ns2.softlayer.com.")

        self.assertEqual(records[3].id, "50772365")
        self.assertEqual(records[3].type, RecordType.A)
        self.assertEqual(records[3].data, "127.0.0.1")

    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_get_record(self):
        record = self.driver.get_record(zone_id="123", record_id="50772366")

        self.assertEqual(record.id, "50772366")
        self.assertEqual(record.type, RecordType.SOA)
        self.assertEqual(record.data, "ns1.softlayer.com.")

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

        with self.assertRaises(RecordDoesNotExistError):
            self.driver.get_record(zone_id="123", record_id="1")

    def test_delete_record(self):
        record = self.driver.get_record(zone_id="123", record_id="50772366")
        status = self.driver.delete_record(record=record)
        self.assertTrue(status)

    def test_delete_record_does_not_exist(self):
        record = self.driver.get_record(zone_id="123", record_id="50772366")

        SoftLayerDNSMockHttp.type = "RECORD_DOES_NOT_EXIST"

        with self.assertRaises(RecordDoesNotExistError):
            self.driver.delete_record(record=record)

    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, "50772870")
        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]

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

        self.assertEqual(record.data, "ns1.softlayer.com.")

        self.assertEqual(updated_record.id, "123")
        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, "1.1.1.1")
コード例 #3
0
class SoftLayerTests(unittest.TestCase):
    def setUp(self):
        SoftLayerDNSDriver.connectionCls.conn_classes = (SoftLayerDNSMockHttp,
                                                         SoftLayerDNSMockHttp)
        SoftLayerDNSMockHttp.type = None
        self.driver = SoftLayerDNSDriver(*SOFTLAYER_PARAMS)

    def test_create_zone(self):
        zone = self.driver.create_zone(domain='bar.com')
        self.assertEqual(zone.id, '123')
        self.assertEqual(zone.domain, 'bar.com')

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

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

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

    def test_get_zone_does_not_exist(self):
        SoftLayerDNSMockHttp.type = 'ZONE_DOES_NOT_EXIST'

        with self.assertRaises(ZoneDoesNotExistError):
            self.driver.get_zone(zone_id='333')

    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]

        SoftLayerDNSMockHttp.type = 'ZONE_DOES_NOT_EXIST'

        with self.assertRaises(ZoneDoesNotExistError):
            self.driver.delete_zone(zone=zone)

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

        records = zone.list_records()

        self.assertEqual(records[0].id, '50772366')
        self.assertEqual(records[0].type, RecordType.SOA)
        self.assertEqual(records[0].data, 'ns1.softlayer.com.')
        self.assertEqual(
            records[0].extra, {
                'mxPriority': '',
                'expire': 604800,
                'retry': 300,
                'refresh': 3600,
                'ttl': 86400
            })
        self.assertEqual(records[1].id, '50772367')
        self.assertEqual(records[1].type, RecordType.NS)
        self.assertEqual(records[1].data, 'ns1.softlayer.com.')

        self.assertEqual(records[2].id, '50772368')
        self.assertEqual(records[2].type, RecordType.NS)
        self.assertEqual(records[2].data, 'ns2.softlayer.com.')

        self.assertEqual(records[3].id, '50772365')
        self.assertEqual(records[3].type, RecordType.A)
        self.assertEqual(records[3].data, '127.0.0.1')

    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_get_record(self):
        record = self.driver.get_record(zone_id='123', record_id='50772366')

        self.assertEqual(record.id, '50772366')
        self.assertEqual(record.type, RecordType.SOA)
        self.assertEqual(record.data, 'ns1.softlayer.com.')

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

        with self.assertRaises(RecordDoesNotExistError):
            self.driver.get_record(zone_id='123', record_id='1')

    def test_delete_record(self):
        record = self.driver.get_record(zone_id='123', record_id='50772366')
        status = self.driver.delete_record(record=record)
        self.assertTrue(status)

    def test_delete_record_does_not_exist(self):
        record = self.driver.get_record(zone_id='123', record_id='50772366')

        SoftLayerDNSMockHttp.type = 'RECORD_DOES_NOT_EXIST'

        with self.assertRaises(RecordDoesNotExistError):
            self.driver.delete_record(record=record)

    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, '50772870')
        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]

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

        self.assertEqual(record.data, 'ns1.softlayer.com.')

        self.assertEqual(updated_record.id, '123')
        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, '1.1.1.1')