Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove Redirect in favour of aspen's built-in request.redirect

  • Loading branch information...
commit 6095056210c7972fb847e67d8c15a69e7dd3b8c1 1 parent fc38ab0
Dusty Phillips authored
View
7 README.md
@@ -6,8 +6,6 @@ This module contains some standard web framework functionality intended to integ
* Sessions
* Single Request Messages
* Authentication
-* simple redirect class
-
The session and auth implementations use mongo_engine for storage. To use them, ensure
trembling is on your path and make your Aspen
@@ -61,10 +59,6 @@ it to a string of your choice in an aspen startup hook.
For an example of how these modules can be used in practice, see
[Todoy](https://github.com/buchuki/Todoy)
-Redirect
---------
-If you want to redirect, raise the trembling.Redirect("url") response. It's a thin wrapper around Response .
-
Messages
--------
If you put something in request.session['messages'] it will automatically be
@@ -72,7 +66,6 @@ popped and submitted as request.messages in the following request. Note that
it doesn't currently do any handling of combining multiple messages into a list
or anything like that.
-
TESTING
-------
View
8 trembling/__init__.py
@@ -1,8 +0,0 @@
-from aspen import Response
-
-
-class Redirect(Response):
- """docstring for Redirect"""
- def __init__(self, location, code=302):
- super(Redirect, self).__init__(code)
- self.headers.set('Location', location)
View
3  trembling/auth.py
@@ -6,7 +6,6 @@
from mongoengine import Document, StringField
from trembling.session import SESSION_COOKIE_NAME
-from trembling import Redirect
SALT_LENGTH = 23
SALT_CHARACTERS = string.ascii_letters + string.digits
@@ -65,7 +64,7 @@ def login_required(request, login_url=None):
if not request.authenticated:
if login_url is None:
login_url = LOGIN_URL
- raise Redirect(login_url)
+ request.redirect(login_url)
else:
return True
View
12 trembling/tests/test_auth.py
@@ -1,4 +1,3 @@
-from trembling import Redirect
from trembling.auth import User, inbound, login, logout, login_required
from mock import Mock
from py.test import raises
@@ -66,9 +65,8 @@ def test_logout(mongodb, user, request):
def test_login_required(mongodb, request):
inbound(request)
- with raises(Redirect) as exc:
- login_required(request, "/login.html")
- assert exc.value.headers.one("Location") == "/login.html"
+ login_required(request, "/login.html")
+ request.redirect.assert_called_with('/login.html')
def test_authenticated_user_passes(mongodb, user, request):
@@ -77,8 +75,8 @@ def test_authenticated_user_passes(mongodb, user, request):
login_required(request, "/login.html")
# If we got this far, great!
+
def test_login_required_no_url(mongodb, request):
inbound(request)
- with raises(Redirect) as exc:
- login_required(request)
- assert exc.value.headers.one("Location") == "/account/login.html"
+ login_required(request)
+ request.redirect.assert_called_with('/account/login.html')
View
6 trembling/tests/test_shortcuts.py
@@ -1,6 +0,0 @@
-from trembling import Redirect
-
-def test_redirect():
- response = Redirect("/")
- assert response.code == 302
- assert response.headers.one("Location") == "/"
Please sign in to comment.
Something went wrong with that request. Please try again.