Skip to content

Commit

Permalink
Merge pull request #156 from jwhitlock/drop-django-1.8-1.10
Browse files Browse the repository at this point in the history
Use is_authenticated attribute, drop Django < 1.11
  • Loading branch information
jsocol authored Dec 29, 2018
2 parents a298b9d + 418acb2 commit 377c4e6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 40 deletions.
13 changes: 1 addition & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
language: python
sudo: false
env:
- DJANGO_VERSION=1.8
- DJANGO_VERSION=1.9
- DJANGO_VERSION=1.10
- DJANGO_VERSION=1.11
- DJANGO_VERSION=2.0
- DJANGO_VERSION=2.1
Expand All @@ -20,9 +17,7 @@ install:
- if [[ $TRAVIS_PYTHON_VERSION == pypy ]]; then pip install -q python-memcached>=1.57; fi
- if [[ $DJANGO_VERSION != master ]]; then pip install -q "Django>=${DJANGO_VERSION},<${DJANGO_VERSION}.99"; fi
- if [[ $DJANGO_VERSION == master ]]; then pip install https://github.com/django/django/archive/master.tar.gz; fi
- if [[ $DJANGO_VERSION == 1* ]]; then pip install django-redis==4.8.0; fi
- if [[ $DJANGO_VERSION != 1* ]]; then pip install django-redis==4.9.0; fi
- pip install flake8
- pip install django-redis==4.9.0 flake8
script:
- ./run.sh test
- ./run.sh flake8
Expand All @@ -38,12 +33,6 @@ matrix:
env: DJANGO_VERSION=2.1
- python: "3.4"
env: DJANGO_VERSION=master
- python: "3.6"
env: DJANGO_VERSION=1.8
- python: "3.6"
env: DJANGO_VERSION=1.9
- python: "3.6"
env: DJANGO_VERSION=1.10
- python: "pypy"
env: DJANGO_VERSION=2.0
- python: "pypy"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Pending
=======

- New release notes here.
- Drop support for Django 1.8, 1.9, and 1.10
- Fix Django 2.0 compatibility and update documentation
- Test Django 2.1 support

v1.1.0
======
Expand Down
11 changes: 4 additions & 7 deletions ratelimit/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
class MockUser(object):
def __init__(self, authenticated=False):
self.pk = 1
self.authenticated = authenticated

def is_authenticated(self):
return self.authenticated
self.is_authenticated = authenticated


class RateParsingTests(TestCase):
Expand Down Expand Up @@ -212,7 +209,7 @@ def test_callable_rate(self):
unauth.user = MockUser(authenticated=False)

def get_rate(group, request):
if request.user.is_authenticated():
if request.user.is_authenticated:
return (2, 60)
return (1, 60)

Expand Down Expand Up @@ -252,7 +249,7 @@ def test_callable_rate_zero(self):
unauth.user = MockUser(authenticated=False)

def get_rate(group, request):
if request.user.is_authenticated():
if request.user.is_authenticated:
return '1/m'
return '0/m'

Expand Down Expand Up @@ -578,7 +575,7 @@ def test_keys(self):
"""Allow custom functions to set cache keys."""

def user_or_ip(group, req):
if req.user.is_authenticated():
if req.user.is_authenticated:
return 'uip:%d' % req.user.pk
return 'uip:%s' % req.META['REMOTE_ADDR']

Expand Down
10 changes: 1 addition & 9 deletions ratelimit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


def user_or_ip(request):
if is_authenticated(request.user):
if request.user.is_authenticated:
return str(request.user.pk)
return request.META['REMOTE_ADDR']

Expand Down Expand Up @@ -184,11 +184,3 @@ def get_usage_count(request, group=None, fn=None, key=None, rate=None,

is_ratelimited.ALL = ALL
is_ratelimited.UNSAFE = UNSAFE


def is_authenticated(user):
# is_authenticated was a method in Django < 1.10
if callable(user.is_authenticated):
return user.is_authenticated()
else:
return user.is_authenticated
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
'Framework :: Django :: 2.1',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
Expand Down
14 changes: 5 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
[tox]
envlist =
py27-django{18,19,110,111},
py34-django{18,19,110,111,20},
py35-django{18,19,110,111,20,21,master},
py27-django111,
py34-django{111,20},
py35-django{111,20,21,master},
py36-django{111,20,21,master},
py37-django{20,21,master},
pypy-django{18,19,110,111}
pypy-django111

[testenv]
deps =
py{27,py}: python-memcached>=1.57
py{34,35,36,37}: python3-memcached>=1.51
django18: Django>=1.8,<1.9
django19: Django>=1.9,<1.10
django110: Django>=1.10,<1.11
django111: Django>=1.11,<1.12
django20: Django>=2.0,<2.1
django21: Django>=2.1,<2.2
djangomaster: https://github.com/django/django/archive/master.tar.gz
django{18,19,110,111}: django-redis==4.8.0
django{20,21,master}: django-redis==4.9.0
django-redis==4.9.0
flake8

commands =
Expand Down

0 comments on commit 377c4e6

Please sign in to comment.