Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 6095056210c7972fb847e67d8c15a69e7dd3b8c1 1 parent fc38ab0
Dusty Phillips authored
7 README.md
Source Rendered
@@ -6,8 +6,6 @@ This module contains some standard web framework functionality intended to integ
6 6 * Sessions
7 7 * Single Request Messages
8 8 * Authentication
9   -* simple redirect class
10   -
11 9
12 10 The session and auth implementations use mongo_engine for storage. To use them, ensure
13 11 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.
61 59 For an example of how these modules can be used in practice, see
62 60 [Todoy](https://github.com/buchuki/Todoy)
63 61
64   -Redirect
65   ---------
66   -If you want to redirect, raise the trembling.Redirect("url") response. It's a thin wrapper around Response .
67   -
68 62 Messages
69 63 --------
70 64 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
72 66 it doesn't currently do any handling of combining multiple messages into a list
73 67 or anything like that.
74 68
75   -
76 69 TESTING
77 70 -------
78 71
8 trembling/__init__.py
... ... @@ -1,8 +0,0 @@
1   -from aspen import Response
2   -
3   -
4   -class Redirect(Response):
5   - """docstring for Redirect"""
6   - def __init__(self, location, code=302):
7   - super(Redirect, self).__init__(code)
8   - self.headers.set('Location', location)
3  trembling/auth.py
@@ -6,7 +6,6 @@
6 6 from mongoengine import Document, StringField
7 7
8 8 from trembling.session import SESSION_COOKIE_NAME
9   -from trembling import Redirect
10 9
11 10 SALT_LENGTH = 23
12 11 SALT_CHARACTERS = string.ascii_letters + string.digits
@@ -65,7 +64,7 @@ def login_required(request, login_url=None):
65 64 if not request.authenticated:
66 65 if login_url is None:
67 66 login_url = LOGIN_URL
68   - raise Redirect(login_url)
  67 + request.redirect(login_url)
69 68 else:
70 69 return True
71 70
12 trembling/tests/test_auth.py
... ... @@ -1,4 +1,3 @@
1   -from trembling import Redirect
2 1 from trembling.auth import User, inbound, login, logout, login_required
3 2 from mock import Mock
4 3 from py.test import raises
@@ -66,9 +65,8 @@ def test_logout(mongodb, user, request):
66 65
67 66 def test_login_required(mongodb, request):
68 67 inbound(request)
69   - with raises(Redirect) as exc:
70   - login_required(request, "/login.html")
71   - assert exc.value.headers.one("Location") == "/login.html"
  68 + login_required(request, "/login.html")
  69 + request.redirect.assert_called_with('/login.html')
72 70
73 71
74 72 def test_authenticated_user_passes(mongodb, user, request):
@@ -77,8 +75,8 @@ def test_authenticated_user_passes(mongodb, user, request):
77 75 login_required(request, "/login.html")
78 76 # If we got this far, great!
79 77
  78 +
80 79 def test_login_required_no_url(mongodb, request):
81 80 inbound(request)
82   - with raises(Redirect) as exc:
83   - login_required(request)
84   - assert exc.value.headers.one("Location") == "/account/login.html"
  81 + login_required(request)
  82 + request.redirect.assert_called_with('/account/login.html')
6 trembling/tests/test_shortcuts.py
... ... @@ -1,6 +0,0 @@
1   -from trembling import Redirect
2   -
3   -def test_redirect():
4   - response = Redirect("/")
5   - assert response.code == 302
6   - assert response.headers.one("Location") == "/"

0 comments on commit 6095056

Please sign in to comment.
Something went wrong with that request. Please try again.