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


Python ViewSet.record_arguments方法代码示例

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


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

示例1: TestViewsetBindedSchemas

# 需要导入模块: from kinto.core.resource import ViewSet [as 别名]
# 或者: from kinto.core.resource.ViewSet import record_arguments [as 别名]
class TestViewsetBindedSchemas(unittest.TestCase):
    def setUp(self):
        self.viewset = ViewSet()
        self.viewset.responses = mock.MagicMock()
        self.resource = mock.MagicMock()

    def test_request_schemas_have_header_and_querystring(self):
        self.viewset = ViewSet(
            default_get_arguments={}, default_record_arguments={}, record_get_arguments={}
        )
        arguments = self.viewset.record_arguments(self.resource, "GET")
        schema = arguments["schema"]
        self.assertIn("querystring", schema)
        self.assertIn("header", schema)

    def test_payload_request_schemas_have_a_body(self):
        arguments = self.viewset.record_arguments(self.resource, "PUT")
        schema = arguments["schema"]
        self.assertIn("body", schema)

    def test_collection_deserialize_sort(self):
        arguments = self.viewset.collection_arguments(self.resource, "DELETE")
        schema = arguments["schema"]
        value = {"querystring": {"_sort": "foo,-bar"}}
        deserialized = schema.deserialize(value)
        expected = {"querystring": {"_sort": ["foo", "-bar"]}}
        self.assertEqual(deserialized, expected)

    def test_get_collection_deserialize_fields(self):
        arguments = self.viewset.collection_arguments(self.resource, "GET")
        schema = arguments["schema"]
        value = {"querystring": {"_fields": "foo,bar"}}
        deserialized = schema.deserialize(value)
        expected = {"querystring": {"_fields": ["foo", "bar"]}}
        self.assertEqual(deserialized, expected)

    def test_get_record_deserialize_fields(self):
        arguments = self.viewset.record_arguments(self.resource, "GET")
        schema = arguments["schema"]
        value = {"querystring": {"_fields": "foo,bar"}}
        deserialized = schema.deserialize(value)
        expected = {"querystring": {"_fields": ["foo", "bar"]}}
        self.assertEqual(deserialized, expected)

    def test_patch_record_validate_response_behavior(self):
        arguments = self.viewset.collection_arguments(self.resource, "PATCH")
        schema = arguments["schema"]
        invalid = {"header": {"Response-Behavior": "impolite"}}
        self.assertRaises(colander.Invalid, schema.deserialize, invalid)
开发者ID:pombredanne,项目名称:kinto,代码行数:51,代码来源:test_viewset.py

示例2: test_class_parameters_overwrite_each_others

# 需要导入模块: from kinto.core.resource import ViewSet [as 别名]
# 或者: from kinto.core.resource.ViewSet import record_arguments [as 别名]
    def test_class_parameters_overwrite_each_others(self):
        # Some class parameters should overwrite each others.
        # The more specifics should prevail over the more generics.
        # Items annoted with a "<<" are the one that should prevail.
        default_arguments = {
            'cors_origins': mock.sentinel.default_cors_origins,
            'error_handler': mock.sentinel.default_error_handler,
            'cors_headers': mock.sentinel.default_cors_headers,  # <<
        }
        default_record_arguments = {
            'cors_origins': mock.sentinel.default_record_cors_origin,
            'error_handler': mock.sentinel.default_record_error_handler,  # <<
        }

        record_get_arguments = {
            'cors_origins': mock.sentinel.record_get_cors_origin,  # <<
        }

        viewset = ViewSet(
            default_arguments=default_arguments,
            default_record_arguments=default_record_arguments,
            record_get_arguments=record_get_arguments,
        )

        arguments = viewset.record_arguments(mock.MagicMock, 'get')
        arguments.pop('schema')

        self.assertDictEqual(
            arguments,
            {
                'cors_headers': mock.sentinel.default_cors_headers,
                'error_handler': mock.sentinel.default_record_error_handler,
                'cors_origins': mock.sentinel.record_get_cors_origin,
            }
        )
开发者ID:Prashant-Surya,项目名称:kinto,代码行数:37,代码来源:test_viewset.py

示例3: test_default_arguments_are_used_for_record_arguments

# 需要导入模块: from kinto.core.resource import ViewSet [as 别名]
# 或者: from kinto.core.resource.ViewSet import record_arguments [as 别名]
    def test_default_arguments_are_used_for_record_arguments(self, mocked):
        default_arguments = {"cors_headers": mock.sentinel.cors_headers}

        default_get_arguments = {"accept": mock.sentinel.accept}

        default_record_arguments = {"cors_origins": mock.sentinel.record_cors_origins}

        record_get_arguments = {"error_handler": mock.sentinel.error_handler}

        viewset = ViewSet(
            default_arguments=default_arguments,
            default_get_arguments=default_get_arguments,
            default_record_arguments=default_record_arguments,
            record_get_arguments=record_get_arguments,
        )

        viewset.responses = mock.MagicMock()
        arguments = viewset.record_arguments(mock.MagicMock(), "get")

        self.assertDictEqual(
            arguments,
            {
                "schema": mocked().bind(),
                "accept": mock.sentinel.accept,
                "cors_headers": mock.sentinel.cors_headers,
                "cors_origins": mock.sentinel.record_cors_origins,
                "error_handler": mock.sentinel.error_handler,
                "validators": [colander_validator],
                "response_schemas": viewset.responses.get_and_bind(),
            },
        )
开发者ID:pombredanne,项目名称:kinto,代码行数:33,代码来源:test_viewset.py

示例4: test_service_arguments_arent_inherited_by_record_arguments

# 需要导入模块: from kinto.core.resource import ViewSet [as 别名]
# 或者: from kinto.core.resource.ViewSet import record_arguments [as 别名]
    def test_service_arguments_arent_inherited_by_record_arguments(self, mocked):
        service_arguments = {"description": "The little book of calm"}

        default_arguments = {"cors_headers": mock.sentinel.cors_headers}
        viewset = ViewSet(
            default_arguments=default_arguments,
            service_arguments=service_arguments,
            default_record_arguments={},
            record_get_arguments={},
        )

        viewset.responses = mock.MagicMock()
        arguments = viewset.record_arguments(mock.MagicMock(), "get")

        self.assertDictEqual(
            arguments,
            {
                "schema": mocked().bind(),
                "cors_headers": mock.sentinel.cors_headers,
                "validators": [colander_validator],
                "response_schemas": viewset.responses.get_and_bind(),
            },
        )
开发者ID:pombredanne,项目名称:kinto,代码行数:25,代码来源:test_viewset.py

示例5: test_service_arguments_arent_inherited_by_record_arguments

# 需要导入模块: from kinto.core.resource import ViewSet [as 别名]
# 或者: from kinto.core.resource.ViewSet import record_arguments [as 别名]
    def test_service_arguments_arent_inherited_by_record_arguments(self):
        service_arguments = {
            'description': 'The little book of calm',
        }

        default_arguments = {
            'cors_headers': mock.sentinel.cors_headers,
        }

        viewset = ViewSet(
            default_arguments=default_arguments,
            service_arguments=service_arguments,
            default_record_arguments={},
            record_get_arguments={}
        )

        arguments = viewset.record_arguments(mock.MagicMock, 'get')
        arguments.pop('schema')
        self.assertDictEqual(
            arguments,
            {
                'cors_headers': mock.sentinel.cors_headers,
            }
        )
开发者ID:Prashant-Surya,项目名称:kinto,代码行数:26,代码来源:test_viewset.py

示例6: test_default_arguments_are_used_for_record_arguments

# 需要导入模块: from kinto.core.resource import ViewSet [as 别名]
# 或者: from kinto.core.resource.ViewSet import record_arguments [as 别名]
    def test_default_arguments_are_used_for_record_arguments(self):
        default_arguments = {
            'cors_headers': mock.sentinel.cors_headers,
        }

        default_get_arguments = {
            'accept': mock.sentinel.accept,
        }

        default_record_arguments = {
            'cors_origins': mock.sentinel.record_cors_origins,
        }

        record_get_arguments = {
            'error_handler': mock.sentinel.error_handler
        }

        viewset = ViewSet(
            default_arguments=default_arguments,
            default_get_arguments=default_get_arguments,
            default_record_arguments=default_record_arguments,
            record_get_arguments=record_get_arguments
        )

        arguments = viewset.record_arguments(mock.MagicMock, 'get')
        arguments.pop('schema')

        self.assertDictEqual(
            arguments,
            {
                'accept': mock.sentinel.accept,
                'cors_headers': mock.sentinel.cors_headers,
                'cors_origins': mock.sentinel.record_cors_origins,
                'error_handler': mock.sentinel.error_handler,
            }
        )
开发者ID:Prashant-Surya,项目名称:kinto,代码行数:38,代码来源:test_viewset.py

示例7: test_class_parameters_overwrite_each_others

# 需要导入模块: from kinto.core.resource import ViewSet [as 别名]
# 或者: from kinto.core.resource.ViewSet import record_arguments [as 别名]
    def test_class_parameters_overwrite_each_others(self, mocked):
        # Some class parameters should overwrite each others.
        # The more specifics should prevail over the more generics.
        # Items annoted with a "<<" are the one that should prevail.
        default_arguments = {
            "cors_origins": mock.sentinel.default_cors_origins,
            "error_handler": mock.sentinel.default_error_handler,
            "cors_headers": mock.sentinel.default_cors_headers,  # <<
        }
        default_record_arguments = {
            "cors_origins": mock.sentinel.default_record_cors_origin,
            "error_handler": mock.sentinel.default_record_error_handler,  # <<
        }

        record_get_arguments = {"cors_origins": mock.sentinel.record_get_cors_origin}  # <<

        viewset = ViewSet(
            default_arguments=default_arguments,
            default_record_arguments=default_record_arguments,
            record_get_arguments=record_get_arguments,
        )

        viewset.responses = mock.MagicMock()
        arguments = viewset.record_arguments(mock.MagicMock(), "get")

        self.assertDictEqual(
            arguments,
            {
                "schema": mocked().bind(),
                "cors_headers": mock.sentinel.default_cors_headers,
                "error_handler": mock.sentinel.default_record_error_handler,
                "cors_origins": mock.sentinel.record_get_cors_origin,
                "validators": [colander_validator],
                "response_schemas": viewset.responses.get_and_bind(),
            },
        )
开发者ID:pombredanne,项目名称:kinto,代码行数:38,代码来源:test_viewset.py


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