You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by se...@apache.org on 2016/01/13 14:24:17 UTC
libcloud git commit: auroradns: Further improve unit tests
Repository: libcloud
Updated Branches:
refs/heads/trunk 391887a87 -> c37f15fba
auroradns: Further improve unit tests
Signed-off-by: Sebastien Goasguen <ru...@gmail.com>
This closes #679
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/c37f15fb
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/c37f15fb
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/c37f15fb
Branch: refs/heads/trunk
Commit: c37f15fba4caec4a5a3b8cc8e1bd7317222a1368
Parents: 391887a
Author: Wido den Hollander <wi...@widodh.nl>
Authored: Fri Jan 8 13:32:20 2016 +0100
Committer: Sebastien Goasguen <ru...@gmail.com>
Committed: Wed Jan 13 14:23:51 2016 +0100
----------------------------------------------------------------------
CHANGES.rst | 4 +
libcloud/dns/drivers/auroradns.py | 4 +
.../dns/fixtures/auroradns/zone_create.json | 11 ++
.../fixtures/auroradns/zone_example_com.json | 11 ++
.../zone_example_com_record_localhost.json | 12 ++
.../auroradns/zone_example_com_records.json | 38 ++++
.../test/dns/fixtures/auroradns/zone_list.json | 24 +++
libcloud/test/dns/test_auroradns.py | 184 ++++++++++++++++++-
8 files changed, 281 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/c37f15fb/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index dc26a13..ed5e407 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -49,6 +49,10 @@ DNS
(GITHUB-675)
[Wido den Hollander]
+- Improve unit tests of Aurora DNS driver
+ (GITHUB-679)
+ [Wido den Hollander]
+
Changes with Apache Libcloud 0.20.0
-----------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/c37f15fb/libcloud/dns/drivers/auroradns.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/auroradns.py b/libcloud/dns/drivers/auroradns.py
index e051d0d..b7ec55b 100644
--- a/libcloud/dns/drivers/auroradns.py
+++ b/libcloud/dns/drivers/auroradns.py
@@ -140,6 +140,7 @@ class AuroraDNSDriver(DNSDriver):
return zones
def list_records(self, zone):
+ self.connection.set_context({'resource': 'zone', 'id': zone.id})
records = []
res = self.connection.request('/zones/%s/records' % zone.id)
@@ -192,13 +193,16 @@ class AuroraDNSDriver(DNSDriver):
return self.__res_to_record(zone, record)
def delete_zone(self, zone):
+ self.connection.set_context({'resource': 'zone', 'id': zone.id})
self.connection.request('/zones/%s' % zone.id, method='DELETE')
+ return True
def delete_record(self, record):
self.connection.set_context({'resource': 'record', 'id': record.id})
self.connection.request('/zones/%s/records/%s' % (record.zone.id,
record.id),
method='DELETE')
+ return True
def update_record(self, record, name, type, data, extra):
rdata = {}
http://git-wip-us.apache.org/repos/asf/libcloud/blob/c37f15fb/libcloud/test/dns/fixtures/auroradns/zone_create.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/auroradns/zone_create.json b/libcloud/test/dns/fixtures/auroradns/zone_create.json
new file mode 100644
index 0000000..5f3694a
--- /dev/null
+++ b/libcloud/test/dns/fixtures/auroradns/zone_create.json
@@ -0,0 +1,11 @@
+ {
+ "created":"2015-05-21T13:51:12Z",
+ "id":"ffb62570-8414-4578-a346-526b44e320b7",
+ "account_id": "7be65324-6e97-4b73-9427-0f4abcf7d216",
+ "cluster_id": "734f21f4-765e-4fea-b571-eedef73b20c5",
+ "name":"example.com",
+ "servers":[
+ "ns1.auroradns.eu",
+ "ns2.auroradns.info"
+ ]
+ }
http://git-wip-us.apache.org/repos/asf/libcloud/blob/c37f15fb/libcloud/test/dns/fixtures/auroradns/zone_example_com.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/auroradns/zone_example_com.json b/libcloud/test/dns/fixtures/auroradns/zone_example_com.json
new file mode 100644
index 0000000..5f3694a
--- /dev/null
+++ b/libcloud/test/dns/fixtures/auroradns/zone_example_com.json
@@ -0,0 +1,11 @@
+ {
+ "created":"2015-05-21T13:51:12Z",
+ "id":"ffb62570-8414-4578-a346-526b44e320b7",
+ "account_id": "7be65324-6e97-4b73-9427-0f4abcf7d216",
+ "cluster_id": "734f21f4-765e-4fea-b571-eedef73b20c5",
+ "name":"example.com",
+ "servers":[
+ "ns1.auroradns.eu",
+ "ns2.auroradns.info"
+ ]
+ }
http://git-wip-us.apache.org/repos/asf/libcloud/blob/c37f15fb/libcloud/test/dns/fixtures/auroradns/zone_example_com_record_localhost.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/auroradns/zone_example_com_record_localhost.json b/libcloud/test/dns/fixtures/auroradns/zone_example_com_record_localhost.json
new file mode 100644
index 0000000..baf7fdf
--- /dev/null
+++ b/libcloud/test/dns/fixtures/auroradns/zone_example_com_record_localhost.json
@@ -0,0 +1,12 @@
+{
+ "id": "5592f1ff",
+ "content": "127.0.0.1",
+ "disabled": false,
+ "health_check_id": null,
+ "name": "localhost",
+ "prio": null,
+ "ttl": 900,
+ "type": "A",
+ "created": "2015-08-07T13:56:51Z",
+ "modified": "2015-08-07T14:11:40Z"
+}
http://git-wip-us.apache.org/repos/asf/libcloud/blob/c37f15fb/libcloud/test/dns/fixtures/auroradns/zone_example_com_records.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/auroradns/zone_example_com_records.json b/libcloud/test/dns/fixtures/auroradns/zone_example_com_records.json
new file mode 100644
index 0000000..c10aa1b
--- /dev/null
+++ b/libcloud/test/dns/fixtures/auroradns/zone_example_com_records.json
@@ -0,0 +1,38 @@
+[
+ {
+ "content":"ns1.auroradns.eu admin.auroradns.eu 2015021901 86400 7200 604800 300",
+ "created":"2015-08-07T13:56:51Z",
+ "disabled":false,
+ "health_check_id":null,
+ "id":"8f4a27b2-0b15-4ed7-b652-813b23c2027f",
+ "modified":"2015-08-07T14:11:40Z",
+ "name":"",
+ "prio":null,
+ "ttl":3600,
+ "type":"SOA"
+ },
+ {
+ "content":"ns1.auroradns.eu",
+ "created":"2015-08-07T13:56:50Z",
+ "disabled":false,
+ "health_check_id":null,
+ "id":"4d8aaffc-2e43-49c6-82cc-a26d01a159bc",
+ "modified":"2015-08-07T14:11:40Z",
+ "name":"",
+ "prio":null,
+ "ttl":3600,
+ "type":"NS"
+ },
+ {
+ "content":"109.72.87.137",
+ "created":"2015-08-07T13:56:50Z",
+ "disabled":false,
+ "health_check_id":"aecad772-9234-4722-9a05-66ad5ff6a5b0",
+ "id":"30245a1a-5569-4136-900f-864f088c60ee",
+ "modified":"2015-08-10T14:10:17Z",
+ "name":"smtp",
+ "prio":null,
+ "ttl":3600,
+ "type":"A"
+ }
+]
http://git-wip-us.apache.org/repos/asf/libcloud/blob/c37f15fb/libcloud/test/dns/fixtures/auroradns/zone_list.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/auroradns/zone_list.json b/libcloud/test/dns/fixtures/auroradns/zone_list.json
new file mode 100644
index 0000000..c96e113
--- /dev/null
+++ b/libcloud/test/dns/fixtures/auroradns/zone_list.json
@@ -0,0 +1,24 @@
+[
+ {
+ "created":"2015-05-21T13:51:12Z",
+ "id":"ffb62570-8414-4578-a346-526b44e320b7",
+ "account_id": "7be65324-6e97-4b73-9427-0f4abcf7d216",
+ "cluster_id": "734f21f4-765e-4fea-b571-eedef73b20c5",
+ "name":"auroradns1.eu",
+ "servers":[
+ "ns1.auroradns.eu",
+ "ns2.auroradns.info"
+ ]
+ },
+ {
+ "created":"2015-07-07T08:15:14Z",
+ "id":"e3c012266-72e5-48a1-ad3d-ffa7daa06dc5",
+ "account_id": "78971987-f0a0-4714-8926-5d9206601aa9",
+ "cluster_id": "d842505b-8dd9-4597-a34d-93fde6b61818",
+ "name":"auroradns2.nl",
+ "servers":[
+ "ns1.auroradns.eu",
+ "ns2.auroradns.info"
+ ]
+ }
+]
http://git-wip-us.apache.org/repos/asf/libcloud/blob/c37f15fb/libcloud/test/dns/test_auroradns.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_auroradns.py b/libcloud/test/dns/test_auroradns.py
index afd9b10..6004650 100644
--- a/libcloud/test/dns/test_auroradns.py
+++ b/libcloud/test/dns/test_auroradns.py
@@ -13,20 +13,27 @@
# See the License for the specific language governing permissions and
import sys
-import unittest
+import json
from libcloud.dns.drivers.auroradns import AuroraDNSDriver
from libcloud.dns.types import RecordType
-from libcloud.test import LibcloudTestCase, MockHttpTestCase
-from libcloud.test.secrets import DNS_PARAMS_AURORADNS
+from libcloud.dns.types import ZoneDoesNotExistError
+from libcloud.dns.types import ZoneAlreadyExistsError
+from libcloud.dns.types import RecordDoesNotExistError
+from libcloud.dns.base import Zone
+from libcloud.test import LibcloudTestCase
+from libcloud.test import MockHttpTestCase
+from libcloud.test import unittest
from libcloud.test.file_fixtures import DNSFileFixtures
+from libcloud.test.secrets import DNS_PARAMS_AURORADNS
+from libcloud.utils.py3 import httplib
class AuroraDNSDriverTests(LibcloudTestCase):
def setUp(self):
- AuroraDNSDriver.connectionCls.conn_classes = \
- (None, AuroraDNSDriverMockHttp)
+ AuroraDNSDriver.connectionCls.conn_classes = (None,
+ AuroraDNSDriverMockHttp)
AuroraDNSDriverMockHttp.type = None
self.driver = AuroraDNSDriver(*DNS_PARAMS_AURORADNS)
@@ -47,17 +54,180 @@ class AuroraDNSDriverTests(LibcloudTestCase):
param: params[param]
}
- data = self.driver._AuroraDNSDriver__merge_extra_data(rdata,
- extra)
+ data = self.driver._AuroraDNSDriver__merge_extra_data(rdata, extra)
self.assertEqual(data['content'], '127.0.0.1')
self.assertEqual(data['type'], RecordType.A)
self.assertEqual(data[param], params[param])
self.assertEqual(data['name'], 'localhost')
+ def test_list_zones(self):
+ zones = self.driver.list_zones()
+ self.assertEqual(len(zones), 2)
+
+ def test_create_zone(self):
+ zone = self.driver.create_zone('example.com')
+ self.assertEquals(zone.domain, 'example.com')
+
+ def test_get_zone(self):
+ zone = self.driver.get_zone('example.com')
+ self.assertEquals(zone.domain, 'example.com')
+ self.assertEquals(zone.id, 'ffb62570-8414-4578-a346-526b44e320b7')
+
+ def test_delete_zone(self):
+ zone = self.driver.get_zone('example.com')
+ self.assertTrue(self.driver.delete_zone(zone))
+
+ def test_create_record(self):
+ zone = self.driver.get_zone('example.com')
+ record = zone.create_record(name='localhost',
+ type=RecordType.A,
+ data='127.0.0.1',
+ extra={'ttl': 900})
+ self.assertEquals(record.id, '5592f1ff')
+ self.assertEquals(record.name, 'localhost')
+ self.assertEquals(record.data, '127.0.0.1')
+ self.assertEquals(record.type, RecordType.A)
+ self.assertEquals(record.extra['ttl'], 900)
+
+ def test_get_record(self):
+ zone = self.driver.get_zone('example.com')
+ record = self.driver.get_record(zone.id, '5592f1ff')
+ self.assertEquals(record.id, '5592f1ff')
+ self.assertEquals(record.name, 'localhost')
+ self.assertEquals(record.data, '127.0.0.1')
+ self.assertEquals(record.type, RecordType.A)
+ self.assertEquals(record.extra['ttl'], 900)
+ self.assertEquals(record.extra['prio'], None)
+
+ def test_update_record(self):
+ ttl = 900
+ zone = self.driver.get_zone('example.com')
+ record = self.driver.get_record(zone.id, '5592f1ff')
+ record = record.update(extra={'ttl': ttl})
+ self.assertEquals(record.extra['ttl'], ttl)
+
+ def test_delete_record(self):
+ zone = self.driver.get_zone('example.com')
+ record = self.driver.get_record(zone.id, '5592f1ff')
+ self.assertTrue(record.delete())
+
+ def test_list_records(self):
+ zone = self.driver.get_zone('example.com')
+ for record in zone.list_records():
+ self.assertEqual(record.extra['ttl'], 3600)
+ self.assertEqual(record.extra['disabled'], False)
+
+ def test_get_zone_non_exist(self):
+ try:
+ self.driver.get_zone('nonexists.example.com')
+ self.fail('expected a ZoneDoesNotExistError')
+ except ZoneDoesNotExistError:
+ pass
+ except:
+ raise
+
+ def test_delete_zone_non_exist(self):
+ try:
+ self.driver.delete_zone(Zone(id=1, domain='nonexists.example.com',
+ type='NATIVE', driver=AuroraDNSDriver,
+ ttl=3600))
+ self.fail('expected a ZoneDoesNotExistError')
+ except ZoneDoesNotExistError:
+ pass
+ except:
+ raise
+
+ def test_create_zone_already_exist(self):
+ try:
+ self.driver.create_zone('exists.example.com')
+ self.fail('expected a ZoneAlreadyExistsError')
+ except ZoneAlreadyExistsError:
+ pass
+ except:
+ raise
+
+ def test_list_records_non_exist(self):
+ try:
+ self.driver.list_records(Zone(id=1, domain='nonexists.example.com',
+ type='NATIVE', driver=AuroraDNSDriver,
+ ttl=3600))
+ self.fail('expected a ZoneDoesNotExistError')
+ except ZoneDoesNotExistError:
+ pass
+ except:
+ raise
+
+ def test_get_record_non_exist(self):
+ try:
+ self.driver.get_record(1, 1)
+ self.fail('expected a RecordDoesNotExistError')
+ except RecordDoesNotExistError:
+ pass
+ except:
+ raise
+
class AuroraDNSDriverMockHttp(MockHttpTestCase):
fixtures = DNSFileFixtures('auroradns')
+ def _zones(self, method, url, body, headers):
+ if method == 'POST':
+ body_json = json.loads(body)
+ if body_json['name'] == 'exists.example.com':
+ return (httplib.CONFLICT, body, {},
+ httplib.responses[httplib.CONFLICT])
+ body = self.fixtures.load('zone_example_com.json')
+ else:
+ body = self.fixtures.load('zone_list.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _zones_example_com(self, method, url, body, headers):
+ body = None
+ if method == 'GET':
+ body = self.fixtures.load('zone_example_com.json')
+
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _zones_nonexists_example_com(self, method, url, body, headers):
+ return (httplib.NOT_FOUND, body, {},
+ httplib.responses[httplib.NOT_FOUND])
+
+ def _zones_ffb62570_8414_4578_a346_526b44e320b7(self, method, url, body,
+ headers):
+ body = self.fixtures.load('zone_example_com.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _zones_ffb62570_8414_4578_a346_526b44e320b7_records(self, method, url,
+ body, headers):
+ if method == 'POST':
+ body = self.fixtures.load('zone_example_com_record_localhost.json')
+ else:
+ body = self.fixtures.load('zone_example_com_records.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _zones_1(self, method, url, body, headers):
+ return (httplib.NOT_FOUND, body, {},
+ httplib.responses[httplib.NOT_FOUND])
+
+ def _zones_1_records(self, method, url, body, headers):
+ return (httplib.NOT_FOUND, body, {},
+ httplib.responses[httplib.NOT_FOUND])
+
+ def _zones_1_records_1(self, method, url, body, headers):
+ return (httplib.NOT_FOUND, body, {},
+ httplib.responses[httplib.NOT_FOUND])
+
+ def _zones_ffb62570_8414_4578_a346_526b44e320b7_records_5592f1ff(self,
+ method,
+ url,
+ body,
+ headers):
+ body = None
+ if method == 'GET':
+ body = self.fixtures.load('zone_example_com_record_localhost.json')
+
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
if __name__ == '__main__':
sys.exit(unittest.main())