Skip to content

Commit

Permalink
Feature/rate limit own cache 120 (#121)
Browse files Browse the repository at this point in the history
* core.ratelimit validate cache config

* tests clear all caches

* settings set ST_RATELIMIT_CACHE to spirit_rl_cache

* core.utils deprecations

* tests deprecations

* core.ratelimit get_fixed window depreaction warning when period is 0

* core.ratelimit tests

* topic.private renamed test
  • Loading branch information
nitely committed May 19, 2016
1 parent 2fbff19 commit 2340242
Show file tree
Hide file tree
Showing 31 changed files with 268 additions and 132 deletions.
3 changes: 3 additions & 0 deletions example/project/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

# Application definition

# This will be the default in next version
ST_RATELIMIT_CACHE = 'st_rate_limit'

# Extend the Spirit installed apps.
# Check out the spirit.settings.py so you do not end up with duplicated apps.
INSTALLED_APPS.extend([
Expand Down
5 changes: 5 additions & 0 deletions example/project/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
},
'st_rate_limit': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'spirit_rl_cache',
'TIMEOUT': None
}
})

PASSWORD_HASHERS = [
Expand Down
5 changes: 2 additions & 3 deletions spirit/admin/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from django.test import TestCase, RequestFactory
from django.core.urlresolvers import reverse
from django.core.cache import cache
from django.core.exceptions import PermissionDenied
from django.contrib.auth import get_user_model

Expand All @@ -27,7 +26,7 @@
class AdminViewTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.user.st.is_administrator = True
self.user.st.save()
Expand Down Expand Up @@ -343,7 +342,7 @@ def test_flag_detail_paginate(self):
class AdminFormTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(self.category)
Expand Down
5 changes: 2 additions & 3 deletions spirit/category/admin/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from django.test import TestCase, RequestFactory
from django.core.urlresolvers import reverse
from django.core.cache import cache
from django.core.exceptions import PermissionDenied
from django.contrib.auth import get_user_model

Expand All @@ -19,7 +18,7 @@
class AdminViewTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.user.st.is_administrator = True
self.user.st.save()
Expand Down Expand Up @@ -87,7 +86,7 @@ def test_category_form_color(self):
class AdminFormTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(self.category)
Expand Down
5 changes: 2 additions & 3 deletions spirit/category/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from django.test import TestCase
from django.core.urlresolvers import reverse
from django.core.cache import cache
from django.utils import timezone
from django.conf import settings

Expand All @@ -21,7 +20,7 @@
class CategoryViewTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category_1 = utils.create_category(title="cat1")
self.subcategory_1 = utils.create_subcategory(self.category_1)
Expand Down Expand Up @@ -152,7 +151,7 @@ def test_category_detail_view_paginate(self):
class CategoryMigrationTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()

def test_uncategorized_category(self):
"""
Expand Down
9 changes: 4 additions & 5 deletions spirit/comment/bookmark/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

from __future__ import unicode_literals

from django.test import TestCase, RequestFactory
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.template import Template, Context
from django.core.cache import cache

from djconfig import config

Expand All @@ -17,7 +16,7 @@
class CommentBookmarkViewTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand All @@ -38,7 +37,7 @@ def test_bookmark_create(self):
class CommentBookmarkModelsTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand Down Expand Up @@ -91,7 +90,7 @@ def test_form(self):
class CommentBookmarkTemplateTagsTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(self.category)
Expand Down
5 changes: 2 additions & 3 deletions spirit/comment/flag/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from django.test import TestCase
from django.core.urlresolvers import reverse
from django.core.cache import cache

from ...core.tests import utils
from .models import Flag, CommentFlag
Expand All @@ -14,7 +13,7 @@
class FlagViewTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand All @@ -36,7 +35,7 @@ def test_flag_create(self):
class FlagFormTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand Down
5 changes: 2 additions & 3 deletions spirit/comment/history/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from django.test import TestCase
from django.core.urlresolvers import reverse
from django.core.cache import cache

from djconfig.utils import override_djconfig

Expand All @@ -17,7 +16,7 @@
class CommentHistoryViewTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand Down Expand Up @@ -113,7 +112,7 @@ def test_comment_history_detail_denied_to_non_logged_users(self):
class CommentHistoryModelsTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand Down
7 changes: 3 additions & 4 deletions spirit/comment/like/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.template import Template, Context
from django.core.cache import cache

from ...core.tests import utils
from ..models import Comment
Expand All @@ -17,7 +16,7 @@
class LikeViewTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand Down Expand Up @@ -106,7 +105,7 @@ def test_like_delete_comment_decrease_likes_count(self):
class LikeFormTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand Down Expand Up @@ -137,7 +136,7 @@ def test_like_create_invalid(self):
class LikeTemplateTagsTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand Down
11 changes: 5 additions & 6 deletions spirit/comment/poll/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from django.test import TestCase, RequestFactory
from django.core.urlresolvers import reverse
from django.core.cache import cache
from django.contrib.auth import get_user_model
from django.utils import timezone
from django.template import Template, Context
Expand All @@ -22,7 +21,7 @@
class PollViewTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.user2 = utils.create_user()
self.category = utils.create_category()
Expand Down Expand Up @@ -234,7 +233,7 @@ def test_poll_voters_secret_closed(self):
class PollFormTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.user2 = utils.create_user()
self.category = utils.create_category()
Expand Down Expand Up @@ -384,7 +383,7 @@ def test_update_vote_single(self):
class CommentPollTemplateTagsTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category)
Expand Down Expand Up @@ -536,7 +535,7 @@ def test_render_polls_secret_closed(self):
class PollModelsTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand Down Expand Up @@ -775,7 +774,7 @@ def test_poll_choice_update_or_create_many_removed_poll(self):
class PollUtilsTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand Down
11 changes: 5 additions & 6 deletions spirit/comment/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import shutil

from django.test import TestCase, RequestFactory
from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.template import Template, Context
from django.core.exceptions import PermissionDenied
Expand Down Expand Up @@ -39,7 +38,7 @@
class CommentViewTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand Down Expand Up @@ -402,7 +401,7 @@ def test_comment_image_upload_invalid(self):
class CommentModelsTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand Down Expand Up @@ -442,7 +441,7 @@ def test_comment_create_moderation_action(self):
class CommentTemplateTagTests(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand Down Expand Up @@ -477,7 +476,7 @@ def test_get_action_text(self):
class CommentFormTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category)
Expand Down Expand Up @@ -601,7 +600,7 @@ def test_comment_max_len_invalid(self):
class CommentUtilsTest(TestCase):

def setUp(self):
cache.clear()
utils.cache_clear()
self.user = utils.create_user()
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
Expand Down
11 changes: 5 additions & 6 deletions spirit/core/tests/tests_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

from __future__ import unicode_literals

from django.core.cache import cache
from django.test import TestCase
from django.test.utils import override_settings
from django.utils import translation
from django.utils import timezone

from ..tests import utils as test_utils
from . import utils
from ..utils.markdown import Markdown, quotify


Expand All @@ -18,10 +17,10 @@
class UtilsMarkdownTests(TestCase):

def setUp(self):
cache.clear()
self.user = test_utils.create_user(username="nitely")
self.user2 = test_utils.create_user(username="esteban")
self.user3 = test_utils.create_user(username="áéíóú")
utils.cache_clear()
self.user = utils.create_user(username="nitely")
self.user2 = utils.create_user(username="esteban")
self.user3 = utils.create_user(username="áéíóú")

def test_markdown_escape(self):
"""
Expand Down
7 changes: 3 additions & 4 deletions spirit/core/tests/tests_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json
import os

from django.core.cache import cache
from django.test import TestCase, RequestFactory
from django.test.utils import override_settings
from django.template import Template, Context
Expand All @@ -28,7 +27,7 @@
from ..utils.timezone import TIMEZONE_CHOICES
from ..utils.decorators import moderator_required, administrator_required
from ..tags import time as ttags_utils
from ..tests import utils as test_utils
from . import utils as test_utils
from ..tags.messages import render_messages

User = get_user_model()
Expand All @@ -37,7 +36,7 @@
class UtilsTests(TestCase):

def setUp(self):
cache.clear()
test_utils.cache_clear()

def test_render_form_errors(self):
"""
Expand Down Expand Up @@ -268,7 +267,7 @@ def test_timezone(self):
class UtilsDecoratorsTests(TestCase):

def setUp(self):
cache.clear()
test_utils.cache_clear()
self.user = test_utils.create_user()

def test_moderator_required(self):
Expand Down
Loading

0 comments on commit 2340242

Please sign in to comment.