/opt/imh-python/lib/python3.9/site-packages/libcloud/test/dns
NameSizeModeActions
fixtures/-0755rm
__pycache__/-0755rm
test_auroradns.py128490644editdlrm
test_base.py49890644editdlrm
test_buddyns.py62940644editdlrm
test_cloudflare.py150930644editdlrm
test_digitalocean.py71150644editdlrm
test_dnsimple.py118140644editdlrm
test_dnspod.py108040644editdlrm
test_durabledns.py278270644editdlrm
test_gandi.py120190644editdlrm
test_gandi_live.py171550644editdlrm
test_godaddy.py72600644editdlrm
test_google.py77320644editdlrm
test_hostvirtual.py107280644editdlrm
test_linode.py139950644editdlrm
test_liquidweb.py140790644editdlrm
test_luadns.py121530644editdlrm
test_nfsn.py60180644editdlrm
test_nsone.py103090644editdlrm
test_onapp.py95380644editdlrm
test_pointdns.py335260644editdlrm
test_powerdns.py77640644editdlrm
test_rackspace.py257930644editdlrm
test_rcodezero.py85650644editdlrm
test_route53.py142130644editdlrm
test_softlayer.py98170644editdlrm
test_vultr.py128480644editdlrm
test_worldwidedns.py203830644editdlrm
test_zerigo.py145870644editdlrm
test_zonomi.py161130644editdlrm
__init__.py00644editdlrm
Edit: /opt/imh-python/lib/python3.9/site-packages/libcloud/test/dns/test_rcodezero.py (8565B)
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and import sys import unittest import json from libcloud.utils.py3 import httplib from libcloud.dns.base import Record, Zone from libcloud.dns.drivers.rcodezero import RcodeZeroDNSDriver from libcloud.dns.types import ZoneDoesNotExistError, ZoneAlreadyExistsError from libcloud.dns.types import RecordType from libcloud.test import LibcloudTestCase, MockHttp from libcloud.test.file_fixtures import DNSFileFixtures class RcodeZeroDNSTestCase(LibcloudTestCase): def setUp(self): RcodeZeroDNSDriver.connectionCls.conn_class = RcodeZeroDNSMockHttp RcodeZeroDNSMockHttp.type = None self.driver = RcodeZeroDNSDriver('mysecret') self.test_zone = Zone(id='example.at', domain='example.at', driver=self.driver, type='master', ttl=None, extra={}) self.test_record = Record(id=None, name='', data='192.0.2.1', type=RecordType.A, zone=self.test_zone, driver=self.driver, extra={}) def test_create_record(self): record = self.test_zone.create_record(name='newrecord', type=RecordType.A, data='192.0.5.4', extra={'ttl': 86400}) self.assertEqual(record.id, None) self.assertEqual(record.name, 'newrecord') self.assertEqual(record.data, '192.0.5.4') self.assertEqual(record.type, RecordType.A) self.assertEqual(record.ttl, 86400) def test_create_zone(self): extra = {"masters": ["193.0.2.2"]} zone = self.driver.create_zone( "example.at", type='slave', extra=extra) self.assertEqual(zone.id, 'example.at.') self.assertEqual(zone.domain, 'example.at') self.assertEqual(zone.type, 'slave') self.assertEqual(zone.ttl, None) def test_delete_record(self): self.assertTrue(self.test_record.delete()) def test_delete_zone(self): self.assertTrue(self.test_zone.delete()) def test_get_record(self): record = self.driver.get_record('example.at.', '12345') self.assertEqual(record, None) def test_get_zone(self): zone = self.driver.get_zone('example.at') self.assertEqual(zone.id, 'example.at') self.assertEqual(zone.domain, 'example.at') self.assertEqual(zone.type, 'master') self.assertEqual(zone.ttl, None) def test_list_record_types(self): result = self.driver.list_record_types() self.assertEqual(len(result), 25) def test_list_records(self): records = self.driver.list_records(self.test_zone) self.assertEqual(len(records), 3) def test_list_zones(self): zones = self.driver.list_zones() self.assertEqual(zones[0].id, 'example1.at') self.assertEqual(zones[0].domain, 'example1.at') self.assertEqual(zones[0].type, 'slave') self.assertEqual(zones[0].ttl, None) self.assertEqual(zones[0].extra['masters'][0], '193.0.2.2') self.assertEqual(zones[0].extra['serial'], 20180411) self.assertEqual(zones[1].id, 'example2.at') self.assertEqual(zones[1].domain, 'example2.at') self.assertEqual(zones[1].type, 'master') self.assertEqual(zones[1].ttl, None) def test_update_record(self): record = self.driver.update_record(self.test_record, name='newrecord', type=RecordType.A, data='127.0.0.1', extra={'ttl': 300}) self.assertEqual(record.id, '430059068a39501b8df5a577b1e46ad7') self.assertEqual(record.name, 'newrecord') self.assertEqual(record.data, '127.0.0.1') self.assertEqual(record.type, RecordType.A) self.assertEqual(record.ttl, 300) def test_update_zone(self): with self.assertRaises(NotImplementedError): self.driver.update_zone(self.test_zone, 'example.at') # # Test some error conditions def test_create_existing_zone(self): RcodeZeroDNSMockHttp.type = 'EXISTS' extra = {'masters': ['193.0.2.2']} with self.assertRaises(ZoneAlreadyExistsError): self.driver.create_zone( "example1.at", type='slave', extra=extra) def test_get_missing_zone(self): RcodeZeroDNSMockHttp.type = 'MISSING' with self.assertRaises(ZoneDoesNotExistError): self.driver.get_zone('example.com') def test_delete_missing_zone(self): RcodeZeroDNSMockHttp.type = 'MISSING' self.assertFalse(self.test_zone.delete()) class RcodeZeroDNSMockHttp(MockHttp): fixtures = DNSFileFixtures('rcodezero') base_headers = {'content-type': 'application/json'} def _api_v1_zones(self, method, url, body, headers): if method == 'GET': # list_zones() body = self.fixtures.load('list_zones.json') elif method == 'POST': # create_zone() # Don't bother with a fixture for this operation, because we do # nothing with the parsed body anyway. body = '' else: raise NotImplementedError('Unexpected method: %s' % method) return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _api_v1_zones_example_at(self, method, *args, **kwargs): if method == 'GET': # list_records() body = self.fixtures.load('get_zone_details.json') elif method == 'DELETE': # delete_zone() return (httplib.NO_CONTENT, '', self.base_headers, httplib.responses[httplib.NO_CONTENT]) else: raise NotImplementedError('Unexpected method: %s' % method) return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _api_v1_zones_example_at__rrsets(self, method, *args, **kwargs): return (self._api_v1_zones_example_at_rrsets(method, *args, **kwargs)) def _api_v1_zones_example_at_rrsets(self, method, *args, **kwargs): if method == 'GET': # list_records() body = self.fixtures.load('list_records.json') elif method == 'PATCH': # create/update/delete_record() # Don't bother with a fixture for these operations, because we do # nothing with the parsed body anyway. body = '' else: raise NotImplementedError('Unexpected method: %s' % method) return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _api_v1_zones_EXISTS(self, method, url, body, headers): # create_zone() is a POST. Raise on all other operations to be safe. if method != 'POST': raise NotImplementedError('Unexpected method: %s' % method) payload = json.loads(body) domain = payload['domain'] body = json.dumps({'error': "Domain '%s' already exists" % domain}) return (httplib.UNPROCESSABLE_ENTITY, body, self.base_headers, 'Unprocessable Entity') def _api_v1_zones_example_com_MISSING(self, *args, **kwargs): return (httplib.NOT_FOUND, '{"status": "failed","message": "Zone not found"}', self.base_headers, 'Unprocessable Entity') def _api_v1_zones_example_at_MISSING(self, *args, **kwargs): return (httplib.NOT_FOUND, '{"status": "failed","message": "Zone not found"}', self.base_headers, 'Unprocessable Entity') if __name__ == '__main__': sys.exit(unittest.main())