本文整理匯總了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))