libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [09/14] libcloud git commit: Implement (inefficient) get_zone and add tests for it.
Date Sun, 06 Dec 2015 06:32:47 GMT
Implement (inefficient) get_zone and add tests for it.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/66ff9d46
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/66ff9d46
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/66ff9d46

Branch: refs/heads/trunk
Commit: 66ff9d4608d09cf63a71ae37ac01f6ba4b8aa41a
Parents: b85a9b6
Author: Tomaz Muraus <tomaz@tomaz.me>
Authored: Sun Dec 6 13:36:56 2015 +0800
Committer: Tomaz Muraus <tomaz@tomaz.me>
Committed: Sun Dec 6 13:36:56 2015 +0800

----------------------------------------------------------------------
 libcloud/dns/drivers/cloudflare.py   | 12 +++++++++++-
 libcloud/test/dns/test_cloudflare.py | 10 ++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/66ff9d46/libcloud/dns/drivers/cloudflare.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/cloudflare.py b/libcloud/dns/drivers/cloudflare.py
index f901d30..d12c122 100644
--- a/libcloud/dns/drivers/cloudflare.py
+++ b/libcloud/dns/drivers/cloudflare.py
@@ -156,6 +156,17 @@ class CloudFlareDNSDriver(DNSDriver):
         records = self._to_records(zone=zone, data=data)
         return records
 
+    def get_zone(self, zone_id):
+        # TODO: This is not efficient
+        zones = self.list_zones()
+
+        try:
+            zone = [z for z in zones if z.id == zone_id][0]
+        except IndexError:
+            raise ZoneDoesNotExistError(value='', driver=self, zone_id=zone_id)
+
+        return zone
+
     def create_record(self, name, zone, type, data, extra=None):
         extra = extra or {}
         params = {'name': name, 'z': zone.domain, 'type': type,
@@ -366,7 +377,6 @@ class CloudFlareDNSDriver(DNSDriver):
         return zones
 
     def _to_zone(self, item):
-        zone_type = item.get('zone_type', '').lower()
         type = 'master'
 
         extra = {}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/66ff9d46/libcloud/test/dns/test_cloudflare.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_cloudflare.py b/libcloud/test/dns/test_cloudflare.py
index f1ebba5..abb99c9 100644
--- a/libcloud/test/dns/test_cloudflare.py
+++ b/libcloud/test/dns/test_cloudflare.py
@@ -76,6 +76,16 @@ class CloudFlareDNSDriverTestCase(unittest.TestCase):
         for attribute_name in RECORD_EXTRA_ATTRIBUTES:
             self.assertTrue(attribute_name in record.extra)
 
+    def test_get_zone(self):
+        zone = self.driver.get_zone(zone_id='1234')
+        self.assertEqual(zone.id, '1234')
+        self.assertEqual(zone.domain, 'example.com')
+        self.assertEqual(zone.type, 'master')
+
+    def test_get_zone_zone_doesnt_exist(self):
+        self.assertRaises(ZoneDoesNotExistError, self.driver.get_zone,
+                          zone_id='doenstexist')
+
     def test_create_record(self):
         zone = self.driver.list_zones()[0]
         record = self.driver.create_record(name='test5', zone=zone, type='A',


Mime
View raw message