本文整理汇总了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')
示例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(),
},
)
示例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,
}
)
示例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)
示例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,
}
)
示例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')
示例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)
示例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)
示例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)
示例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)
示例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)
示例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()
示例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')
示例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)
示例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(),
},
)