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


Python Eve.register_resource方法代码示例

本文整理汇总了Python中eve.flaskapp.Eve.register_resource方法的典型用法代码示例。如果您正苦于以下问题:Python Eve.register_resource方法的具体用法?Python Eve.register_resource怎么用?Python Eve.register_resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eve.flaskapp.Eve的用法示例。


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

示例1: TestConfig

# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import register_resource [as 别名]

#.........这里部分代码省略.........

    def assertValidateConfigSuccess(self):
        try:
            self.app.validate_domain_struct()
            self.app.validate_config()
        except ConfigException as e:
            self.fail('ConfigException not expected: %s' % e)

    def assertValidateConfigFailure(self, expected):
        try:
            self.app.validate_domain_struct()
            self.app.validate_config()
        except ConfigException as e:
            if isinstance(expected, str):
                expected = [expected]
            for exp in expected:
                self.assertTrue(exp.lower() in str(e).lower())
        else:
            self.fail("ConfigException expected but not raised.")

    def assertValidateSchemaFailure(self, resource, schema, expected):
        try:
            self.app.validate_schema(resource, schema)
        except SchemaException as e:
            self.assertTrue(expected.lower() in str(e).lower())
        else:
            self.fail("SchemaException expected but not raised.")

    def test_schema_defaults(self):
        self.domain.clear()
        self.domain['resource'] = {
            'schema': {
                'title': {
                    'type': 'string',
                    'default': 'Mr.',
                },
                'price': {
                    'type': 'integer',
                    'default': 100
                },
            }
        }
        self.app.set_defaults()
        settings = self.domain['resource']
        self.assertEqual({'title': 'Mr.', 'price': 100}, settings['defaults'])

    def test_url_helpers(self):
        self.assertNotEqual(self.app.config.get('URLS'), None)
        self.assertEqual(type(self.app.config['URLS']), dict)

        self.assertNotEqual(self.app.config.get('SOURCES'), None)
        self.assertEqual(type(self.app.config['SOURCES']), dict)

        del(self.domain['internal_transactions'])
        for resource, settings in self.domain.items():
            self.assertEqual(settings['url'],
                             self.app.config['URLS'][resource])
            self.assertEqual(settings['datasource'],
                             self.app.config['SOURCES'][resource])

    def test_url_rules(self):
        map_adapter = self.app.url_map.bind(self.app.config.get(
            'SERVER_NAME', ''))

        del(self.domain['peopleinvoices'])
        del(self.domain['internal_transactions'])
        for _, settings in self.domain.items():
            for method in settings['resource_methods']:
                self.assertTrue(map_adapter.test('/%s/' % settings['url'],
                                                 method))

            # TODO test item endpoints as well. gonna be tricky since
            # we have to reverse regexes here. will be fun.

    def test_register_resource(self):
        resource = 'resource'
        settings = {
            'schema': {
                'title': {
                    'type': 'string',
                    'default': 'Mr.',
                },
                'price': {
                    'type': 'integer',
                    'default': 100
                },
            }
        }
        self.app.register_resource(resource, settings)
        self._test_defaults_for_resource(resource)
        self._test_datasource_for_resource(resource)
        self.test_validate_roles()

    def test_auth_field_as_idfield(self):
        resource = 'resource'
        settings = {
            'auth_field': self.app.config['ID_FIELD'],
        }
        self.assertRaises(ConfigException, self.app.register_resource,
                          resource, settings)
开发者ID:omixen,项目名称:eve,代码行数:104,代码来源:config.py

示例2: TestConfig

# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import register_resource [as 别名]

#.........这里部分代码省略.........
        self.assertNotEqual(self.app.config.get('SOURCES'), None)
        self.assertEqual(type(self.app.config['SOURCES']), dict)

        del(self.domain['internal_transactions'])
        for resource, settings in self.domain.items():
            self.assertEqual(settings['datasource'],
                             self.app.config['SOURCES'][resource])

    def test_pretty_resource_urls(self):
        """ test that regexes are stripped out of urls and #466 is fixed. """
        resource_url = self.app.config['URLS']['peopleinvoices']
        pretty_url = 'users/<person>/invoices'
        self.assertEqual(resource_url, pretty_url)
        resource_url = self.app.config['URLS']['peoplesearches']
        pretty_url = 'users/<person>/saved_searches'
        self.assertEqual(resource_url, pretty_url)

    def test_url_rules(self):
        map_adapter = self.app.url_map.bind('')

        del(self.domain['peopleinvoices'])
        del(self.domain['peoplerequiredinvoices'])
        del(self.domain['peoplesearches'])
        del(self.domain['internal_transactions'])
        del(self.domain['child_products'])
        for _, settings in self.domain.items():
            for method in settings['resource_methods']:
                self.assertTrue(map_adapter.test('/%s/' % settings['url'],
                                                 method))

            # TODO test item endpoints as well. gonna be tricky since
            # we have to reverse regexes here. will be fun.

    def test_register_resource(self):
        resource = 'resource'
        settings = {
            'schema': {
                'title': {
                    'type': 'string',
                    'default': 'Mr.',
                },
                'price': {
                    'type': 'integer',
                    'default': 100
                },
            }
        }
        self.app.register_resource(resource, settings)
        self._test_defaults_for_resource(resource)
        self._test_datasource_for_resource(resource)
        self.test_validate_roles()

    def test_auth_field_as_idfield(self):
        resource = 'resource'
        settings = {
            'auth_field': self.app.config['ID_FIELD'],
        }
        self.assertRaises(ConfigException, self.app.register_resource,
                          resource, settings)

    def test_auth_field_as_custom_idfield(self):
        resource = 'resource'
        settings = {
            'schema': {
                'id': {'type': 'string'}
            },
开发者ID:Adam-Koza,项目名称:python-services-rest-api,代码行数:70,代码来源:config.py

示例3: TestConfig

# 需要导入模块: from eve.flaskapp import Eve [as 别名]
# 或者: from eve.flaskapp.Eve import register_resource [as 别名]

#.........这里部分代码省略.........
        self.assertNotEqual(self.app.config.get("SOURCES"), None)
        self.assertEqual(type(self.app.config["SOURCES"]), dict)

        del self.domain["internal_transactions"]
        for resource, settings in self.domain.items():
            self.assertEqual(
                settings["datasource"], self.app.config["SOURCES"][resource]
            )

    def test_pretty_resource_urls(self):
        """ test that regexes are stripped out of urls and #466 is fixed. """
        resource_url = self.app.config["URLS"]["peopleinvoices"]
        pretty_url = "users/<person>/invoices"
        self.assertEqual(resource_url, pretty_url)
        resource_url = self.app.config["URLS"]["peoplesearches"]
        pretty_url = "users/<person>/saved_searches"
        self.assertEqual(resource_url, pretty_url)

    def test_url_rules(self):
        map_adapter = self.app.url_map.bind("")

        del self.domain["peopleinvoices"]
        del self.domain["peoplerequiredinvoices"]
        del self.domain["peoplesearches"]
        del self.domain["internal_transactions"]
        del self.domain["child_products"]
        for _, settings in self.domain.items():
            for method in settings["resource_methods"]:
                self.assertTrue(map_adapter.test("/%s/" % settings["url"], method))

            # TODO test item endpoints as well. gonna be tricky since
            # we have to reverse regexes here. will be fun.

    def test_register_resource(self):
        resource = "resource"
        settings = {
            "schema": {
                "title": {"type": "string", "default": "Mr."},
                "price": {"type": "integer", "default": 100},
            }
        }
        self.app.register_resource(resource, settings)
        self._test_defaults_for_resource(resource)
        self._test_datasource_for_resource(resource)
        self.test_validate_roles()

    def test_auth_field_as_idfield(self):
        resource = "resource"
        settings = {"auth_field": self.app.config["ID_FIELD"]}
        self.assertRaises(
            ConfigException, self.app.register_resource, resource, settings
        )

    def test_auth_field_as_custom_idfield(self):
        resource = "resource"
        settings = {
            "schema": {"id": {"type": "string"}},
            "id_field": "id",
            "auth_field": "id",
        }
        self.assertRaises(
            ConfigException, self.app.register_resource, resource, settings
        )

    def test_oplog_config(self):
开发者ID:sunbit,项目名称:eve,代码行数:69,代码来源:config.py


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