From ee5efbf52a810b69dee02f7f37913670025c422d Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Tue, 8 Dec 2015 18:06:35 +0000 Subject: [PATCH] Object model: require "priority" field Add tests Closes-Bug: #1516350 Change-Id: I91ac97f5f6b860f1649b91cf53d9c268c4df0de6 --- designate/objects/pool_ns_record.py | 1 + designate/tests/test_api/test_v2/test_pools.py | 12 ++++++++++++ designate/tests/test_central/test_service.py | 9 +++++++++ 3 files changed, 22 insertions(+) diff --git a/designate/objects/pool_ns_record.py b/designate/objects/pool_ns_record.py index 2de69736..26904a62 100644 --- a/designate/objects/pool_ns_record.py +++ b/designate/objects/pool_ns_record.py @@ -32,6 +32,7 @@ class PoolNsRecord(base.DictObjectMixin, base.PersistentObjectMixin, 'minimum': 1, 'maximum': 10000 }, + 'required': True }, 'hostname': { 'schema': { diff --git a/designate/tests/test_api/test_v2/test_pools.py b/designate/tests/test_api/test_v2/test_pools.py index 3509480e..a422ea6f 100644 --- a/designate/tests/test_api/test_v2/test_pools.py +++ b/designate/tests/test_api/test_v2/test_pools.py @@ -307,6 +307,18 @@ class ApiV2PoolsTest(ApiV2TestCase): [n['hostname'] for n in response.json['ns_records']]) + def test_update_pool_ns_records_without_priority(self): + pool = self.create_pool() + body = {'ns_records': [ + {'hostname': 'new-ns1.example.org.'}, + {'hostname': 'new-ns2.example.org.'}, + ]} + url = '/pools/%s' % pool['id'] + # The missing "apriority" field triggers an object validation error + response = self.client.patch_json(url, body, status=400) + errmsg = response.json['errors']['errors'][0]['message'] + self.assertEqual("'priority' is a required property", errmsg) + def test_update_pool_attributes(self): # Create a pool pool = self.create_pool() diff --git a/designate/tests/test_central/test_service.py b/designate/tests/test_central/test_service.py index f7acdbe7..6d6a5558 100644 --- a/designate/tests/test_central/test_service.py +++ b/designate/tests/test_central/test_service.py @@ -2911,6 +2911,15 @@ class CentralServiceTest(CentralTestCase): self.assertEqual(set([n.hostname for n in pool.ns_records]), set([n.data for n in ns_recordset.records])) + def test_update_pool_add_ns_record_without_priority(self): + pool = self.create_pool(fixture=0) + self.create_zone(pool_id=pool.id) + new_ns_record = objects.PoolNsRecord(hostname='ns-new.example.org.') + pool.ns_records.append(new_ns_record) + # PoolNsRecord without "priority" triggers a DB exception + with testtools.ExpectedException(db_exception.DBError): + self.central_service.update_pool(self.admin_context, pool) + def test_update_pool_remove_ns_record(self): # Create a server pool and zone pool = self.create_pool(fixture=0)