Python http.HTTPStatus.FOUND Examples
The following are 11
code examples of http.HTTPStatus.FOUND().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
http.HTTPStatus
, or try the search function
.
Example #1
Source File: webserver.py From qutebrowser with GNU General Public License v3.0 | 6 votes |
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)))
Example #2
Source File: test_login_flow.py From nomad with Apache License 2.0 | 6 votes |
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'
Example #3
Source File: test_new_plan.py From Kiwi with GNU General Public License v2.0 | 6 votes |
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)
Example #4
Source File: webserver_sub.py From qutebrowser with GNU General Public License v3.0 | 5 votes |
def relative_redirect(): """302 Redirect once.""" response = app.make_response('') response.status_code = HTTPStatus.FOUND response.headers['Location'] = flask.url_for('root') return response
Example #5
Source File: webserver_sub.py From qutebrowser with GNU General Public License v3.0 | 5 votes |
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
Example #6
Source File: webserver_sub.py From qutebrowser with GNU General Public License v3.0 | 5 votes |
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
Example #7
Source File: test_core_endpoints.py From caldera with Apache License 2.0 | 5 votes |
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
Example #8
Source File: test_login_flow.py From nomad with Apache License 2.0 | 5 votes |
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
Example #9
Source File: test_profile.py From nomad with Apache License 2.0 | 5 votes |
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 == ''
Example #10
Source File: test_profile.py From nomad with Apache License 2.0 | 5 votes |
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 == ''
Example #11
Source File: client.py From Hands-On-Application-Development-with-PyCharm with MIT License | 4 votes |
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