Repository: libcloud Updated Branches: refs/heads/trunk 664bb3402 -> f0072ab93
auroradns: Implement iterator for zones and records By implementing iterate_zones() and iterate_records() you can iterate over zones and records returned by the API. The list_zones() and list_records() methods simply talk to the iteration functions and create a list of it and return that. The test cases should still match since they call the list functions and those call the iterators on their turn. The test case test_list_zones() however has been expanded to iterate over the result. The test_list_records case already iterated over the results, so that verifies that the result is iteratable. Closes #829 Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/29698dee Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/29698dee Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/29698dee Branch: refs/heads/trunk Commit: 29698dee228a23b29b3bda94309fc239597ae717 Parents: 664bb34 Author: Wido den Hollander <w...@widodh.nl> Authored: Sat Jul 2 18:52:28 2016 +0200 Committer: Anthony Shaw <anthonys...@apache.org> Committed: Wed Jul 6 10:48:16 2016 +1000 ---------------------------------------------------------------------- libcloud/dns/drivers/auroradns.py | 17 ++++++++--------- libcloud/test/dns/test_auroradns.py | 2 ++ 2 files changed, 10 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/29698dee/libcloud/dns/drivers/auroradns.py ---------------------------------------------------------------------- diff --git a/libcloud/dns/drivers/auroradns.py b/libcloud/dns/drivers/auroradns.py index f0991f4..eb8a994 100644 --- a/libcloud/dns/drivers/auroradns.py +++ b/libcloud/dns/drivers/auroradns.py @@ -261,24 +261,23 @@ class AuroraDNSDriver(DNSDriver): AuroraDNSHealthCheckType.TCP: 'TCP' } - def list_zones(self): - zones = [] - + def iterate_zones(self): res = self.connection.request('/zones') for zone in res.parse_body(): - zones.append(self.__res_to_zone(zone)) + yield self.__res_to_zone(zone) - return zones + def list_zones(self): + return list(self.iterate_zones()) - def list_records(self, zone): + def iterate_records(self, zone): self.connection.set_context({'resource': 'zone', 'id': zone.id}) - records = [] res = self.connection.request('/zones/%s/records' % zone.id) for record in res.parse_body(): - records.append(self.__res_to_record(zone, record)) + yield self.__res_to_record(zone, record) - return records + def list_records(self, zone): + return list(self.iterate_records(zone)) def get_zone(self, zone_id): self.connection.set_context({'resource': 'zone', 'id': zone_id}) http://git-wip-us.apache.org/repos/asf/libcloud/blob/29698dee/libcloud/test/dns/test_auroradns.py ---------------------------------------------------------------------- diff --git a/libcloud/test/dns/test_auroradns.py b/libcloud/test/dns/test_auroradns.py index c8ab632..6855f89 100644 --- a/libcloud/test/dns/test_auroradns.py +++ b/libcloud/test/dns/test_auroradns.py @@ -90,6 +90,8 @@ class AuroraDNSDriverTests(LibcloudTestCase): def test_list_zones(self): zones = self.driver.list_zones() self.assertEqual(len(zones), 2) + for zone in zones: + self.assertTrue(zone.domain.startswith('auroradns')) def test_create_zone(self): zone = self.driver.create_zone('example.com')