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


Python resource.ViewSet类代码示例

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


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

示例1: test_get_service_name_returns_resource_att_if_not_callable

 def test_get_service_name_returns_resource_att_if_not_callable(self):
     viewset = ViewSet()
     resource = mock.MagicMock()
     resource.name = 'fakename'
     self.assertEquals(
         viewset.get_service_name('record', resource),
         'fakename-record')
开发者ID:Prashant-Surya,项目名称:kinto,代码行数:7,代码来源:test_viewset.py

示例2: test_class_parameters_are_used_for_collection_arguments

    def test_class_parameters_are_used_for_collection_arguments(self, mocked):
        default_arguments = {"cors_headers": mock.sentinel.cors_headers}

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

        default_collection_arguments = {"cors_origins": mock.sentinel.cors_origins}

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

        viewset = ViewSet(
            default_arguments=default_arguments,
            default_get_arguments=default_get_arguments,
            default_collection_arguments=default_collection_arguments,
            collection_get_arguments=collection_get_arguments,
        )

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

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

示例3: test_class_parameters_overwrite_each_others

    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,代码行数:35,代码来源:test_viewset.py

示例4: test_default_arguments_are_copied_before_being_returned

 def test_default_arguments_are_copied_before_being_returned(self):
     original_arguments = {}
     viewset = ViewSet(collection_get_arguments=original_arguments)
     viewset.responses = mock.MagicMock()
     arguments = viewset.collection_arguments(mock.MagicMock(), "GET")
     self.assertEqual(original_arguments, {})
     self.assertNotEquals(original_arguments, arguments)
开发者ID:pombredanne,项目名称:kinto,代码行数:7,代码来源:test_viewset.py

示例5: test_class_parameters_are_used_for_collection_arguments

    def test_class_parameters_are_used_for_collection_arguments(self):
        default_arguments = {
            'cors_headers': mock.sentinel.cors_headers,
        }

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

        default_collection_arguments = {
            'cors_origins': mock.sentinel.cors_origins,
        }

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

        viewset = ViewSet(
            default_arguments=default_arguments,
            default_get_arguments=default_get_arguments,
            default_collection_arguments=default_collection_arguments,
            collection_get_arguments=collection_get_arguments
        )

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

示例6: test_get_service_name_doesnt_use_callable_as_a_name

 def test_get_service_name_doesnt_use_callable_as_a_name(self):
     viewset = ViewSet()
     resource = mock.MagicMock()
     resource.name = lambda x: 'should not be called'
     resource.__name__ = "FakeName"
     self.assertEquals(
         viewset.get_service_name('record', resource),
         'fakename-record')
开发者ID:Prashant-Surya,项目名称:kinto,代码行数:8,代码来源:test_viewset.py

示例7: test_is_endpoint_enabled_returns_true_if_enabled

 def test_is_endpoint_enabled_returns_true_if_enabled(self):
     viewset = ViewSet()
     config = {
         'record_fake_get_enabled': True
     }
     is_enabled = viewset.is_endpoint_enabled('record', 'fake', 'get',
                                              config)
     self.assertTrue(is_enabled)
开发者ID:Prashant-Surya,项目名称:kinto,代码行数:8,代码来源:test_viewset.py

示例8: test_is_endpoint_enabled_returns_false_for_delete_if_readonly

 def test_is_endpoint_enabled_returns_false_for_delete_if_readonly(self):
     viewset = ViewSet()
     config = {
         'readonly': True
     }
     is_enabled = viewset.is_endpoint_enabled('record', 'fake', 'delete',
                                              config)
     self.assertFalse(is_enabled)
开发者ID:Prashant-Surya,项目名称:kinto,代码行数:8,代码来源:test_viewset.py

示例9: test_is_endpoint_enabled_returns_true_for_head_if_readonly

 def test_is_endpoint_enabled_returns_true_for_head_if_readonly(self):
     viewset = ViewSet()
     config = {
         'readonly': True
     }
     is_enabled = viewset.is_endpoint_enabled('record', 'fake', 'head',
                                              config)
     self.assertTrue(is_enabled)
开发者ID:Prashant-Surya,项目名称:kinto,代码行数:8,代码来源:test_viewset.py

示例10: test_schema_is_added_when_uppercase_method_matches

 def test_schema_is_added_when_uppercase_method_matches(self):
     viewset = ViewSet(
         validate_schema_for=('GET', )
     )
     resource = mock.MagicMock(mapping=colander.SchemaNode(colander.Int()))
     arguments = viewset.collection_arguments(resource, 'get')
     schema = arguments['schema']
     self.assertEquals(schema.children[0], resource.mapping)
开发者ID:Prashant-Surya,项目名称:kinto,代码行数:8,代码来源:test_viewset.py

示例11: test_default_arguments_are_copied_before_being_returned

 def test_default_arguments_are_copied_before_being_returned(self):
     original_arguments = {}
     viewset = ViewSet(
         collection_get_arguments=original_arguments,
         validate_schema_for=()
     )
     arguments = viewset.collection_arguments(mock.sentinel.resource, 'GET')
     self.assertEquals(original_arguments, {})
     self.assertNotEquals(original_arguments, arguments)
开发者ID:Prashant-Surya,项目名称:kinto,代码行数:9,代码来源:test_viewset.py

示例12: test_a_default_schema_is_added_when_method_doesnt_match

    def test_a_default_schema_is_added_when_method_doesnt_match(self, mocked):
        viewset = ViewSet()
        resource = mock.MagicMock()
        viewset.responses = mock.MagicMock()
        mocked.Mapping.return_value = mock.sentinel.default_schema

        arguments = viewset.collection_arguments(resource, "GET")
        self.assertNotEqual(arguments["schema"], resource.schema)

        mocked.assert_called_with()
开发者ID:pombredanne,项目名称:kinto,代码行数:10,代码来源:test_viewset.py

示例13: test_a_default_schema_is_added_when_method_doesnt_match

    def test_a_default_schema_is_added_when_method_doesnt_match(self, mocked):
        viewset = ViewSet(
            validate_schema_for=('GET', )
        )
        resource = mock.MagicMock()
        mocked.MappingSchema.return_value = mock.sentinel.default_schema

        arguments = viewset.collection_arguments(resource, 'POST')
        self.assertEquals(arguments['schema'], mock.sentinel.default_schema)
        self.assertNotEqual(arguments['schema'], resource.mapping)

        mocked.MappingSchema.assert_called_with(unknown='preserve')
开发者ID:Prashant-Surya,项目名称:kinto,代码行数:12,代码来源:test_viewset.py

示例14: test_request_schemas_have_header_and_querystring

 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)
开发者ID:pombredanne,项目名称:kinto,代码行数:8,代码来源:test_viewset.py

示例15: test_service_arguments_arent_inherited_by_record_arguments

    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,代码行数:23,代码来源:test_viewset.py


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