Rahman Syed ce50ad9444 Implement zone export
Zone export commands (create, list, show, delete, showfile)
are missing from the python-designateclient.

This change includes implementation, as well as unit tests
and functionaltests.

Change-Id: I957946d739bceea1074e2fda2ce7f841143b0611
Partial-Bug: #1550532
2016-03-23 20:34:14 -05:00

95 lines
3.4 KiB
Python

"""
Copyright 2016 Rackspace
Author: Rahman Syed <rahman.syed@gmail.com>
Licensed 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
limitations under the License.
"""
from designateclient.functionaltests.base import BaseDesignateTest
from designateclient.functionaltests.datagen import random_zone_name
from designateclient.functionaltests.v2.fixtures import ExportFixture
from designateclient.functionaltests.v2.fixtures import ZoneFixture
class TestZoneExport(BaseDesignateTest):
def setUp(self):
super(TestZoneExport, self).setUp()
self.ensure_tld_exists('com')
fixture = self.useFixture(ZoneFixture(
name=random_zone_name(),
email='test@example.com',
))
self.zone = fixture.zone
def test_list_zone_exports(self):
zone_export = self.useFixture(ExportFixture(
zone=self.zone
)).zone_export
zone_exports = self.clients.zone_export_list()
self.assertGreater(len(zone_exports), 0)
self.assertTrue(self._is_export_in_list(zone_export, zone_exports))
def test_create_and_show_zone_export(self):
zone_export = self.useFixture(ExportFixture(
zone=self.zone
)).zone_export
fetched_export = self.clients.zone_export_show(zone_export.id)
self.assertEqual(zone_export.created_at, fetched_export.created_at)
self.assertEqual(zone_export.id, fetched_export.id)
self.assertEqual(zone_export.message, fetched_export.message)
self.assertEqual(zone_export.project_id, fetched_export.project_id)
self.assertEqual(zone_export.zone_id, fetched_export.zone_id)
def test_delete_zone_export(self):
zone_export = self.useFixture(ExportFixture(
zone=self.zone
)).zone_export
zone_exports = self.clients.zone_export_list()
self.assertTrue(self._is_export_in_list(zone_export, zone_exports))
self.clients.zone_export_delete(zone_export.id)
zone_exports = self.clients.zone_export_list()
self.assertFalse(self._is_export_in_list(zone_export, zone_exports))
def test_show_export_file(self):
zone_export = self.useFixture(ExportFixture(
zone=self.zone
)).zone_export
fetched_export = self.clients.zone_export_showfile(zone_export.id)
self.assertIn('$ORIGIN', fetched_export.data)
self.assertIn('$TTL', fetched_export.data)
self.assertIn('SOA', fetched_export.data)
self.assertIn('NS', fetched_export.data)
self.assertIn(self.zone.name, fetched_export.data)
def _is_export_in_list(self, zone_export, zone_export_list):
"""Determines if the given export exists in the given export list.
Uses the zone export id for comparison.
Because the zone export list command displays fewer fields than
the show command, an __eq__ method on the FieldValueModel class
is insufficient.
"""
return any([export_record.id == zone_export.id
for export_record in zone_export_list])