Merge "Remove unused AdvEnum class definition"

This commit is contained in:
Jenkins 2016-07-26 23:03:50 +00:00 committed by Gerrit Code Review
commit 77b5ff2472
2 changed files with 0 additions and 58 deletions

View File

@ -60,31 +60,6 @@ class ProjectNotAuthorized(ClientSideError):
status_code=401)
class AdvEnum(wtypes.wsproperty):
"""Handle default and mandatory for wtypes.Enum."""
def __init__(self, name, *args, **kwargs):
self._name = '_advenum_%s' % name
self._default = kwargs.pop('default', None)
mandatory = kwargs.pop('mandatory', False)
enum = wtypes.Enum(*args, **kwargs)
super(AdvEnum, self).__init__(datatype=enum, fget=self._get,
fset=self._set, mandatory=mandatory)
def _get(self, parent):
if hasattr(parent, self._name):
value = getattr(parent, self._name)
return value or self._default
return self._default
def _set(self, parent, value):
try:
if self.datatype.validate(value):
setattr(parent, self._name, value)
except ValueError as e:
raise wsme.exc.InvalidInput(self._name.replace('_advenum_', '', 1),
value, e)
class Base(wtypes.DynamicBase):
@classmethod

View File

@ -1,33 +0,0 @@
#
# Copyright 2013 eNovance <licensing@enovance.com>
#
# 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.
from oslotest import base
import wsme
from ceilometer.api.controllers.v2 import base as v2_base
class TestWsmeCustomType(base.BaseTestCase):
def test_advenum_default(self):
class dummybase(wsme.types.Base):
ae = v2_base.AdvEnum("name", str, "one", "other", default="other")
obj = dummybase()
self.assertEqual("other", obj.ae)
obj = dummybase(ae="one")
self.assertEqual("one", obj.ae)
self.assertRaises(wsme.exc.InvalidInput, dummybase, ae="not exists")