-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
483ea2d
commit 30588eb
Showing
7 changed files
with
28 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
class HackingAttempt(Exception): | ||
pass | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
import httplib | ||
|
||
from django.test import TestCase | ||
from django.test.client import Client | ||
from django.conf import settings | ||
|
||
|
||
class MiddlewareTests(TestCase): | ||
|
||
def setUp(self): | ||
self.client = Client() | ||
|
||
def test_normal_view_is_unaffected(self): | ||
"A normal view is unaffected" | ||
response = self.client.get('/') | ||
self.assertEquals(httplib.OK, response.status_code) | ||
|
||
def test_raising_exception_issues_redirect(self): | ||
"Raising the HackingAttempt exception should lead to a redirect" | ||
response = self.client.get('/') | ||
response = self.client.get('/hacking/') | ||
self.assertEquals(httplib.FOUND, response.status_code) | ||
|
||
def test_raising_exception_redirects_to_youtube_by_default(self): | ||
"Raising the HackingAttempt exception should rickroll" | ||
response = self.client.get('/') | ||
self.assertEquals('http://www.youtube.com/watch?v=oHg5SJYRHA0', response['Location']) | ||
response = self.client.get('/hacking/') | ||
self.assertEquals('http://www.youtube.com/watch?v=oHg5SJYRHA0', | ||
response['Location']) | ||
|
||
def test_redirect_url_can_be_manually_set(self): | ||
"The redirect URL can be changed in settings" | ||
settings.RICKROLL_URL = 'http://www.youtube.com/watch?v=YbaTur4A1OU' | ||
response = self.client.get('/') | ||
response = self.client.get('/hacking/') | ||
self.assertEquals(settings.RICKROLL_URL, response['Location']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from django.conf.urls.defaults import * | ||
|
||
urlpatterns = patterns('', | ||
url(r'^$', 'tests.views.index'), | ||
url(r'^$', 'tests.views.normal_view'), | ||
url(r'^hacking/$', 'tests.views.hacking_attempt'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
from django.http import HttpResponse | ||
from rickroll.exceptions import HackingAttempt | ||
|
||
|
||
def index(request): | ||
raise HackingAttempt("Naughty!") | ||
def normal_view(request): | ||
return HttpResponse() | ||
|
||
|
||
def hacking_attempt(request): | ||
raise HackingAttempt("Naughty!") |