Merge "Removed unused function and improved Zone Master coverage"
This commit is contained in:
commit
dd5993ad1b
designate
@ -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
|
||||
|
72
designate/tests/unit/objects/test_zone_master.py
Normal file
72
designate/tests/unit/objects/test_zone_master.py
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user