Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Now entirely pep8 compliant

  • Loading branch information...
commit 30588eb7dd32b2e753c0413abfce7c1c38247920 1 parent 483ea2d
@codeinthehole authored
View
2  rickroll/exceptions.py
@@ -1,2 +1,2 @@
class HackingAttempt(Exception):
- pass
+ pass
View
2  rickroll/middleware.py
@@ -14,4 +14,4 @@ def get_redirect_url(self):
def process_exception(self, request, exception):
if isinstance(exception, HackingAttempt):
- return HttpResponseRedirect(self.get_redirect_url())
+ return HttpResponseRedirect(self.get_redirect_url())
View
7 run_tests.py
@@ -6,7 +6,7 @@
if not settings.configured:
settings.configure(
- DATABASES = {
+ DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
}
@@ -20,7 +20,7 @@
'rickroll',
'tests',
],
- MIDDLEWARE_CLASSES = global_settings.MIDDLEWARE_CLASSES + (
+ MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES + (
'rickroll.middleware.HackingAttemptMiddleware',
),
ROOT_URLCONF='tests.urls',
@@ -30,6 +30,7 @@
from django.test.simple import DjangoTestSuiteRunner
+
def run_tests():
# Modify path
parent = os.path.dirname(os.path.abspath(__file__))
@@ -41,4 +42,4 @@ def run_tests():
sys.exit(failures)
if __name__ == '__main__':
- run_tests()
+ run_tests()
View
6 setup.py
@@ -8,9 +8,7 @@
long_description=open('README.rst').read(),
author='David Winterbottom',
author_email='david.winterbottom@gmail.com',
+ url='https://github.com/codeinthehole/django-rickroll',
license='BSD',
packages=find_packages(exclude=('tests',)),
- tests_require=[
- 'django>=1.3'
- ],
-)
+ tests_require=['django>=1.3'])
View
16 tests/tests.py
@@ -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'])
View
3  tests/urls.py
@@ -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'),
)
View
8 tests/views.py
@@ -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!")
Please sign in to comment.
Something went wrong with that request. Please try again.