Python rest_framework.status 模块,HTTP_302_FOUND 实例源码

我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用rest_framework.status.HTTP_302_FOUND

项目:micromasters    作者:mitodl    | 项目源码 | 文件源码
def test_success(self):
        """
        Test /pearson/success URL
        """
        response = self.client.get('/pearson/success/')
        assert response.status_code == status.HTTP_302_FOUND
        assert response.url == "/dashboard?exam=success"
项目:micromasters    作者:mitodl    | 项目源码 | 文件源码
def test_error(self):
        """
        Test /pearson/error URL
        """
        response = self.client.get('/pearson/error/')
        assert response.status_code == status.HTTP_302_FOUND
        assert response.url == "/dashboard?exam=error"
项目:micromasters    作者:mitodl    | 项目源码 | 文件源码
def test_timeout(self):
        """
        Test /pearson/error URL
        """
        response = self.client.get('/pearson/timeout/')
        assert response.status_code == status.HTTP_302_FOUND
        assert response.url == "/dashboard?exam=timeout"
项目:micromasters    作者:mitodl    | 项目源码 | 文件源码
def test_logout(self):
        """
        Test /pearson/logout URL
        """
        response = self.client.get('/pearson/logout/')
        assert response.status_code == status.HTTP_302_FOUND
        assert response.url == "/dashboard?exam=logout"
项目:jianshu-api    作者:strugglingyouth    | 项目源码 | 文件源码
def render(self, data, accepted_media_type=None, renderer_context=None):
        self.accepted_media_type = accepted_media_type or ''
        self.renderer_context = renderer_context or {}

        response = renderer_context['response']
        request = renderer_context['request']
        view = self.renderer_context['view']

        if response.status_code == status.HTTP_400_BAD_REQUEST:
            # Errors still need to display the list or detail information.
            # The only way we can get at that is to simulate a GET request.
            self.error_form = self.get_rendered_html_form(data, view, request.method, request)
            self.error_title = {'POST': 'Create', 'PUT': 'Edit'}.get(request.method, 'Errors')

            with override_method(view, request, 'GET') as request:
                response = view.get(request, *view.args, **view.kwargs)
            data = response.data

        template = loader.get_template(self.template)
        context = self.get_context(data, accepted_media_type, renderer_context)
        ret = template_render(template, context, request=renderer_context['request'])

        # Creation and deletion should use redirects in the admin style.
        if (response.status_code == status.HTTP_201_CREATED) and ('Location' in response):
            response.status_code = status.HTTP_302_FOUND
            response['Location'] = request.build_absolute_uri()
            ret = ''

        if response.status_code == status.HTTP_204_NO_CONTENT:
            response.status_code = status.HTTP_302_FOUND
            try:
                # Attempt to get the parent breadcrumb URL.
                response['Location'] = self.get_breadcrumbs(request)[-2][1]
            except KeyError:
                # Otherwise reload current URL to get a 'Not Found' page.
                response['Location'] = request.full_path
            ret = ''

        return ret
项目:odl-video-service    作者:mitodl    | 项目源码 | 文件源码
def test_index(client):
    """Test index anonymous"""
    response = client.get(reverse('index'))
    assert response.status_code == status.HTTP_302_FOUND
    assert response.url == reverse('collection-react-view')
项目:django-fb-oauth    作者:Tuss4    | 项目源码 | 文件源码
def test_fb_login(self):
        url = reverse('fb-login')
        r = self.client.get(url)
        self.assertEqual(r.status_code, status.HTTP_302_FOUND)
项目:api-django    作者:lafranceinsoumise    | 项目源码 | 文件源码
def test_cannot_access_hard_login_page_while_soft_logged_in(self):
        self.client.force_login(self.person.role, self.soft_backend)

        response = self.client.get(reverse('create_event'))

        self.assertRedirects(
            response, reverse('oauth_redirect_view') + '?next=' + reverse('create_event'),
            target_status_code=status.HTTP_302_FOUND
        )
项目:api-django    作者:lafranceinsoumise    | 项目源码 | 文件源码
def test_unsubscribe_redirects_to_message_preferences_when_logged(self):
        message_preferences_path = reverse('message_preferences')
        unsubscribe_path = reverse('unsubscribe')

        self.client.force_login(self.person.role)
        response = self.client.get(unsubscribe_path)
        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
        target_url = urlparse(response.url)
        self.assertEqual(target_url.path, message_preferences_path)
项目:django-oscar-cybersource    作者:thelabnyc    | 项目源码 | 文件源码
def test_free_product(self):
        """Full checkout process using minimal api calls"""
        product = self.create_product(price=D('0.00'))

        resp = self.do_get_basket()
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        basket_id = resp.data['id']

        resp = self.do_add_to_basket(product.id)
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        resp = self.do_checkout(basket_id)
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        order_number = resp.data['number']

        resp = self.do_fetch_payment_states()
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        self.assertEqual(resp.data['order_status'], 'Pending')
        self.assertEqual(resp.data['payment_method_states']['cybersource']['required_action']['name'], 'get-token')

        action = resp.data['payment_method_states']['cybersource']['required_action']
        resp = self.do_cs_get_token(action['url'], action['fields'])
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)

        resp = self.do_fetch_payment_states()
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        self.assertEqual(resp.data['order_status'], 'Pending')
        self.assertEqual(resp.data['payment_method_states']['cybersource']['required_action']['name'], 'authorize')

        action = resp.data['payment_method_states']['cybersource']['required_action']
        resp = self.do_cs_auth(action['url'], action['fields'])
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)

        resp = self.do_fetch_payment_states()
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        self.assertEqual(resp.data['order_status'], 'Authorized')
        self.assertEqual(resp.data['payment_method_states']['cybersource']['amount'], '0.00')
        self.check_finished_order(order_number, product.id)
项目:email-service    作者:telminov    | 项目源码 | 文件源码
def test_auth(self):

        response = self.client.get(self.url)

        self.assertEqual(response.status_code, status.HTTP_302_FOUND)
项目:django-oscar-cybersource    作者:thelabnyc    | 项目源码 | 文件源码
def test_checkout_process(self):
        """Full checkout process using minimal api calls"""
        product = self.create_product()

        resp = self.do_get_basket()
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        basket_id = resp.data['id']

        resp = self.do_add_to_basket(product.id)
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        resp = self.do_checkout(basket_id)
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        order_number = resp.data['number']

        resp = self.do_fetch_payment_states()
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        self.assertEqual(resp.data['order_status'], 'Pending')
        self.assertEqual(resp.data['payment_method_states']['cybersource']['status'], 'Pending')
        self.assertEqual(resp.data['payment_method_states']['cybersource']['amount'], '10.00')
        self.assertEqual(resp.data['payment_method_states']['cybersource']['required_action']['name'], 'get-token')

        action = resp.data['payment_method_states']['cybersource']['required_action']
        resp = self.do_cs_get_token(action['url'], action['fields'])
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)

        resp = self.do_fetch_payment_states()
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        self.assertEqual(resp.data['order_status'], 'Pending')
        self.assertEqual(resp.data['payment_method_states']['cybersource']['status'], 'Pending')
        self.assertEqual(resp.data['payment_method_states']['cybersource']['amount'], '10.00')
        self.assertEqual(resp.data['payment_method_states']['cybersource']['required_action']['name'], 'authorize')

        action = resp.data['payment_method_states']['cybersource']['required_action']

        resp = self.do_cs_auth(action['url'], action['fields'])
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)

        resp = self.do_fetch_payment_states()
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        self.assertEqual(resp.data['order_status'], 'Authorized')
        self.assertEqual(resp.data['payment_method_states']['cybersource']['status'], 'Complete')
        self.assertEqual(resp.data['payment_method_states']['cybersource']['amount'], '10.00')
        self.assertIsNone(resp.data['payment_method_states']['cybersource']['required_action'])

        self.check_finished_order(order_number, product.id)
项目:django-oscar-cybersource    作者:thelabnyc    | 项目源码 | 文件源码
def test_add_product_during_auth(self):
        """Test attempting to add a product during the authorize flow"""
        product = self.create_product()

        resp = self.do_get_basket()
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        basket_id = resp.data['id']

        # Adding a product here should succeed
        resp = self.do_add_to_basket(product.id)
        basket1 = resp.data['id']
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        resp = self.do_checkout(basket_id)
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        order_number = resp.data['number']

        # Adding a product here should go to a new basket, not the one we're auth'ing
        resp = self.do_add_to_basket(product.id)
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        basket2 = resp.data['id']
        self.assertNotEqual(basket1, basket2)

        # Finish checkout process
        resp = self.do_fetch_payment_states()
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        self.assertEqual(resp.data['order_status'], 'Pending')
        self.assertEqual(resp.data['payment_method_states']['cybersource']['required_action']['name'], 'get-token')

        action = resp.data['payment_method_states']['cybersource']['required_action']
        resp = self.do_cs_get_token(action['url'], action['fields'])
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)

        resp = self.do_fetch_payment_states()
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        self.assertEqual(resp.data['order_status'], 'Pending')
        self.assertEqual(resp.data['payment_method_states']['cybersource']['required_action']['name'], 'authorize')

        action = resp.data['payment_method_states']['cybersource']['required_action']
        resp = self.do_cs_auth(action['url'], action['fields'])
        self.assertEqual(resp.status_code, status.HTTP_302_FOUND)

        resp = self.do_fetch_payment_states()
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        self.assertEqual(resp.data['order_status'], 'Authorized')
        self.check_finished_order(order_number, product.id)

        # Adding a product here should go to basket2, not basket1
        resp = self.do_add_to_basket(product.id)
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        basket3 = resp.data['id']
        self.assertEqual(basket2, basket3)
项目:django-async-rest    作者:Netsach    | 项目源码 | 文件源码
def test_invalid_values(self):
        resource_name = 'rotted-french-fries'
        handler = Handler('test_invalid_values')

        def made_to_fail(order_uuid, **kwargs):
            order = Order.objects.get(uuid=order_uuid)
            with fail_on_error(order, 'msg', status='failed'):

                raise Exception('I was made to fail')

        # Register invalid call back (logged through logging/error)
        dispatcher.register(resource_name, made_to_fail, 'queued')
        dispatcher.register(resource_name, handler.failed_task, 'failed')

        # Place an invalid order
        res = self.client.post(
            reverse('async-rest:place-order', kwargs={'resource_name':resource_name}),
            {
                'context': {}
            },
            format='json'
        )
        self.assertEqual(res.status_code, status.HTTP_302_FOUND)
        # Retrieve order and get status

        res = self.client.get(res.url)
        # Test assertions
        self.assertEqual(res.data['status'], 'failed')
        self.assertEqual(handler.count, 1)

        # Place another invalid order
        res = self.client.post(
            reverse('async-rest:place-order', kwargs={'resource_name':resource_name}),
            {
                'context': '"size": "XL"'
            },
            format='json'
        )
        # Retrieve error
        context = res.data.get('context')
        self.assertIsNotNone(context)
        self.assertTrue(context[0].endswith('is not a valid JSON string.'))