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

Python wrappers.apply_privacy函数代码示例

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

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



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

示例1: test_simple_call_with_nested

    def test_simple_call_with_nested(self, mock_eng):
        document_cls = Mock(
            _public_fields=['name', 'desc'],
            _auth_fields=['id', 'creator'],
            _hidden_fields=[])
        mock_eng.get_document_cls.return_value = document_cls
        request = Mock(user=Mock())
        data = {
            'id': 1,
            '_type': 'foo1',
            'username': 'admin',
            'creator': {
                'id': 2,
                '_type': 'foo2',
                'creator': 'foo',
                'address': 'adsasd',
            }
        }
        filtered = wrappers.apply_privacy(request)(
            result=data, is_admin=False)
        assert filtered == {
            '_type': 'foo1',
            'id': 1,
            'creator': {
                '_type': 'foo2',
                'creator': 'foo',
                'id': 2
            }

        }
开发者ID:mbijon,项目名称:nefertari,代码行数:30,代码来源:test_wrappers.py


示例2: test_apply_privacy_item_no_document_cls

 def test_apply_privacy_item_no_document_cls(self, mock_eng):
     mock_eng.get_document_cls.side_effect = ValueError
     request = Mock(user=Mock())
     filtered = wrappers.apply_privacy(request)(
         result=self.model_test_data, is_admin=True)
     assert list(sorted(filtered.keys())) == [
         '_type', 'desc', 'id', 'name', 'other_field', 'self']
开发者ID:karthikmm,项目名称:nefertari,代码行数:7,代码来源:test_wrappers.py


示例3: test_apply_privacy_item_no_request

 def test_apply_privacy_item_no_request(self, mock_eng):
     document_cls = Mock(
         _public_fields=['name', 'desc'],
         _auth_fields=['id'])
     mock_eng.get_document_cls.return_value = document_cls
     filtered = wrappers.apply_privacy(None)(result=self.model_test_data)
     assert list(sorted(filtered.keys())) == [
         '_type', 'desc', 'id', 'name', 'other_field', 'self']
开发者ID:karthikmm,项目名称:nefertari,代码行数:8,代码来源:test_wrappers.py


示例4: setup_default_wrappers

    def setup_default_wrappers(self):
        """ Setup defaulf wrappers.

        Wrappers are applied when view method does not return instance
        of Response. In this case nefertari renderers call wrappers and
        handle response generation.

        Note: It's important for `add_etag` wrapper be applied before
        `apply_privacy` as later may remove response data that
        is used to generate etag
        """
        # Index
        self._after_calls['index'] = [
            wrappers.wrap_in_dict(self.request),
            wrappers.add_meta(self.request),
            wrappers.add_object_url(self.request),
            wrappers.add_etag(self.request),
        ]

        # Show
        self._after_calls['show'] = [
            wrappers.wrap_in_dict(self.request),
            wrappers.add_meta(self.request),
            wrappers.add_object_url(self.request),
        ]

        # Create
        self._after_calls['create'] = [
            wrappers.wrap_in_dict(self.request),
            wrappers.add_meta(self.request),
            wrappers.add_object_url(self.request),
        ]

        # Update
        self._after_calls['update'] = [
            wrappers.wrap_in_dict(self.request),
            wrappers.add_meta(self.request),
            wrappers.add_object_url(self.request),
        ]

        # Replace
        self._after_calls['replace'] = [
            wrappers.wrap_in_dict(self.request),
            wrappers.add_meta(self.request),
            wrappers.add_object_url(self.request),
        ]

        # Privacy wrappers
        if self._auth_enabled:
            for meth in ('index', 'show', 'create', 'update', 'replace'):
                self._after_calls[meth] += [
                    wrappers.apply_privacy(self.request),
                ]
            for meth in ('update', 'replace', 'update_many'):
                self._before_calls[meth] += [
                    wrappers.apply_request_privacy(
                        self.Model, self._json_params),
                ]
开发者ID:mbijon,项目名称:nefertari,代码行数:58,代码来源:view.py


示例5: test_apply_privacy_item_no_fields

 def test_apply_privacy_item_no_fields(self, mock_eng):
     document_cls = Mock(
         _public_fields=['name', 'desc'],
         _auth_fields=[])
     mock_eng.get_document_cls.return_value = document_cls
     request = Mock(user=Mock())
     filtered = wrappers.apply_privacy(request)(
         result=self.model_test_data, is_admin=False)
     assert list(sorted(filtered.keys())) == ['_type', 'self']
开发者ID:karthikmm,项目名称:nefertari,代码行数:9,代码来源:test_wrappers.py


示例6: test_item_non_auth

 def test_item_non_auth(self, mock_eng):
     document_cls = Mock(
         _public_fields=['name', 'desc'],
         _auth_fields=['id'],
         _hidden_fields=[])
     mock_eng.get_document_cls.return_value = document_cls
     request = Mock(user=None)
     filtered = wrappers.apply_privacy(request)(result=self.model_test_data)
     assert list(sorted(filtered.keys())) == [
         '_pk', '_self', '_type', 'desc', 'name']
开发者ID:mbijon,项目名称:nefertari,代码行数:10,代码来源:test_wrappers.py


示例7: test_collection

 def test_collection(self, mock_eng):
     document_cls = Mock(_public_fields=["name", "desc"], _auth_fields=["id"], _hidden_fields=[])
     mock_eng.get_document_cls.return_value = document_cls
     request = Mock(user=Mock())
     result = {"total": 1, "count": 1, "data": [self.model_test_data]}
     filtered = wrappers.apply_privacy(request)(result=result, is_admin=False)
     assert list(sorted(filtered.keys())) == ["count", "data", "total"]
     assert len(filtered["data"]) == 1
     data = filtered["data"][0]
     assert list(sorted(data.keys())) == ["_pk", "_self", "_type", "id"]
开发者ID:geniusproject,项目名称:nefertari,代码行数:10,代码来源:test_wrappers.py


示例8: test_no_type

 def test_no_type(self, mock_eng):
     data = self.model_test_data.copy()
     data.pop("_type")
     request = Mock(user=Mock())
     filtered = wrappers.apply_privacy(request)(result=data, is_admin=True)
     assert list(sorted(filtered.keys())) == ["_pk", "_self", "desc", "id", "name", "other_field"]
     filtered["desc"] == "User 1 data"
     filtered["id"] == 1
     filtered["name"] == "User1"
     filtered["other_field"] == 123
     filtered["_self"] == "http://example.com/1"
     assert not mock_eng.get_document_cls.called
开发者ID:geniusproject,项目名称:nefertari,代码行数:12,代码来源:test_wrappers.py


示例9: test_item_auth_calculated

    def test_item_auth_calculated(self, mock_eng):
        document_cls = Mock(_public_fields=["name", "desc"], _auth_fields=["id"], _hidden_fields=[])
        mock_eng.get_document_cls.return_value = document_cls

        class User(object):
            @classmethod
            def is_admin(self, obj):
                return False

        request = Mock(user=User())
        filtered = wrappers.apply_privacy(request)(result=self.model_test_data)
        assert list(sorted(filtered.keys())) == ["_pk", "_self", "_type", "id"]
开发者ID:geniusproject,项目名称:nefertari,代码行数:12,代码来源:test_wrappers.py


示例10: test_hidden_fields_not_drop

 def test_hidden_fields_not_drop(self, mock_eng):
     document_cls = Mock(
         _public_fields=['name', 'desc'],
         _auth_fields=['id'],
         _hidden_fields=['name'])
     mock_eng.get_document_cls.return_value = document_cls
     request = Mock(user=Mock())
     filtered = wrappers.apply_privacy(request)(
         result=self.model_test_data, is_admin=False,
         drop_hidden=False)
     assert list(sorted(filtered.keys())) == [
         '_pk', '_self', '_type', 'id', 'name']
开发者ID:mbijon,项目名称:nefertari,代码行数:12,代码来源:test_wrappers.py


示例11: test_apply_nested_privacy_list

 def test_apply_nested_privacy_list(self, mock_eng):
     document_cls = Mock(_public_fields=["name", "desc"], _auth_fields=["id"], _hidden_fields=[])
     mock_eng.get_document_cls.return_value = document_cls
     request = Mock(user=Mock())
     data = {"owner": [self.model_test_data]}
     wrapper = wrappers.apply_privacy(request)
     wrapper.is_admin = False
     wrapper.drop_hidden = False
     filtered = wrapper._apply_nested_privacy(data)
     assert list(filtered.keys()) == ["owner"]
     owner = filtered["owner"][0]
     assert sorted(owner.keys()) == ["_pk", "_self", "_type", "id"]
开发者ID:geniusproject,项目名称:nefertari,代码行数:12,代码来源:test_wrappers.py


示例12: test_simple_call_with_nested

 def test_simple_call_with_nested(self, mock_eng):
     document_cls = Mock(_public_fields=["name", "desc"], _auth_fields=["id", "creator"], _hidden_fields=[])
     mock_eng.get_document_cls.return_value = document_cls
     request = Mock(user=Mock())
     data = {
         "id": 1,
         "_type": "foo1",
         "username": "admin",
         "creator": {"id": 2, "_type": "foo2", "creator": "foo", "address": "adsasd"},
     }
     filtered = wrappers.apply_privacy(request)(result=data, is_admin=False)
     assert filtered == {"_type": "foo1", "id": 1, "creator": {"_type": "foo2", "creator": "foo", "id": 2}}
开发者ID:geniusproject,项目名称:nefertari,代码行数:12,代码来源:test_wrappers.py


示例13: test_item_admin

 def test_item_admin(self, mock_eng):
     document_cls = Mock(_public_fields=["name", "desc"], _auth_fields=["id"], _hidden_fields=[])
     mock_eng.get_document_cls.return_value = document_cls
     request = Mock(user=Mock())
     filtered = wrappers.apply_privacy(request)(result=self.model_test_data, is_admin=True)
     assert list(sorted(filtered.keys())) == ["_pk", "_self", "_type", "desc", "id", "name", "other_field"]
     filtered["_type"] == "foo"
     filtered["desc"] == "User 1 data"
     filtered["id"] == 1
     filtered["name"] == "User1"
     filtered["other_field"] == 123
     filtered["_self"] == "http://example.com/1"
     mock_eng.get_document_cls.assert_called_once_with("foo")
开发者ID:geniusproject,项目名称:nefertari,代码行数:13,代码来源:test_wrappers.py


示例14: test_apply_privacy_no_type

 def test_apply_privacy_no_type(self, mock_eng):
     data = self.model_test_data.copy()
     data.pop('_type')
     request = Mock(user=Mock())
     filtered = wrappers.apply_privacy(request)(
         result=data, is_admin=True)
     assert list(sorted(filtered.keys())) == [
         'desc', 'id', 'name', 'other_field', 'self']
     filtered['desc'] == 'User 1 data'
     filtered['id'] == 1
     filtered['name'] == 'User1'
     filtered['other_field'] == 123
     filtered['self'] == 'http://example.com/1'
     assert not mock_eng.get_document_cls.called
开发者ID:karthikmm,项目名称:nefertari,代码行数:14,代码来源:test_wrappers.py


示例15: test_apply_privacy_item_auth_calculated

    def test_apply_privacy_item_auth_calculated(self, mock_eng):
        document_cls = Mock(
            _public_fields=['name', 'desc'],
            _auth_fields=['id'])
        mock_eng.get_document_cls.return_value = document_cls

        class User(object):
            @classmethod
            def is_admin(self, obj):
                return False

        request = Mock(user=User())
        filtered = wrappers.apply_privacy(request)(result=self.model_test_data)
        assert list(sorted(filtered.keys())) == [
            '_type', 'id', 'self']
开发者ID:karthikmm,项目名称:nefertari,代码行数:15,代码来源:test_wrappers.py


示例16: setup_default_wrappers

    def setup_default_wrappers(self):
        root_resource = getattr(self, 'root_resource', None)
        auth_enabled = root_resource and root_resource.auth

        self._after_calls['index'] = [
            wrappers.wrap_in_dict(self.request),
            wrappers.add_meta(self.request),
        ]
        if auth_enabled:
            self._after_calls['index'] += [
                wrappers.apply_privacy(self.request),
            ]
        self._after_calls['index'] += [
            wrappers.add_etag(self.request),
        ]

        self._after_calls['show'] = [
            wrappers.wrap_in_dict(self.request),
            wrappers.add_meta(self.request),
        ]
        if auth_enabled:
            self._after_calls['show'] += [
                wrappers.apply_privacy(self.request),
            ]

        self._after_calls['delete'] = [
            wrappers.add_confirmation_url(self.request)
        ]

        self._after_calls['delete_many'] = [
            wrappers.add_confirmation_url(self.request)
        ]

        self._after_calls['update_many'] = [
            wrappers.add_confirmation_url(self.request)
        ]
开发者ID:karthikmm,项目名称:nefertari,代码行数:36,代码来源:view.py


示例17: test_apply_nested_privacy_list

 def test_apply_nested_privacy_list(self, mock_eng):
     document_cls = Mock(
         _public_fields=['name', 'desc'],
         _auth_fields=['id'],
         _hidden_fields=[])
     mock_eng.get_document_cls.return_value = document_cls
     request = Mock(user=Mock())
     data = {'owner': [self.model_test_data]}
     wrapper = wrappers.apply_privacy(request)
     wrapper.is_admin = False
     wrapper.drop_hidden = False
     filtered = wrapper._apply_nested_privacy(data)
     assert list(filtered.keys()) == ['owner']
     owner = filtered['owner'][0]
     assert sorted(owner.keys()) == [
         '_pk', '_self', '_type', 'id']
开发者ID:mbijon,项目名称:nefertari,代码行数:16,代码来源:test_wrappers.py


示例18: test_apply_privacy_item_admin

 def test_apply_privacy_item_admin(self, mock_eng):
     document_cls = Mock(
         _public_fields=['name', 'desc'],
         _auth_fields=['id'])
     mock_eng.get_document_cls.return_value = document_cls
     request = Mock(user=Mock())
     filtered = wrappers.apply_privacy(request)(
         result=self.model_test_data, is_admin=True)
     assert list(sorted(filtered.keys())) == [
         '_type', 'desc', 'id', 'name', 'other_field', 'self']
     filtered['_type'] == 'foo'
     filtered['desc'] == 'User 1 data'
     filtered['id'] == 1
     filtered['name'] == 'User1'
     filtered['other_field'] == 123
     filtered['self'] == 'http://example.com/1'
     mock_eng.get_document_cls.assert_called_once_with('foo')
开发者ID:karthikmm,项目名称:nefertari,代码行数:17,代码来源:test_wrappers.py


示例19: __init__

    def __init__(self, *args, **kwargs):
        resource = kwargs.pop('resource', None)
        encoder = kwargs.pop('encoder', None)
        request = kwargs.pop('request', None)
        super(JHTTPCreated, self).__init__(*args, **kwargs)

        if resource and 'location' in kwargs:
            resource['self'] = kwargs['location']

        auth = request and request.registry._root_resources.values()[0].auth
        if resource and auth:
            wrapper = apply_privacy(request=request)
            resource = wrapper(result=resource)

        create_json_response(
            self, data=resource,
            encoder=encoder)
开发者ID:karthikmm,项目名称:nefertari,代码行数:17,代码来源:json_httpexceptions.py


示例20: test_apply_privacy_collection

 def test_apply_privacy_collection(self, mock_eng):
     document_cls = Mock(
         _public_fields=['name', 'desc'],
         _auth_fields=['id'])
     mock_eng.get_document_cls.return_value = document_cls
     request = Mock(user=Mock())
     result = {
         'total': 1,
         'count': 1,
         'data': [self.model_test_data]
     }
     filtered = wrappers.apply_privacy(request)(
         result=result, is_admin=False)
     assert list(sorted(filtered.keys())) == ['count', 'data', 'total']
     assert len(filtered['data']) == 1
     data = filtered['data'][0]
     assert list(sorted(data.keys())) == ['_type', 'id', 'self']
开发者ID:karthikmm,项目名称:nefertari,代码行数:17,代码来源:test_wrappers.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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