当前位置: 首页>>代码示例>>Python>>正文


Python fields.StringField方法代码示例

本文整理汇总了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)) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:27,代码来源:test_fields.py

示例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']) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:18,代码来源:test_fixture.py

示例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) 
开发者ID:openstack,项目名称:karbor,代码行数:18,代码来源:test_base.py

示例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] 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:10,代码来源:test_fields.py

示例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']) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:15,代码来源:test_objects.py

示例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()) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:12,代码来源:test_objects.py

示例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)) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:13,代码来源:test_objects.py


注:本文中的oslo_versionedobjects.fields.StringField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。