本文整理汇总了Python中oslo_versionedobjects.fields.StringField方法的典型用法代码示例。如果您正苦于以下问题:Python fields.StringField方法的具体用法?Python fields.StringField怎么用?Python fields.StringField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_versionedobjects.fields
的用法示例。
在下文中一共展示了fields.StringField方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_primitive
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import StringField [as 别名]
def test_from_primitive(self):
@obj_base.VersionedObjectRegistry.register
class TestFakeObject(obj_base.VersionedObject):
OBJ_PROJECT_NAMESPACE = 'fake-project'
@obj_base.VersionedObjectRegistry.register
class TestBar(TestFakeObject, obj_base.ComparableVersionedObject):
fields = {
'name': fields.StringField(),
}
@obj_base.VersionedObjectRegistry.register
class TestFoo(TestFakeObject, obj_base.ComparableVersionedObject):
fields = {
'name': fields.StringField(),
'bar': fields.ObjectField('TestBar', nullable=True)
}
bar = TestBar(name='bar')
foo = TestFoo(name='foo', bar=bar)
from_primitive_values = [(foo.obj_to_primitive(), foo), (foo, foo)]
for prim_val, out_val in from_primitive_values:
self.assertEqual(out_val, self.field.from_primitive(
foo, 'attr', prim_val))
示例2: test_changes_sort
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import StringField [as 别名]
def test_changes_sort(self):
@base.VersionedObjectRegistry.register_if(False)
class TestObject(base.VersionedObject):
fields = {'z': fields.StringField(),
'a': fields.StringField()}
def obj_what_changed(self):
return ['z', 'a']
obj = TestObject(a='foo', z='bar')
self.assertEqual(['z', 'a'],
obj.obj_to_primitive()['versioned_object.changes'])
with fixture.StableObjectJsonFixture():
self.assertEqual(
['a', 'z'],
obj.obj_to_primitive()['versioned_object.changes'])
示例3: test_refresh
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import StringField [as 别名]
def test_refresh(self):
@objects.base.KarborObjectRegistry.register_if(False)
class MyTestObject(objects.base.KarborObject,
objects.base.KarborObjectDictCompat,
objects.base.KarborComparableObject):
fields = {'id': fields.UUIDField(),
'name': fields.StringField()}
test_obj = MyTestObject(id='1', name='foo')
refresh_obj = MyTestObject(id='1', name='bar')
with mock.patch(
'karbor.objects.base.KarborObject.get_by_id') as get_by_id:
get_by_id.return_value = refresh_obj
test_obj.refresh()
self._compare(self, refresh_obj, test_obj)
示例4: setUp
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import StringField [as 别名]
def setUp(self):
super(TestString, self).setUp()
self.field = fields.StringField()
self.coerce_good_values = [
('foo', 'foo'), (1, '1'), (1.0, '1.0'), (True, 'True')]
self.coerce_bad_values = [None]
self.to_primitive_values = self.coerce_good_values[0:1]
self.from_primitive_values = self.coerce_good_values[0:1]
示例5: test_obj_make_compatible_removes_field_cleans_changes
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import StringField [as 别名]
def test_obj_make_compatible_removes_field_cleans_changes(self):
@base.VersionedObjectRegistry.register_if(False)
class TestObject(base.VersionedObject):
VERSION = '1.1'
fields = {'foo': fields.StringField(),
'bar': fields.StringField()}
def obj_make_compatible(self, primitive, target_version):
del primitive['bar']
obj = TestObject(foo='test1', bar='test2')
prim = obj.obj_to_primitive('1.0')
self.assertEqual(['foo'], prim['versioned_object.changes'])
示例6: test_initialize_objects
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import StringField [as 别名]
def test_initialize_objects(self):
class Foo(base.ObjectListBase, base.VersionedObject):
fields = {'objects': fields.ListOfObjectsField('Bar')}
class Bar(base.VersionedObject):
fields = {'foo': fields.StringField()}
obj = Foo()
self.assertEqual([], obj.objects)
self.assertEqual(set(), obj.obj_what_changed())
示例7: test_obj_repr
# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import StringField [as 别名]
def test_obj_repr(self):
@base.VersionedObjectRegistry.register
class Foo(base.ObjectListBase, base.VersionedObject):
fields = {'objects': fields.ListOfObjectsField('Bar')}
@base.VersionedObjectRegistry.register
class Bar(base.VersionedObject):
fields = {'uuid': fields.StringField()}
obj = Foo(objects=[Bar(uuid='fake-uuid')])
self.assertEqual('Foo(objects=[Bar(fake-uuid)])', repr(obj))