Object model: require "priority" field

Add tests
Closes-Bug: #1516350

Change-Id: I91ac97f5f6b860f1649b91cf53d9c268c4df0de6
This commit is contained in:
Federico Ceratto 2015-12-08 18:06:35 +00:00
parent c2a0af1aa8
commit ee5efbf52a
3 changed files with 22 additions and 0 deletions

View File

@ -32,6 +32,7 @@ class PoolNsRecord(base.DictObjectMixin, base.PersistentObjectMixin,
'minimum': 1, 'minimum': 1,
'maximum': 10000 'maximum': 10000
}, },
'required': True
}, },
'hostname': { 'hostname': {
'schema': { 'schema': {

View File

@ -307,6 +307,18 @@ class ApiV2PoolsTest(ApiV2TestCase):
[n['hostname'] for n in [n['hostname'] for n in
response.json['ns_records']]) 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): def test_update_pool_attributes(self):
# Create a pool # Create a pool
pool = self.create_pool() pool = self.create_pool()

View File

@ -2911,6 +2911,15 @@ class CentralServiceTest(CentralTestCase):
self.assertEqual(set([n.hostname for n in pool.ns_records]), self.assertEqual(set([n.hostname for n in pool.ns_records]),
set([n.data for n in ns_recordset.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): def test_update_pool_remove_ns_record(self):
# Create a server pool and zone # Create a server pool and zone
pool = self.create_pool(fixture=0) pool = self.create_pool(fixture=0)