Skip to content

Commit

Permalink
Now entirely pep8 compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
codeinthehole committed Nov 29, 2011
1 parent 483ea2d commit 30588eb
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rickroll/exceptions.py
@@ -1,2 +1,2 @@
class HackingAttempt(Exception):
pass
pass
2 changes: 1 addition & 1 deletion rickroll/middleware.py
Expand Up @@ -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())
7 changes: 4 additions & 3 deletions run_tests.py
Expand Up @@ -6,7 +6,7 @@

if not settings.configured:
settings.configure(
DATABASES = {
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
}
Expand All @@ -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',
Expand All @@ -30,6 +30,7 @@

from django.test.simple import DjangoTestSuiteRunner


def run_tests():
# Modify path
parent = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -41,4 +42,4 @@ def run_tests():
sys.exit(failures)

if __name__ == '__main__':
run_tests()
run_tests()
6 changes: 2 additions & 4 deletions setup.py
Expand Up @@ -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'])
16 changes: 12 additions & 4 deletions 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'])
3 changes: 2 additions & 1 deletion 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'),
)
8 changes: 6 additions & 2 deletions 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!")

0 comments on commit 30588eb

Please sign in to comment.