當前位置: 首頁>>代碼示例>>Python>>正文


Python HTTPStatus.FOUND屬性代碼示例

本文整理匯總了Python中http.HTTPStatus.FOUND屬性的典型用法代碼示例。如果您正苦於以下問題:Python HTTPStatus.FOUND屬性的具體用法?Python HTTPStatus.FOUND怎麽用?Python HTTPStatus.FOUND使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在http.HTTPStatus的用法示例。


在下文中一共展示了HTTPStatus.FOUND屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_dupe_email_login

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import FOUND [as 別名]
def test_dupe_email_login(self, testapp, db, person, carpool):
        # Steve logs in once using his Facebook account
        res = login(testapp, 'steve@facebook', 'stevejobs', 'steve@example.com')
        assert res.status_code == HTTPStatus.FOUND
        url = urllib.parse.urlparse(res.headers['Location'])
        assert url.path == '/profile'

        # ... then logs out
        res = testapp.post('/logout')
        assert res.status_code == HTTPStatus.FOUND
        url = urllib.parse.urlparse(res.headers['Location'])
        assert url.path == '/'

        # Steve tries to login again, this time using Google
        res = login(testapp, 'steve@google', 'stevejobs', 'steve@example.com')
        assert res.status_code == HTTPStatus.FOUND
        url = urllib.parse.urlparse(res.headers['Location'])
        assert url.path == '/login' 
開發者ID:RagtagOpen,項目名稱:nomad,代碼行數:20,代碼來源:test_login_flow.py

示例2: _test_plan_create_new

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import FOUND [as 別名]
def _test_plan_create_new(self, is_active):
        self.request['is_active'] = is_active

        response = self.client.post(self.location, self.request)
        self.assertEqual(response.status_code, HTTPStatus.FOUND)

        plan = TestPlan.objects.get(
            name=self.plan_name,
            is_active=is_active,
        )
        self.assertEqual(plan.author, self.user)
        self.assertEqual(plan.product, self.product)
        self.assertEqual(plan.product_version, self.product_version)
        self.assertEqual(plan.type, self.plan_type)
        self.assertEqual(plan.is_active, is_active)
        self.assertTrue(plan.emailing.auto_to_plan_author)
        self.assertTrue(plan.emailing.auto_to_case_owner)
        self.assertTrue(plan.emailing.auto_to_case_default_tester)
        self.assertTrue(plan.emailing.notify_on_plan_update)
        self.assertTrue(plan.emailing.notify_on_case_update) 
開發者ID:kiwitcms,項目名稱:Kiwi,代碼行數:22,代碼來源:test_new_plan.py

示例3: _check_status

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import FOUND [as 別名]
def _check_status(self):
        """Check if the http status is what we expected."""
        path_to_statuses = {
            '/favicon.ico': [HTTPStatus.OK, HTTPStatus.PARTIAL_CONTENT],

            '/does-not-exist': [HTTPStatus.NOT_FOUND],
            '/does-not-exist-2': [HTTPStatus.NOT_FOUND],
            '/404': [HTTPStatus.NOT_FOUND],

            '/redirect-later': [HTTPStatus.FOUND],
            '/redirect-self': [HTTPStatus.FOUND],
            '/redirect-to': [HTTPStatus.FOUND],
            '/relative-redirect': [HTTPStatus.FOUND],
            '/absolute-redirect': [HTTPStatus.FOUND],

            '/cookies/set': [HTTPStatus.FOUND],

            '/500-inline': [HTTPStatus.INTERNAL_SERVER_ERROR],
            '/500': [HTTPStatus.INTERNAL_SERVER_ERROR],
        }
        for i in range(15):
            path_to_statuses['/redirect/{}'.format(i)] = [HTTPStatus.FOUND]
        for suffix in ['', '1', '2', '3', '4', '5', '6']:
            key = ('/basic-auth/user{suffix}/password{suffix}'
                   .format(suffix=suffix))
            path_to_statuses[key] = [HTTPStatus.UNAUTHORIZED, HTTPStatus.OK]

        default_statuses = [HTTPStatus.OK, HTTPStatus.NOT_MODIFIED]

        sanitized = QUrl('http://localhost' + self.path).path()  # Remove ?foo
        expected_statuses = path_to_statuses.get(sanitized, default_statuses)
        if self.status not in expected_statuses:
            raise AssertionError(
                "{} loaded with status {} but expected {}".format(
                    sanitized, self.status,
                    ' / '.join(repr(e) for e in expected_statuses))) 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:38,代碼來源:webserver.py

示例4: relative_redirect

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import FOUND [as 別名]
def relative_redirect():
    """302 Redirect once."""
    response = app.make_response('')
    response.status_code = HTTPStatus.FOUND
    response.headers['Location'] = flask.url_for('root')
    return response 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:8,代碼來源:webserver_sub.py

示例5: absolute_redirect

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import FOUND [as 別名]
def absolute_redirect():
    """302 Redirect once."""
    response = app.make_response('')
    response.status_code = HTTPStatus.FOUND
    response.headers['Location'] = flask.url_for('root', _external=True)
    return response 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:8,代碼來源:webserver_sub.py

示例6: redirect_to

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import FOUND [as 別名]
def redirect_to():
    """302/3XX Redirects to the given URL."""
    # We need to build the response manually and convert to UTF-8 to prevent
    # werkzeug from "fixing" the URL. This endpoint should set the Location
    # header to the exact string supplied.
    response = app.make_response('')
    response.status_code = HTTPStatus.FOUND
    response.headers['Location'] = flask.request.args['url'].encode('utf-8')
    return response 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:11,代碼來源:webserver_sub.py

示例7: test_login

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import FOUND [as 別名]
def test_login(aiohttp_client):
    resp = await aiohttp_client.post('/enter', allow_redirects=False, data=dict(username='admin', password='admin'))
    assert resp.status == HTTPStatus.FOUND
    assert resp.headers.get('Location') == '/'
    assert 'API_SESSION' in resp.cookies 
開發者ID:mitre,項目名稱:caldera,代碼行數:7,代碼來源:test_core_endpoints.py

示例8: test_redirect_on_login

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import FOUND [as 別名]
def test_redirect_on_login(self, testapp, db, person, carpool):
        cancel_carpool_url = '/carpools/{}/cancel'.format(carpool.uuid)
        res = testapp.get(cancel_carpool_url)
        res = res.follow()
        res = login_person(testapp, person, follow=False)
        assert res.status_code == HTTPStatus.FOUND
        url = urllib.parse.urlparse(res.headers['Location'])
        assert url.path == cancel_carpool_url 
開發者ID:RagtagOpen,項目名稱:nomad,代碼行數:10,代碼來源:test_login_flow.py

示例9: test_profile_not_logged_in

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import FOUND [as 別名]
def test_profile_not_logged_in(self, testapp):
        res = testapp.get('/profile')
        assert res.status_code == HTTPStatus.FOUND
        url = urllib.parse.urlparse(res.headers['Location'])
        assert url.path == '/login'
        assert url.query == '' 
開發者ID:RagtagOpen,項目名稱:nomad,代碼行數:8,代碼來源:test_profile.py

示例10: test_profile_blocked_is_logged_out

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import FOUND [as 別名]
def test_profile_blocked_is_logged_out(self, testapp, db, person, blocked_role):
        login_person(testapp, person)
        person.roles.append(blocked_role)
        db.session.commit()
        res = testapp.get('/profile')
        assert res.status_code == HTTPStatus.FOUND
        url = urllib.parse.urlparse(res.headers['Location'])
        assert url.path == '/login'
        assert url.query == '' 
開發者ID:RagtagOpen,項目名稱:nomad,代碼行數:11,代碼來源:test_profile.py

示例11: _handle_redirects

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import FOUND [as 別名]
def _handle_redirects(self, response, data='', content_type='', **extra):
        """
        Follow any redirects by requesting responses from the server using GET.
        """
        response.redirect_chain = []
        redirect_status_codes = (
            HTTPStatus.MOVED_PERMANENTLY,
            HTTPStatus.FOUND,
            HTTPStatus.SEE_OTHER,
            HTTPStatus.TEMPORARY_REDIRECT,
            HTTPStatus.PERMANENT_REDIRECT,
        )
        while response.status_code in redirect_status_codes:
            response_url = response.url
            redirect_chain = response.redirect_chain
            redirect_chain.append((response_url, response.status_code))

            url = urlsplit(response_url)
            if url.scheme:
                extra['wsgi.url_scheme'] = url.scheme
            if url.hostname:
                extra['SERVER_NAME'] = url.hostname
            if url.port:
                extra['SERVER_PORT'] = str(url.port)

            # Prepend the request path to handle relative path redirects
            path = url.path
            if not path.startswith('/'):
                path = urljoin(response.request['PATH_INFO'], path)

            if response.status_code in (HTTPStatus.TEMPORARY_REDIRECT, HTTPStatus.PERMANENT_REDIRECT):
                # Preserve request method post-redirect for 307/308 responses.
                request_method = getattr(self, response.request['REQUEST_METHOD'].lower())
            else:
                request_method = self.get
                data = QueryDict(url.query)
                content_type = None

            response = request_method(path, data=data, content_type=content_type, follow=False, **extra)
            response.redirect_chain = redirect_chain

            if redirect_chain[-1] in redirect_chain[:-1]:
                # Check that we're not redirecting to somewhere we've already
                # been to, to prevent loops.
                raise RedirectCycleError("Redirect loop detected.", last_response=response)
            if len(redirect_chain) > 20:
                # Such a lengthy chain likely also means a loop, but one with
                # a growing path, changing view, or changing query argument;
                # 20 is the value of "network.http.redirection-limit" from Firefox.
                raise RedirectCycleError("Too many redirects.", last_response=response)

        return response 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:54,代碼來源:client.py


注:本文中的http.HTTPStatus.FOUND屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。