summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Olof Gunnar Andersson <eandersson@blizzard.com>2021-11-30 00:39:03 -0800
committerErik Olof Gunnar Andersson <eandersson@blizzard.com>2021-12-07 08:33:15 +0000
commit87e9b3333bb7d1b2648474df6bbb6a06693964fd (patch)
tree1e83d7410844d70adc5596d9a0ab03b93657a663
parent15a0070d96313b49bfdf41fab52a9bb252bfa0b4 (diff)
downloadpython-designateclient-87e9b3333bb7d1b2648474df6bbb6a06693964fd.tar.gz
Add basic osc unit tests
We currently have no unit test coverage for the cli (openstack) implementation. This adds some very basic coverage that we can later expand upon. Change-Id: Ibf06cfcbf4f7c12957cf5aa0ba8de66e0554f4d0
-rw-r--r--designateclient/tests/osc/__init__.py0
-rw-r--r--designateclient/tests/osc/resources/__init__.py21
-rw-r--r--designateclient/tests/osc/resources/recordset_create.json22
-rw-r--r--designateclient/tests/osc/resources/recordset_list.json74
-rw-r--r--designateclient/tests/osc/resources/recordset_list_all.json116
-rw-r--r--designateclient/tests/osc/resources/zone_create.json22
-rw-r--r--designateclient/tests/osc/resources/zone_list.json54
-rw-r--r--designateclient/tests/osc/v2/__init__.py0
-rw-r--r--designateclient/tests/osc/v2/test_recordsets.py98
-rw-r--r--designateclient/tests/osc/v2/test_zone.py72
10 files changed, 479 insertions, 0 deletions
diff --git a/designateclient/tests/osc/__init__.py b/designateclient/tests/osc/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/designateclient/tests/osc/__init__.py
diff --git a/designateclient/tests/osc/resources/__init__.py b/designateclient/tests/osc/resources/__init__.py
new file mode 100644
index 0000000..4676d02
--- /dev/null
+++ b/designateclient/tests/osc/resources/__init__.py
@@ -0,0 +1,21 @@
+# 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.
+
+import json
+import os.path
+
+path = os.path.dirname(os.path.realpath(__file__))
+
+
+def load(action):
+ with open(os.path.join(path, f'{action}.json')) as fp:
+ return json.load(fp)
diff --git a/designateclient/tests/osc/resources/recordset_create.json b/designateclient/tests/osc/resources/recordset_create.json
new file mode 100644
index 0000000..38ea9e1
--- /dev/null
+++ b/designateclient/tests/osc/resources/recordset_create.json
@@ -0,0 +1,22 @@
+{
+ "id": "a00ac483-d74d-4555-b30f-2e0a176287e2",
+ "zone_id": "6f106adb-0896-4114-b34f-4ac8dfee9465",
+ "project_id": "15a6ae43e4dd498383e127e5f2521301",
+ "name": "example.internal.example.org.",
+ "zone_name": "internal.example.org.",
+ "type": "A",
+ "records": [
+ "127.0.0.1",
+ "127.0.0.2"
+ ],
+ "description": null,
+ "ttl": null,
+ "status": "PENDING",
+ "action": "CREATE",
+ "version": 1,
+ "created_at": "2021-12-05T23:47:57.000000",
+ "updated_at": null,
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones/6f106adb-0896-4114-b34f-4ac8dfee9465/recordsets/a00ac483-d74d-4555-b30f-2e0a176287e2"
+ }
+}
diff --git a/designateclient/tests/osc/resources/recordset_list.json b/designateclient/tests/osc/resources/recordset_list.json
new file mode 100644
index 0000000..d6f7c19
--- /dev/null
+++ b/designateclient/tests/osc/resources/recordset_list.json
@@ -0,0 +1,74 @@
+{
+ "recordsets": [
+ {
+ "id": "393d65fe-c0f1-4a55-a91e-bf6c1725dddc",
+ "zone_id": "6f106adb-0896-4114-b34f-4ac8dfee9465",
+ "project_id": "15a6ae43e4dd498383e127e5f2521301",
+ "name": "internal.example.org.",
+ "zone_name": "internal.example.org.",
+ "type": "NS",
+ "records": [
+ "ns1.example.org."
+ ],
+ "description": null,
+ "ttl": null,
+ "status": "ACTIVE",
+ "action": "NONE",
+ "version": 1,
+ "created_at": "2021-12-05T23:45:54.000000",
+ "updated_at": null,
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones/6f106adb-0896-4114-b34f-4ac8dfee9465/recordsets/393d65fe-c0f1-4a55-a91e-bf6c1725dddc"
+ }
+ },
+ {
+ "id": "4055914e-0f2b-4c47-a8d3-287a5286fe92",
+ "zone_id": "6f106adb-0896-4114-b34f-4ac8dfee9465",
+ "project_id": "15a6ae43e4dd498383e127e5f2521301",
+ "name": "internal.example.org.",
+ "zone_name": "internal.example.org.",
+ "type": "SOA",
+ "records": [
+ "ns1.example.org. fake.example.org. 1638748076 3584 600 86400 3600"
+ ],
+ "description": null,
+ "ttl": null,
+ "status": "ACTIVE",
+ "action": "NONE",
+ "version": 4,
+ "created_at": "2021-12-05T23:45:54.000000",
+ "updated_at": "2021-12-05T23:47:57.000000",
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones/6f106adb-0896-4114-b34f-4ac8dfee9465/recordsets/4055914e-0f2b-4c47-a8d3-287a5286fe92"
+ }
+ },
+ {
+ "id": "a00ac483-d74d-4555-b30f-2e0a176287e2",
+ "zone_id": "6f106adb-0896-4114-b34f-4ac8dfee9465",
+ "project_id": "15a6ae43e4dd498383e127e5f2521301",
+ "name": "example.internal.example.org.",
+ "zone_name": "internal.example.org.",
+ "type": "A",
+ "records": [
+ "127.0.0.2",
+ "127.0.0.1"
+ ],
+ "description": null,
+ "ttl": null,
+ "status": "ACTIVE",
+ "action": "NONE",
+ "version": 1,
+ "created_at": "2021-12-05T23:47:57.000000",
+ "updated_at": null,
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones/6f106adb-0896-4114-b34f-4ac8dfee9465/recordsets/a00ac483-d74d-4555-b30f-2e0a176287e2"
+ }
+ }
+ ],
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones/6f106adb-0896-4114-b34f-4ac8dfee9465/recordsets"
+ },
+ "metadata": {
+ "total_count": 3
+ }
+}
diff --git a/designateclient/tests/osc/resources/recordset_list_all.json b/designateclient/tests/osc/resources/recordset_list_all.json
new file mode 100644
index 0000000..ed4dfd5
--- /dev/null
+++ b/designateclient/tests/osc/resources/recordset_list_all.json
@@ -0,0 +1,116 @@
+{
+ "recordsets": [
+ {
+ "id": "393d65fe-c0f1-4a55-a91e-bf6c1725dddc",
+ "zone_id": "6f106adb-0896-4114-b34f-4ac8dfee9465",
+ "project_id": "15a6ae43e4dd498383e127e5f2521301",
+ "name": "internal.example.org.",
+ "zone_name": "internal.example.org.",
+ "type": "NS",
+ "records": [
+ "ns1.example.org."
+ ],
+ "description": null,
+ "ttl": null,
+ "status": "ACTIVE",
+ "action": "NONE",
+ "version": 1,
+ "created_at": "2021-12-05T23:45:54.000000",
+ "updated_at": null,
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones/6f106adb-0896-4114-b34f-4ac8dfee9465/recordsets/393d65fe-c0f1-4a55-a91e-bf6c1725dddc"
+ }
+ },
+ {
+ "id": "4055914e-0f2b-4c47-a8d3-287a5286fe92",
+ "zone_id": "6f106adb-0896-4114-b34f-4ac8dfee9465",
+ "project_id": "15a6ae43e4dd498383e127e5f2521301",
+ "name": "internal.example.org.",
+ "zone_name": "internal.example.org.",
+ "type": "SOA",
+ "records": [
+ "ns1.example.org. fake.example.org. 1638748076 3584 600 86400 3600"
+ ],
+ "description": null,
+ "ttl": null,
+ "status": "ACTIVE",
+ "action": "NONE",
+ "version": 4,
+ "created_at": "2021-12-05T23:45:54.000000",
+ "updated_at": "2021-12-05T23:47:57.000000",
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones/6f106adb-0896-4114-b34f-4ac8dfee9465/recordsets/4055914e-0f2b-4c47-a8d3-287a5286fe92"
+ }
+ },
+ {
+ "id": "a00ac483-d74d-4555-b30f-2e0a176287e2",
+ "zone_id": "6f106adb-0896-4114-b34f-4ac8dfee9465",
+ "project_id": "15a6ae43e4dd498383e127e5f2521301",
+ "name": "example.internal.example.org.",
+ "zone_name": "internal.example.org.",
+ "type": "A",
+ "records": [
+ "127.0.0.2",
+ "127.0.0.1"
+ ],
+ "description": null,
+ "ttl": null,
+ "status": "ACTIVE",
+ "action": "NONE",
+ "version": 1,
+ "created_at": "2021-12-05T23:47:57.000000",
+ "updated_at": null,
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones/6f106adb-0896-4114-b34f-4ac8dfee9465/recordsets/a00ac483-d74d-4555-b30f-2e0a176287e2"
+ }
+ },
+ {
+ "id": "2f5b0a00-2f03-426c-a5fc-5c1c85a5156b",
+ "zone_id": "a5f8e94e-af03-4e3e-b3eb-688a3b9f3b31",
+ "project_id": "15a6ae43e4dd498383e127e5f2521301",
+ "name": "external.example.org.",
+ "zone_name": "external.example.org.",
+ "type": "SOA",
+ "records": [
+ "ns1.example.org. another_fake.example.org. 1638748236 3554 600 86400 3600"
+ ],
+ "description": null,
+ "ttl": null,
+ "status": "PENDING",
+ "action": "CREATE",
+ "version": 1,
+ "created_at": "2021-12-05T23:50:36.000000",
+ "updated_at": null,
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones/a5f8e94e-af03-4e3e-b3eb-688a3b9f3b31/recordsets/2f5b0a00-2f03-426c-a5fc-5c1c85a5156b"
+ }
+ },
+ {
+ "id": "4aacd04d-2546-43d9-98cd-58960a0a2494",
+ "zone_id": "a5f8e94e-af03-4e3e-b3eb-688a3b9f3b31",
+ "project_id": "15a6ae43e4dd498383e127e5f2521301",
+ "name": "external.example.org.",
+ "zone_name": "external.example.org.",
+ "type": "NS",
+ "records": [
+ "ns1.example.org."
+ ],
+ "description": null,
+ "ttl": null,
+ "status": "PENDING",
+ "action": "CREATE",
+ "version": 1,
+ "created_at": "2021-12-05T23:50:36.000000",
+ "updated_at": null,
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones/a5f8e94e-af03-4e3e-b3eb-688a3b9f3b31/recordsets/4aacd04d-2546-43d9-98cd-58960a0a2494"
+ }
+ }
+ ],
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/recordsets"
+ },
+ "metadata": {
+ "total_count": 5
+ }
+}
diff --git a/designateclient/tests/osc/resources/zone_create.json b/designateclient/tests/osc/resources/zone_create.json
new file mode 100644
index 0000000..e095685
--- /dev/null
+++ b/designateclient/tests/osc/resources/zone_create.json
@@ -0,0 +1,22 @@
+{
+ "id": "6f106adb-0896-4114-b34f-4ac8dfee9465",
+ "pool_id": "794ccc2c-d751-44fe-b57f-8894c9f5c842",
+ "project_id": "15a6ae43e4dd498383e127e5f2521301",
+ "name": "internal.example.org.",
+ "email": "fake@example.org",
+ "description": null,
+ "ttl": 3600,
+ "serial": 1638747953,
+ "status": "PENDING",
+ "action": "CREATE",
+ "version": 1,
+ "attributes": {},
+ "type": "PRIMARY",
+ "masters": [],
+ "created_at": "2021-12-05T23:45:54.000000",
+ "updated_at": null,
+ "transferred_at": null,
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones/6f106adb-0896-4114-b34f-4ac8dfee9465"
+ }
+}
diff --git a/designateclient/tests/osc/resources/zone_list.json b/designateclient/tests/osc/resources/zone_list.json
new file mode 100644
index 0000000..d5d7737
--- /dev/null
+++ b/designateclient/tests/osc/resources/zone_list.json
@@ -0,0 +1,54 @@
+{
+ "zones": [
+ {
+ "id": "6f106adb-0896-4114-b34f-4ac8dfee9465",
+ "pool_id": "794ccc2c-d751-44fe-b57f-8894c9f5c842",
+ "project_id": "15a6ae43e4dd498383e127e5f2521301",
+ "name": "internal.example.org.",
+ "email": "fake@example.org",
+ "description": null,
+ "ttl": 3600,
+ "serial": 1638748076,
+ "status": "ACTIVE",
+ "action": "NONE",
+ "version": 8,
+ "attributes": {},
+ "type": "PRIMARY",
+ "masters": [],
+ "created_at": "2021-12-05T23:45:54.000000",
+ "updated_at": "2021-12-05T23:48:02.000000",
+ "transferred_at": null,
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones/6f106adb-0896-4114-b34f-4ac8dfee9465"
+ }
+ },
+ {
+ "id": "a5f8e94e-af03-4e3e-b3eb-688a3b9f3b31",
+ "pool_id": "794ccc2c-d751-44fe-b57f-8894c9f5c842",
+ "project_id": "15a6ae43e4dd498383e127e5f2521301",
+ "name": "external.example.org.",
+ "email": "another_fake@example.org",
+ "description": null,
+ "ttl": 3600,
+ "serial": 1638748236,
+ "status": "ACTIVE",
+ "action": "NONE",
+ "version": 2,
+ "attributes": {},
+ "type": "PRIMARY",
+ "masters": [],
+ "created_at": "2021-12-05T23:50:36.000000",
+ "updated_at": "2021-12-05T23:50:42.000000",
+ "transferred_at": null,
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones/a5f8e94e-af03-4e3e-b3eb-688a3b9f3b31"
+ }
+ }
+ ],
+ "links": {
+ "self": "http://10.0.1.203/dns/v2/zones?type=PRIMARY"
+ },
+ "metadata": {
+ "total_count": 2
+ }
+}
diff --git a/designateclient/tests/osc/v2/__init__.py b/designateclient/tests/osc/v2/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/designateclient/tests/osc/v2/__init__.py
diff --git a/designateclient/tests/osc/v2/test_recordsets.py b/designateclient/tests/osc/v2/test_recordsets.py
new file mode 100644
index 0000000..c9d2252
--- /dev/null
+++ b/designateclient/tests/osc/v2/test_recordsets.py
@@ -0,0 +1,98 @@
+# 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 unittest import mock
+
+from osc_lib.tests import utils
+
+from designateclient.tests.osc import resources
+from designateclient.v2 import base
+from designateclient.v2.cli import recordsets
+
+
+class TestDesignateCreateRecordSets(utils.TestCommand):
+ def setUp(self):
+ super(TestDesignateCreateRecordSets, self).setUp()
+ self.app.client_manager.dns = mock.MagicMock()
+ self.cmd = recordsets.CreateRecordSetCommand(self.app, None)
+ self.dns_client = self.app.client_manager.dns
+
+ def test_create_recordset(self):
+ arg_list = [
+ '6f106adb-0896-4114-b34f-4ac8dfee9465',
+ 'example',
+ '--type', 'A',
+ '--record', '127.0.0.1',
+ '--record', '127.0.0.2',
+ ]
+ verify_args = [
+ ('zone_id', '6f106adb-0896-4114-b34f-4ac8dfee9465'),
+ ('name', 'example'),
+ ('type', 'A'),
+ ('record', ['127.0.0.1', '127.0.0.2']),
+ ]
+
+ body = resources.load('recordset_create')
+ self.dns_client.recordsets.create.return_value = body
+
+ parsed_args = self.check_parser(self.cmd, arg_list, verify_args)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ results = list(data)
+
+ self.assertEqual(14, len(results))
+
+
+class TestDesignateListRecordSets(utils.TestCommand):
+ def setUp(self):
+ super(TestDesignateListRecordSets, self).setUp()
+ self.app.client_manager.dns = mock.MagicMock()
+ self.cmd = recordsets.ListRecordSetsCommand(self.app, None)
+ self.dns_client = self.app.client_manager.dns
+
+ def test_list_recordsets(self):
+ arg_list = ['6f106adb-0896-4114-b34f-4ac8dfee9465']
+ verify_args = [
+ ('zone_id', '6f106adb-0896-4114-b34f-4ac8dfee9465'),
+ ]
+
+ body = resources.load('recordset_list')
+ result = base.DesignateList()
+ result.extend(body['recordsets'])
+
+ self.dns_client.recordsets.list.return_value = result
+
+ parsed_args = self.check_parser(self.cmd, arg_list, verify_args)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ results = list(data)
+
+ self.assertEqual(3, len(results))
+
+ def test_list_all_recordsets(self):
+ arg_list = ['all']
+ verify_args = [
+ ('zone_id', 'all'),
+ ]
+
+ body = resources.load('recordset_list_all')
+ result = base.DesignateList()
+ result.extend(body['recordsets'])
+
+ self.dns_client.recordsets.list_all_zones.return_value = result
+
+ parsed_args = self.check_parser(self.cmd, arg_list, verify_args)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ results = list(data)
+
+ self.assertEqual(5, len(results))
diff --git a/designateclient/tests/osc/v2/test_zone.py b/designateclient/tests/osc/v2/test_zone.py
new file mode 100644
index 0000000..adf3f3d
--- /dev/null
+++ b/designateclient/tests/osc/v2/test_zone.py
@@ -0,0 +1,72 @@
+# 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 unittest import mock
+
+from osc_lib.tests import utils
+
+from designateclient.tests.osc import resources
+from designateclient.v2 import base
+from designateclient.v2.cli import zones
+
+
+class TestDesignateCreateZone(utils.TestCommand):
+ def setUp(self):
+ super(TestDesignateCreateZone, self).setUp()
+ self.app.client_manager.dns = mock.MagicMock()
+ self.cmd = zones.CreateZoneCommand(self.app, None)
+ self.dns_client = self.app.client_manager.dns
+
+ def test_create_zone(self):
+ arg_list = [
+ 'example.devstack.org.',
+ '--email', 'fake@devstack.org',
+ ]
+ verify_args = [
+ ('name', 'example.devstack.org.'),
+ ('email', 'fake@devstack.org'),
+ ]
+
+ body = resources.load('zone_create')
+ self.dns_client.zones.create.return_value = body
+
+ parsed_args = self.check_parser(self.cmd, arg_list, verify_args)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ results = list(data)
+
+ self.assertEqual(17, len(results))
+
+
+class TestDesignateListZones(utils.TestCommand):
+ def setUp(self):
+ super(TestDesignateListZones, self).setUp()
+ self.app.client_manager.dns = mock.MagicMock()
+ self.cmd = zones.ListZonesCommand(self.app, None)
+ self.dns_client = self.app.client_manager.dns
+
+ def test_list_zones(self):
+ arg_list = []
+ verify_args = []
+
+ body = resources.load('zone_list')
+ result = base.DesignateList()
+ result.extend(body['zones'])
+
+ self.dns_client.zones.list.return_value = result
+
+ parsed_args = self.check_parser(self.cmd, arg_list, verify_args)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ results = list(data)
+
+ self.assertEqual(2, len(results))