From 75e0b5480fb07bf70a6e5b0cd389b0865bcb6524 Mon Sep 17 00:00:00 2001 From: Erik Olof Gunnar Andersson Date: Tue, 9 Jan 2024 16:30:59 -0800 Subject: [PATCH] Removed unused function and improved Zone Master coverage - Removed to_list as it is implemented the same way in the base class. Change-Id: I74558bd4b1ca4effdbd2475ff7f08a5072e1e44f --- designate/objects/zone_master.py | 22 ++---- .../tests/unit/objects/test_zone_master.py | 72 +++++++++++++++++++ 2 files changed, 76 insertions(+), 18 deletions(-) create mode 100644 designate/tests/unit/objects/test_zone_master.py diff --git a/designate/objects/zone_master.py b/designate/objects/zone_master.py index c159800ef..03d435157 100644 --- a/designate/objects/zone_master.py +++ b/designate/objects/zone_master.py @@ -13,7 +13,7 @@ # 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 oslo_versionedobjects import base as ovoo_base + from designate.objects import base from designate.objects import fields @@ -60,22 +60,8 @@ class ZoneMasterList(base.ListObjectMixin, base.DesignateObject): return instance - def to_list(self): - - list_ = [] - - for item in self.objects: - if isinstance(item, ovoo_base.ObjectListBase): - list_.append(item.to_list()) - elif isinstance(item, base.DesignateObject): - list_.append(item.to_dict()) - else: - list_.append(item) - - return list_ - def to_data(self): - zone_master_list = [] + zone_masters = [] for item in self.objects: - zone_master_list.append(item.to_data()) - return zone_master_list + zone_masters.append(item.to_data()) + return zone_masters diff --git a/designate/tests/unit/objects/test_zone_master.py b/designate/tests/unit/objects/test_zone_master.py new file mode 100644 index 000000000..a4e97850e --- /dev/null +++ b/designate/tests/unit/objects/test_zone_master.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. + + +import oslotest.base + +from designate import objects + + +class ZoneMasterTest(oslotest.base.BaseTestCase): + def test_zone_master_from_data(self): + zone_master = objects.ZoneMaster.from_data('192.0.2.2:5354') + self.assertEqual('192.0.2.2', zone_master.host) + self.assertEqual(5354, zone_master.port) + + def test_zone_master_to_data(self): + zone_master = objects.ZoneMaster.from_data('192.0.2.2:5354') + + self.assertEqual('192.0.2.2:5354', zone_master.to_data()) + + def test_zone_masters_from_list(self): + zone_masters = objects.ZoneMasterList.from_list([ + {'host': '192.0.2.1', 'port': 5354, }, + {'host': '192.0.2.2', 'port': 5354, }, + {'host': '192.0.2.100', 'port': 5354, }, + ]) + + self.assertEqual(3, len(zone_masters)) + + for zone_master in zone_masters: + self.assertIn('192.0.2.', zone_master.host) + self.assertEqual(5354, zone_master.port) + + def test_zone_masters_to_list(self): + zone_masters_payload = [ + {'host': '192.0.2.1', 'port': 53, }, + {'host': '192.0.2.100', 'port': 5354, }, + ] + + zone_masters = objects.ZoneMasterList.from_list(zone_masters_payload) + + self.assertEqual(2, len(zone_masters)) + + for zone_master in zone_masters.to_list(): + self.assertIn(zone_master, zone_masters_payload) + + def test_zone_masters_to_data(self): + expected_results = [ + '192.0.2.1:53', + '192.0.2.2:5354' + ] + + zone_masters = [ + {'host': '192.0.2.1', 'port': 53, }, + {'host': '192.0.2.2', 'port': 5354, }, + ] + + zone_masters = objects.ZoneMasterList.from_list(zone_masters) + + self.assertEqual(2, len(zone_masters)) + + for zone_master in zone_masters.to_data(): + self.assertIn(zone_master, expected_results)