
This makes use of complex types validations of WSME that now works. Change-Id: I5cd46d5c2caeb3f3c4cd1ef90448e7fd3c81404d Closes-Bug: #1223847
63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
#!/usr/bin/env python
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
# Copyright 2013 Red Hat, Inc.
|
|
# All Rights Reserved.
|
|
#
|
|
# 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 six
|
|
import wsme
|
|
|
|
from ironic.api.controllers.v1 import utils
|
|
from ironic.tests.api import base
|
|
|
|
from oslo.config import cfg
|
|
|
|
CONF = cfg.CONF
|
|
|
|
|
|
class TestApiUtils(base.FunctionalTest):
|
|
|
|
def test_validate_limit(self):
|
|
limit = utils.validate_limit(10)
|
|
self.assertEqual(10, 10)
|
|
|
|
# max limit
|
|
limit = utils.validate_limit(999999999)
|
|
self.assertEqual(CONF.api.max_limit, limit)
|
|
|
|
# negative
|
|
self.assertRaises(wsme.exc.ClientSideError, utils.validate_limit, -1)
|
|
|
|
def test_validate_sort_dir(self):
|
|
sort_dir = utils.validate_sort_dir('asc')
|
|
self.assertEqual('asc', sort_dir)
|
|
|
|
# invalid sort_dir parameter
|
|
self.assertRaises(wsme.exc.ClientSideError,
|
|
utils.validate_sort_dir,
|
|
'fake-sort')
|
|
|
|
def test_valid_types(self):
|
|
vt = utils.ValidTypes(wsme.types.text, six.integer_types)
|
|
|
|
value = vt.validate("hello")
|
|
self.assertEqual("hello", value)
|
|
|
|
value = vt.validate(10)
|
|
self.assertEqual(10, value)
|
|
|
|
# wrong value
|
|
self.assertRaises(ValueError, vt.validate, 0.10)
|