• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python warlock.model_factory函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中warlock.model_factory函数的典型用法代码示例。如果您正苦于以下问题:Python model_factory函数的具体用法?Python model_factory怎么用?Python model_factory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了model_factory函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_resolver

    def test_resolver(self):
        from jsonschema import RefResolver
        dirname = os.path.dirname(__file__)
        schemas_path = 'file://' + os.path.join(dirname, 'schemas/')
        resolver = RefResolver(schemas_path, None)

        country_schema_file = \
            open(os.path.join(dirname, 'schemas/') + 'country.json')
        person_schema_file = \
            open(os.path.join(dirname, 'schemas/') + 'person.json')

        country_schema = json.load(country_schema_file)
        person_schema = json.load(person_schema_file)
        Country = warlock.model_factory(country_schema, resolver)
        Person = warlock.model_factory(person_schema, resolver)

        england = Country(
            name="England",
            population=53865800,
            overlord=Person(
                title="Queen",
                firstname="Elizabeth",
                lastname="Windsor"
            )
        )
        expected = {
            'name': 'England',
            'population': 53865800,
            'overlord': {
                'title': 'Queen',
                'lastname': 'Windsor',
                'firstname': 'Elizabeth'
             }
        }
        self.assertEqual(england, expected)
开发者ID:bcwaldon,项目名称:warlock,代码行数:35,代码来源:test_core.py


示例2: test_naming

 def test_naming(self):
     Country = warlock.model_factory(fixture)
     self.assertEqual(Country.__name__, 'Country')
     
     Country2 = warlock.model_factory(fixture, name='Country2')
     self.assertEqual(Country2.__name__, 'Country2')
     
     nameless = warlock.model_factory(nameless_fixture)
     self.assertEqual(nameless.__name__, 'Model')
     
     nameless2 = warlock.model_factory(nameless_fixture, name='Country3')
     self.assertEqual(nameless2.__name__, 'Country3')
开发者ID:menudoproblema,项目名称:warlock,代码行数:12,代码来源:test_core.py


示例3: test_recursive_models

    def test_recursive_models(self):
        Parent = warlock.model_factory(parent_fixture)
        Child = warlock.model_factory(child_fixture)

        mom = Parent(name='Abby', children=[])

        teenager = Child(age=15, mother=mom)
        toddler = Child(age=3, mother=mom)

        mom.children = [teenager, toddler]

        self.assertEqual(mom.children[0].age, 15)
        self.assertEqual(mom.children[1].age, 3)
开发者ID:bcwaldon,项目名称:warlock,代码行数:13,代码来源:test_core.py


示例4: test_BaseModel_setattr

 def test_BaseModel_setattr(self):
     model_class = model_factory(self._test_schema, BaseModel)
     model = model_class(**self._test_values)
     self.assertRaises(AttributeError, getattr, model, 'test')
     model.test = 'FOO'
     self.assertEqual('FOO', model.test)
     self.assertRaises(AttributeError, getattr, model.json_object, 'test')
开发者ID:IMIO,项目名称:imio.webservice.json,代码行数:7,代码来源:test_base.py


示例5: create_one_image

    def create_one_image(attrs=None):
        """Create a fake image.

        :param Dictionary attrs:
            A dictionary with all attrbutes of image
        :return:
            A FakeResource object with id, name, owner, protected,
            visibility and tags attrs
        """
        attrs = attrs or {}

        # Set default attribute
        image_info = {
            'id': str(uuid.uuid4()),
            'name': 'image-name' + uuid.uuid4().hex,
            'owner': 'image-owner' + uuid.uuid4().hex,
            'protected': bool(random.choice([0, 1])),
            'visibility': random.choice(['public', 'private']),
            'tags': [uuid.uuid4().hex for r in range(2)],
        }

        # Overwrite default attributes if there are some attributes set
        image_info.update(attrs)

        # Set up the schema
        model = warlock.model_factory(
            IMAGE_schema,
            schemas.SchemaBasedModel,
        )

        return model(**image_info)
开发者ID:davisaaronj,项目名称:python-openstackclient,代码行数:31,代码来源:fakes.py


示例6: test_BaseModel

    def test_BaseModel(self):
        model_class = model_factory(self._test_schema, BaseModel)
        model = model_class(**self._test_values)
        model.test = 'foo'

        self.assertEqual('FOO', model.type)
        self.assertEqual('0001', model.id)
开发者ID:IMIO,项目名称:imio.webservice.json,代码行数:7,代码来源:test_base.py


示例7: test_patch_alter_value

 def test_patch_alter_value(self):
     Country = warlock.model_factory(fixture)
     sweden = Country(name='Sweden', population=9379116)
     sweden['name'] = 'Finland'
     self.assertEqual(
         sweden.patch,
         '[{"path": "/name", "value": "Finland", "op": "replace"}]')
开发者ID:robbrit,项目名称:warlock,代码行数:7,代码来源:test_core.py


示例8: test_patch_drop_attribute

 def test_patch_drop_attribute(self):
     Country = warlock.model_factory(fixture)
     sweden = Country(name='Sweden', population=9379116)
     del sweden['name']
     self.assertEqual(
         json.loads(sweden.patch),
         json.loads('[{"path": "/name", "op": "remove"}]'))
开发者ID:menudoproblema,项目名称:warlock,代码行数:7,代码来源:test_core.py


示例9: test_deepcopy

    def test_deepcopy(self):
        """Make sure we aren't leaking references."""
        Mixmaster = warlock.model_factory(complex_fixture)
        mike = Mixmaster(sub={'foo': 'mike'})

        self.assertEquals(mike.sub['foo'], 'mike')

        mike_1 = mike.copy()
        mike_1['sub']['foo'] = 'james'
        self.assertEquals(mike.sub['foo'], 'mike')

        mike_2 = dict(mike.iteritems())
        mike_2['sub']['foo'] = 'james'
        self.assertEquals(mike.sub['foo'], 'mike')

        mike_2 = dict(mike.items())
        mike_2['sub']['foo'] = 'james'
        self.assertEquals(mike.sub['foo'], 'mike')

        mike_3_sub = list(mike.itervalues())[0]
        mike_3_sub['foo'] = 'james'
        self.assertEquals(mike.sub['foo'], 'mike')

        mike_3_sub = list(mike.values())[0]
        mike_3_sub['foo'] = 'james'
        self.assertEquals(mike.sub['foo'], 'mike')
开发者ID:robbrit,项目名称:warlock,代码行数:26,代码来源:test_core.py


示例10: unvalidated_model

 def unvalidated_model(self):
     """A model which does not validate the image against the v2 schema."""
     schema = self.schema_client.get('image')
     warlock_model = warlock.model_factory(schema.raw(),
                                           schemas.SchemaBasedModel)
     warlock_model.validate = lambda *args, **kwargs: None
     return warlock_model
开发者ID:klmitch,项目名称:python-glanceclient,代码行数:7,代码来源:images.py


示例11: test_items

 def test_items(self):
     Country = warlock.model_factory(fixture)
     sweden = Country(name='Sweden', population=9379116)
     self.assertEqual(set(list(sweden.iteritems())),
                      set([('name', 'Sweden'), ('population', 9379116)]))
     self.assertEqual(set(sweden.items()),
                      set([('name', 'Sweden'), ('population', 9379116)]))
开发者ID:termie,项目名称:warlock,代码行数:7,代码来源:test_core.py


示例12: test_forbidden_methods

 def test_forbidden_methods(self):
     Country = warlock.model_factory(fixture)
     sweden = Country(name='Sweden', population=9379116)
     exc = warlock.InvalidOperation
     self.assertRaises(exc, sweden.clear)
     self.assertRaises(exc, sweden.pop, 0)
     self.assertRaises(exc, sweden.popitem)
开发者ID:robbrit,项目名称:warlock,代码行数:7,代码来源:test_core.py


示例13: test_changes

 def test_changes(self):
     Country = warlock.model_factory(fixture)
     sweden = Country(name='Sweden', population=9379116)
     self.assertEqual(sweden.changes, {})
     sweden['name'] = 'Finland'
     self.assertEqual(sweden.changes, {'name': 'Finland'})
     sweden['name'] = 'Norway'
     self.assertEqual(sweden.changes, {'name': 'Norway'})
开发者ID:termie,项目名称:warlock,代码行数:8,代码来源:test_core.py


示例14: model

 def model(**item):
     schema = self.schemas.get('scene')
     wrapped_model = warlock.model_factory(
         schema.raw(),
         schemas.SceneSchemaModel)
     model = wrapped_model(**item)
     model.controller = self.scenes
     return model
开发者ID:haklein,项目名称:fiblary,代码行数:8,代码来源:client.py


示例15: test_dict_syntax

    def test_dict_syntax(self):
        Country = warlock.model_factory(fixture)
        sweden = Country(name='Sweden', population=9379116)

        sweden['name'] = 'Finland'
        self.assertEqual('Finland', sweden['name'])

        del sweden['name']
        self.assertRaises(AttributeError, getattr, sweden, 'name')
开发者ID:bcwaldon,项目名称:warlock,代码行数:9,代码来源:test_core.py


示例16: test_attr_syntax

    def test_attr_syntax(self):
        Country = warlock.model_factory(fixture)
        sweden = Country(name='Sweden', population=9379116)

        sweden.name = 'Finland'
        self.assertEqual(sweden.name, 'Finland')

        delattr(sweden, 'name')
        self.assertRaises(AttributeError, getattr, sweden, 'name')
开发者ID:robbrit,项目名称:warlock,代码行数:9,代码来源:test_core.py


示例17: get_project_by_id

 def get_project_by_id(self, project_id):
     PROJECT_SCHEMA = {'name': {'type': ['null', 'string'], 'description': 'name of the project/tenant', 'maxLength': 255}}
     MockProject = warlock.model_factory(PROJECT_SCHEMA)
     if not project_id:
         return None
     elif 'admin' in project_id.lower():
         return MockProject(name='admin')
     else:
         return MockProject(name='UnknownUser')
开发者ID:xuhang57,项目名称:atmosphere,代码行数:9,代码来源:mock.py


示例18: setUp

    def setUp(self):
        super(TestImageShow, self).setUp()

        # Set up the schema
        self.model = warlock.model_factory(image_fakes.IMAGE_schema, schemas.SchemaBasedModel)

        self.images_mock.get.return_value = self.model(**image_fakes.IMAGE)

        # Get the command object to test
        self.cmd = image.ShowImage(self.app, None)
开发者ID:Aresall1990,项目名称:python-openstackclient,代码行数:10,代码来源:test_image.py


示例19: test_patch_multiple_operations

    def test_patch_multiple_operations(self):
        Country = warlock.model_factory(fixture)
        sweden = Country(name='Sweden', population=9379116)

        sweden['name'] = 'Finland'
        sweden['population'] = 5387000
        self.assertEqual(
            sweden.patch,
            '[{"path": "/name", "value": "Finland", "op": "replace"}, '
            '{"path": "/population", "value": 5387000, "op": "replace"}]')
开发者ID:robbrit,项目名称:warlock,代码行数:10,代码来源:test_core.py


示例20: test_with_value_spec

    def test_with_value_spec(self):
        o = self.calculation_info.create_object(id="/cat/name/1", category="ENDPOINT", version='1')

        res = schema.get("result_endpoint").schema
        res['properties']['result'] = { "enum": ["positive", "negative", "unknown"]}
        o['return_type_spec'] = res

        vts = copy.deepcopy(o['return_type_spec'])
        vt = warlock.model_factory(vts)
        t = vt()
        t.cmp_id = ""
        t.result = "positive"
开发者ID:mnkleinoeder,项目名称:etoxws-api,代码行数:12,代码来源:test_schemas.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python warning_dialog.warning_dialog函数代码示例发布时间:2022-05-26
下一篇:
Python views.search函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap