Merge "API v1 for creating domains ignore some attributes now"
This commit is contained in:
commit
c668fd5f91
@ -132,3 +132,22 @@ class UUIDConverter(BaseConverter):
|
|||||||
|
|
||||||
def to_url(self, value):
|
def to_url(self, value):
|
||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
|
def load_values(request, valid_keys):
|
||||||
|
"""Load valid atributes from request"""
|
||||||
|
result = {}
|
||||||
|
error_keys = []
|
||||||
|
values = request.json
|
||||||
|
for k in values:
|
||||||
|
if k in valid_keys:
|
||||||
|
result[k] = values[k]
|
||||||
|
else:
|
||||||
|
error_keys.append(k)
|
||||||
|
|
||||||
|
if error_keys:
|
||||||
|
error_msg = 'Provided object does not match schema. Keys {0} are not \
|
||||||
|
valid in the request body', error_keys
|
||||||
|
raise exceptions.InvalidObject(error_msg)
|
||||||
|
|
||||||
|
return result
|
||||||
|
@ -18,6 +18,7 @@ import flask
|
|||||||
from designate.openstack.common import log as logging
|
from designate.openstack.common import log as logging
|
||||||
from designate import schema
|
from designate import schema
|
||||||
from designate.api import get_central_api
|
from designate.api import get_central_api
|
||||||
|
from designate.api.v1 import load_values
|
||||||
from designate.objects import Domain
|
from designate.objects import Domain
|
||||||
|
|
||||||
|
|
||||||
@ -40,10 +41,13 @@ def get_domains_schema():
|
|||||||
|
|
||||||
@blueprint.route('/domains', methods=['POST'])
|
@blueprint.route('/domains', methods=['POST'])
|
||||||
def create_domain():
|
def create_domain():
|
||||||
|
valid_attributes = ['name', 'email', 'ttl', 'description']
|
||||||
context = flask.request.environ.get('context')
|
context = flask.request.environ.get('context')
|
||||||
values = flask.request.json
|
|
||||||
|
values = load_values(flask.request, valid_attributes)
|
||||||
|
|
||||||
domain_schema.validate(values)
|
domain_schema.validate(values)
|
||||||
|
|
||||||
domain = get_central_api().create_domain(context, Domain(**values))
|
domain = get_central_api().create_domain(context, Domain(**values))
|
||||||
|
|
||||||
response = flask.jsonify(domain_schema.filter(domain))
|
response = flask.jsonify(domain_schema.filter(domain))
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
import datetime
|
||||||
|
|
||||||
from mock import patch
|
from mock import patch
|
||||||
from oslo import messaging
|
from oslo import messaging
|
||||||
|
|
||||||
@ -110,6 +112,23 @@ class ApiV1DomainsTest(ApiV1Test):
|
|||||||
# Create the domain, ensuring it fails with a 400
|
# Create the domain, ensuring it fails with a 400
|
||||||
self.post('domains', data=fixture, status_code=400)
|
self.post('domains', data=fixture, status_code=400)
|
||||||
|
|
||||||
|
def test_create_domain_with_unwanted_attributes(self):
|
||||||
|
# Create a server
|
||||||
|
domain_id = "2d1d1d1d-1324-4a80-aa32-1f69a91bf2c8"
|
||||||
|
created_at = datetime.datetime(2014, 6, 22, 21, 50, 0)
|
||||||
|
updated_at = datetime.datetime(2014, 6, 22, 21, 50, 0)
|
||||||
|
serial = 1234567
|
||||||
|
self.create_server()
|
||||||
|
|
||||||
|
# Create a domain
|
||||||
|
fixture = self.get_domain_fixture(0)
|
||||||
|
fixture['id'] = domain_id
|
||||||
|
fixture['created_at'] = created_at
|
||||||
|
fixture['updated_at'] = updated_at
|
||||||
|
fixture['serial'] = serial
|
||||||
|
|
||||||
|
self.post('domains', data=fixture, status_code=400)
|
||||||
|
|
||||||
def test_create_invalid_name(self):
|
def test_create_invalid_name(self):
|
||||||
# Prepare a domain
|
# Prepare a domain
|
||||||
fixture = self.get_domain_fixture(0)
|
fixture = self.get_domain_fixture(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user