Skip to content

Commit

Permalink
Merge branch 'master' into expiration
Browse files Browse the repository at this point in the history
Fixing conflicts. Making sure tests pass still. Bumping the version to 1.5.0.
  • Loading branch information
Gavin McQuillan committed Jan 6, 2016
2 parents ec5be1d + 8d584f9 commit e065722
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion brake/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = (1, 3, 1)
VERSION = (1, 5, 0)
2 changes: 1 addition & 1 deletion brake/backends/cachebe.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def limit(self, func_name, request,
'ratelimited_by': ratelimited_by,
'period': period,
'field': field,
'count': counters[counter],
'count': current_count,
'cache_key': counter,
'ip': self.get_ip(request)
})
Expand Down
24 changes: 23 additions & 1 deletion brake/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import time

import unittest
from django.core.cache import cache
from django.http import HttpResponse
from django.utils import unittest

from brake.decorators import ratelimit

Expand Down Expand Up @@ -279,3 +279,25 @@ def test_dont_use_request_path(self):
rl = ratelimit(method='POST', use_request_path=False, rate='5/m', block=True)
result = self.client.post(rl(fake_login_use_request_path), self.bad_payload)
self.assertEqual(result.status_code, 200)

def test_new_counters_are_created(self):
"""Makes sure that we create counters for keys/buckets.
This is so we know that we're populating some values for every
bucket.
"""
# a bad post
self.assertFalse(self.client.post(fake_login, self.bad_payload))
# These are the cache keys that are specified by the decorator
# for this view.
fake_login_cache_keys = [
self.KEYS.fake_login_field_60,
self.KEYS.fake_login_field_3600,
self.KEYS.fake_login_field_86400,
self.KEYS.fake_login_ip_60,
self.KEYS.fake_login_ip_3600,
self.KEYS.fake_login_ip_86400,
]
for key in fake_login_cache_keys:
self.assertTrue(cache.get(key) > 1)

0 comments on commit e065722

Please sign in to comment.