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

Python mock_request.savory_dispatch_batch函数代码示例

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

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



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

示例1: test_method_not_allowed

    def test_method_not_allowed(self):
        root_resource = mock_resource(
            name='root',
            base_regex=r'^api/v2/(?P<base_resource>.*)$'
        )

        root_resource.allowed_methods.add('POST')

        root_resource.get.side_effect = Exception

        request_data = {
            "data": [
                self._generate_batch_partial('get', 'http://localhost:8081/api/v2/', {'business_id': 12345})
            ]
        }
        body = json.dumps(request_data)
        response = savory_dispatch_batch(
            root_resource,
            full_host='localhost:8081',
            method='POST',
            body=body
        )
        self.assertEqual(response.status_code, 200)

        data = json.loads(response.content)['data']
        self.assertEqual(len(data), 1)
        self.assertEqual(data[0]['status'], 405)
        self.assertEqual(data[0]['allowed'], 'POST')
开发者ID:wware,项目名称:savory-pie,代码行数:28,代码来源:test_views.py


示例2: test_put_nocontent_batch

    def test_put_nocontent_batch(self):
        root_resource = self.create_root_resource_with_children(
            r'^api/v2/(?P<base_resource>.*)$',
            methods=['PUT'],
            result={}
        )
        request_data = {
            "data": [
                self._generate_batch_partial(
                    'put',
                    'http://localhost:8081/api/v2/child/grandchild',
                    {'business_id': 12345}
                )
            ]
        }
        response = savory_dispatch_batch(
            root_resource,
            full_host='localhost:8081',
            method='POST',
            body=json.dumps(request_data)
        )
        self.assertEqual(response.status_code, 200)

        response_json = json.loads(response.content)
        data = response_json['data']

        self.assertEqual(len(data), 1)
        self.assertEqual(data[0]['status'], 204)
        self.assertEqual(data[0]['uri'], 'http://localhost:8081/api/v2/child/grandchild')
        self.assertTrue('data' not in data[0])
开发者ID:wware,项目名称:savory-pie,代码行数:30,代码来源:test_views.py


示例3: test_one_fails_one_passes

    def test_one_fails_one_passes(self):
        root_resource = self.create_root_resource_with_children(
            r'^api/v2/(?P<base_resource>.*)$',
            methods=['PUT'],
            result={'name': 'value'}
        )

        request_data = {
            "data": [
                self._generate_batch_partial(
                    'put',
                    'http://localhost:8081/api/v2/child/grandchild',
                    {'business_id': 12345}
                ), self._generate_batch_partial(
                    'get',
                    'http://localhost:8081/api/v2/child',
                    {'business_id': 12345}
                )
            ]
        }

        response = savory_dispatch_batch(
            root_resource,
            full_host='localhost:8081',
            method='POST',
            body=json.dumps(request_data)
        )
        self.assertEqual(response.status_code, 200)

        response_json = json.loads(response.content)
        data = response_json['data']

        self.assertEqual(len(data), 2)
        self.assertEqual(data[0]['status'], 200)
        self.assertEqual(data[1]['status'], 405)
开发者ID:wware,项目名称:savory-pie,代码行数:35,代码来源:test_views.py


示例4: test_unauthorized_batch

    def test_unauthorized_batch(self):
        child_resource = mock_resource(name='child')
        root_resource = mock_resource(
            name='root',
            child_resource=child_resource,
            base_regex=r'^api/v2/(?P<base_resource>.*)$'
        )
        child_resource.allowed_methods.add('GET')
        child_resource.get.side_effect = AuthorizationError('foo')

        request_data = {
            "data": [
                self._generate_batch_partial('get', 'http://localhost:8081/api/v2/child', {'business_id': 12345})
            ]
        }
        body = json.dumps(request_data)
        response = savory_dispatch_batch(
            root_resource,
            full_host='localhost:8081',
            method='POST',
            body=body
        )
        self.assertEqual(response.status_code, 200)

        data = json.loads(response.content)['data']

        self.assertEqual(len(data), 1)
        self.assertEqual(data[0]['status'], 403)
        self.assertEqual(data[0]['validation_errors'], [u'Modification of field foo not authorized'])
开发者ID:wware,项目名称:savory-pie,代码行数:29,代码来源:test_views.py


示例5: test_exception_in_batch

    def test_exception_in_batch(self, format_exc):
        format_exc.return_value = 'some traceback'
        root_resource = mock_resource(
            name='root',
            base_regex=r'^api/v2/(?P<base_resource>.*)$'
        )

        root_resource.allowed_methods.add('GET')
        root_resource.allowed_methods.add('POST')

        root_resource.get.side_effect = Exception

        request_data = {
            "data": [
                self._generate_batch_partial('get', 'http://localhost:8081/api/v2/', {'business_id': 12345})
            ]
        }
        body = json.dumps(request_data)
        response = savory_dispatch_batch(
            root_resource,
            full_host='localhost:8081',
            method='POST',
            body=body
        )
        self.assertEqual(response.status_code, 200)

        data = json.loads(response.content)['data']
        self.assertEqual(len(data), 1)
        self.assertEqual(data[0]['status'], 500)
        self.assertEqual(data[0]['data'], {'error': 'some traceback'})
开发者ID:wware,项目名称:savory-pie,代码行数:30,代码来源:test_views.py


示例6: test_post_batch

    def test_post_batch(self):
        result = Mock(resource_path='grand_child_path')
        root_resource = self.create_root_resource_with_children(
            r'^api/v2/(?P<base_resource>.*)$',
            methods=['POST'],
            result=result
        )
        request_data = {
            "data": [
                self._generate_batch_partial('post', 'http://localhost:8081/api/v2/child/grandchild', {})
            ]
        }
        body = json.dumps(request_data)
        response = savory_dispatch_batch(
            root_resource,
            full_host='localhost:8081',
            method='POST',
            body=body
        )

        self.assertEqual(response.status_code, 200)

        response_json = json.loads(response.content)

        data = response_json['data']

        self.assertEqual(len(data), 1)
        self.assertEqual(data[0]['status'], 201)
        self.assertEqual(data[0]['uri'], 'http://localhost:8081/api/v2/child/grandchild')
        self.assertEqual(data[0]['location'], 'http://localhost:8081/api/v2/grand_child_path')
开发者ID:wware,项目名称:savory-pie,代码行数:30,代码来源:test_views.py


示例7: test_get_batch

    def test_get_batch(self):
        root_resource = self.create_root_resource_with_children(
            r'^api/v2/(?P<base_resource>.*)$',
            methods=['GET'],
            result={'name': 'value'}
        )
        request_data = {
            "data": [
                self._generate_batch_partial(
                    'get',
                    'http://localhost:8081/api/v2/child/grandchild',
                    {'business_id': 12345}
                )
            ]
        }
        response = savory_dispatch_batch(
            root_resource,
            full_host='localhost:8081',
            method='POST',
            body=json.dumps(request_data)
        )
        self.assertEqual(response.status_code, 200)

        response_json = json.loads(response.content)
        data = response_json['data']

        self.assertEqual(len(data), 1)
        self.assertEqual(data[0]['status'], 200)
        self.assertEqual(data[0]['uri'], 'http://localhost:8081/api/v2/child/grandchild')
        self.assertEqual(data[0]['data'], {u'name': u'value'})

        ctx = mock_context()
        ctx.formatter = JSONFormatter()

        self.assertEqual(data[0]['etag'], get_sha1(ctx, {u'name': u'value'}))
开发者ID:wware,项目名称:savory-pie,代码行数:35,代码来源:test_views.py


示例8: test_put_key_error_batch

    def test_put_key_error_batch(self):
        root_resource = mock_resource(
            name='root',
            base_regex=r'^api/v2/(?P<base_resource>.*)$'
        )

        root_resource.allowed_methods.add('PUT')

        root_resource.get.side_effect = KeyError('bad key message')

        request_data = {
            "data": [
                self._generate_batch_partial(
                    'put',
                    'http://localhost:8081/api/v2/',
                    {'business_id': 12345}
                )
            ]
        }
        response = savory_dispatch_batch(
            root_resource,
            full_host='localhost:8081',
            method='POST',
            body=json.dumps(request_data)
        )
        self.assertEqual(response.status_code, 200)

        data = json.loads(response.content)['data']
        self.assertEqual(len(data), 1)
        self.assertEqual(data[0]['status'], 400)
        self.assertEqual(data[0]['validation_errors'], {'missingData': 'bad key message'})
开发者ID:wware,项目名称:savory-pie,代码行数:31,代码来源:test_views.py


示例9: test_no_post_root_resource

    def test_no_post_root_resource(self):
        root_resource = self.create_root_resource_with_children(
            r'^api/v2/(?P<base_resource>.*)$',
            methods=['GET'],
            result={'name': 'value'}
        )
        request_data = {
            "data": [{"method": "get", "uri": "someurl", "body": {}}]
        }
        response = savory_dispatch_batch(
            root_resource,
            full_host='localhost:8081',
            method='GET',
            body=json.dumps(request_data)
        )

        self.assertEqual(response.status_code, 405)
开发者ID:wware,项目名称:savory-pie,代码行数:17,代码来源:test_views.py


示例10: test_post_with_collision_two_batch

    def test_post_with_collision_two_batch(self, enter):
        def side_effect(*args, **kwargs):
            # This could occur if a slightly earlier POST or PUT still had
            # the database locked during a DB transaction.
            from django.db.transaction import TransactionManagementError

            raise TransactionManagementError()

        enter.side_effect = side_effect

        child_resource = mock_resource(name='child')
        root_resource = mock_resource(
            name='root',
            child_resource=child_resource,
            base_regex=r'^api/v2/(?P<base_resource>.*)$'
        )
        child_resource.allowed_methods.add('POST')
        child_resource.get.side_effect = AuthorizationError('foo')

        request_data = {
            "data": [
                self._generate_batch_partial('post', 'http://localhost:8081/api/v2/child', {'id ': 12345})
            ]
        }

        response = savory_dispatch_batch(
            root_resource,
            full_host='localhost:8081',
            method='POST',
            body=json.dumps(request_data)
        )

        data = json.loads(response.content)['data']
        self.assertEqual(len(data), 1)

        self.assertEqual(data[0]['status'], 409)
        self.assertEqual(data[0]['uri'], 'http://localhost:8081/api/v2/child')
开发者ID:wware,项目名称:savory-pie,代码行数:37,代码来源:test_views.py


示例11: test_validation_exception_batch

    def test_validation_exception_batch(self):
        root_resource = mock_resource(
            name='root',
            base_regex=r'^api/v2/(?P<base_resource>.*)$'
        )

        root_resource.allowed_methods.add('POST')

        root_resource.post.side_effect = validators.ValidationError(
            Mock(),
            {
                'class.field': 'broken',
            }
        )

        request_data = {
            "data": [
                self._generate_batch_partial(
                    'post',
                    'http://localhost:8081/api/v2/',
                    {'business_id': 12345}
                )
            ]
        }

        response = savory_dispatch_batch(
            root_resource,
            full_host='localhost:8081',
            method='POST',
            body=json.dumps(request_data)
        )
        self.assertEqual(response.status_code, 200)

        data = json.loads(response.content)['data']
        self.assertEqual(len(data), 1)
        self.assertEqual(data[0]['status'], 400)
        self.assertEqual(data[0]['validation_errors'], {'class.field': 'broken'})
开发者ID:wware,项目名称:savory-pie,代码行数:37,代码来源:test_views.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python mock_context.mock_context函数代码示例发布时间:2022-05-27
下一篇:
Python mock_request.savory_dispatch函数代码示例发布时间: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