Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

WIP: laying foundation for tests

  • Loading branch information...
commit bf31da3d5054705ff4afa9cf5ff6e9b89911dec8 1 parent 2f18f2b
@gmcquillan authored
View
2  .gitignore
@@ -7,4 +7,4 @@ include/
lib/
local/
man/
-
+share/
View
1  brake/tests/__init__.py
@@ -0,0 +1 @@
+from .tests import *
View
33 brake/tests/tests.py
@@ -1,6 +1,4 @@
-
from django.core.cache import cache
-from django.test.client import Client
from django.utils import unittest
from brake.decorators import ratelimit
@@ -14,6 +12,24 @@ class RateLimitError(Exception):
pass
+class FakeRequest(object):
+ """A simple request stub."""
+ method = 'POST'
+
+
+class FakeClient(object):
+ """An extremely light-weight test client."""
+
+ def post(self, view_func, data):
+ request = FakeRequest()
+ if callable(view_func):
+ request.POST = data
+
+ return view_func(request)
+
+ return request
+
+
class RateLimitTestCase(unittest.TestCase):
"""Adds assertFailsLogin and other helper methods."""
@@ -77,7 +93,8 @@ def set_field_ratelimit_counts(self, func_name, period, field_hash, count):
def setUp(self):
super(RateLimitTestCase, self).setUp()
- self.client = Client()
+ self.client = FakeClient()
+ self.app = FakeDjangoApp()
# We want fresh cache for ratelimit testing
cache.clear()
@@ -120,8 +137,14 @@ def test_allow_some_failures(self):
bad_payload = {'username': 'user'}
good_payload = {'username': 'user', 'password': 'correct'}
- self.assertFalse(self.client.post(bad_payload))
+ #TODO(gavin): fix the client post and login so that we can call them.
+ self.assertFalse(
+ self.client.post(self.app.fake_login, bad_payload)
+ )
# We haven't gone over any threshold yet, so we should be able to
# successfully login now.
- self.assertTrue(self.client.post(good_payload))
+ good_response = self._parse_response(
+ self.client.post(FakeDjangoApp.fake_login, good_payload)
+ )
+ self.assertTrue(good_response)
View
15 test_settings.py
@@ -1,5 +1,5 @@
DATABASES = {'default':{
- 'NAME':'project.db',
+ 'NAME':':memory:',
'ENGINE':'django.db.backends.sqlite3'
}}
@@ -15,8 +15,7 @@
# This is where our ratelimiting information is stored.
CACHES = {
'default': {
- 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
- 'LOCATION': '127.0.0.1:11211',
+ 'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
@@ -28,5 +27,13 @@
# turn this file into a pseudo-urls.py.
from django.conf.urls.defaults import *
+from brake.tests import FakeDjangoApp
-urlpatterns = patterns('')
+urlpatterns = patterns(
+ '',
+ url(
+ r'^fake_login/$',
+ FakeDjangoApp.fake_login,
+ name='fake_login'
+ ),
+)
Please sign in to comment.
Something went wrong with that request. Please try again.