This repository has been archived by the owner on Jan 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from orsinium/clear
Tests, some service features
- Loading branch information
Showing
11 changed files
with
172 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
__pycache__ | ||
build/ | ||
dist/ | ||
.tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
language: python | ||
python: | ||
- "2.7" | ||
- "3.4" | ||
- "3.6" | ||
sudo: false | ||
env: | ||
- DJANGO=1.8 | ||
- DJANGO=1.11 | ||
- DJANGO=2.0 | ||
- DJANGO=master | ||
matrix: | ||
fast_finish: true | ||
exclude: | ||
- { python: "2.7", env: DJANGO=2.0 } | ||
- { python: "2.7", env: DJANGO=master } | ||
- { python: "3.4", env: DJANGO=master } | ||
services: | ||
- redis-server | ||
install: | ||
- if [[ $DJANGO == 'master' ]]; then pip install https://github.com/django/django/archive/master.tar.gz; fi | ||
- if [[ $DJANGO != 'master' ]]; then pip install django==$DJANGO; fi | ||
- pip install redis | ||
- pip install -e . | ||
script: | ||
- cd example && python manage.py test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
from .core import Attempt # noQA | ||
from . import checkers # noQA | ||
from .utils import Rule # noQA | ||
from .core import Attempt, clear # noQA | ||
from . import checkers # noQA | ||
from .utils import Rule # noQA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# coding=utf-8 | ||
from django.test import TestCase, Client, RequestFactory | ||
from djbrut import Attempt, clear | ||
|
||
|
||
class DjBrutTest(TestCase): | ||
def setUp(self): | ||
clear() | ||
|
||
def test_view(self): | ||
client = Client() | ||
|
||
# first 5 requests is ok | ||
for _i in range(5): | ||
response = client.get('/') | ||
self.assertEqual(response.content, b'ok') | ||
|
||
# 6st requests is failed | ||
response = client.get('/') | ||
self.assertEqual(response.content, b'Too many requests (ip). Maximum 5 per 1 minutes.') | ||
|
||
def test_timelimit(self): | ||
factory = RequestFactory() | ||
request = factory.get('/') | ||
attempt = Attempt('index', request) | ||
attempt.check() | ||
for key in attempt.connection.keys('*:ip:*:int'): | ||
self.assertLessEqual(attempt.connection.ttl(key), 60) | ||
|
||
def test_check(self): | ||
factory = RequestFactory() | ||
request = factory.get('/') | ||
for _i in range(5): | ||
attempt = Attempt('index', request) | ||
self.assertTrue(attempt.check()) | ||
attempt = Attempt('index', request) | ||
self.assertFalse(attempt.check()) | ||
|
||
def test_default_rule(self): | ||
factory = RequestFactory() | ||
request = factory.get('/') | ||
for _i in range(10): | ||
attempt = Attempt('lorem ipsum', request) | ||
self.assertTrue(attempt.check()) | ||
attempt = Attempt('lorem ipsum', request) | ||
self.assertFalse(attempt.check()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setup( | ||
name='djbrut', | ||
version='0.8.1', | ||
version='1.0.0', | ||
|
||
author='orsinium', | ||
author_email='[email protected]', | ||
|
@@ -22,7 +22,7 @@ | |
|
||
license='GNU Lesser General Public License v3.0', | ||
classifiers=[ | ||
'Development Status :: 4 - Beta', | ||
'Development Status :: 5 - Production/Stable', | ||
'Environment :: Plugins', | ||
'Framework :: Django', | ||
'Intended Audience :: Developers', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[tox] | ||
envlist = | ||
py{2,3}-django{18,111}, | ||
py3-django{20,master}, | ||
|
||
[testenv] | ||
commands = | ||
python manage.py test | ||
changedir = example | ||
envdir = {toxworkdir}/venvs/{envname} | ||
setenv = | ||
PYTHONDONTWRITEBYTECODE=1 | ||
PYTHONWARNINGS=once | ||
deps = | ||
django18: Django>=1.8,<1.9 | ||
django111: Django>=1.11,<2.0 | ||
django20: Django>=2.0,<2.1 | ||
djangomaster: https://github.com/django/django/archive/master.tar.gz | ||
redis | ||
|
||
[testenv:flake8] | ||
max-line-length = 120 | ||
skip_install = True | ||
deps = | ||
flake8 | ||
commands = | ||
flake8 {toxinidir}/djbrut | ||
|
||
[flake8] | ||
max-line-length = 120 |