Skip to content

Commit 7abaefa

Browse files
authored
Update tests for current django & python versions (jazzband#261)
* Change to github actions as CI * update python and django version remove and add outdated python and django versions * remove deprecated isort settings * ensure expired token for test sometimes tests failed on windows * Remove deprecated `django-nose`
1 parent 8447cd0 commit 7abaefa

File tree

8 files changed

+66
-52
lines changed

8 files changed

+66
-52
lines changed

.github/workflows/test.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-20.04
8+
strategy:
9+
fail-fast: false
10+
max-parallel: 5
11+
matrix:
12+
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
22+
- name: Get pip cache dir
23+
id: pip-cache
24+
run: |
25+
echo "::set-output name=dir::$(pip cache dir)"
26+
27+
- name: Cache
28+
uses: actions/cache@v2
29+
with:
30+
path: ${{ steps.pip-cache.outputs.dir }}
31+
key:
32+
${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/tox.ini') }}
33+
restore-keys: |
34+
${{ matrix.python-version }}-v1-
35+
36+
- name: Install dependencies
37+
run: |
38+
python -m pip install --upgrade pip
39+
python -m pip install --upgrade tox tox-gh-actions
40+
41+
- name: Tox tests
42+
run: |
43+
tox -v

.isort.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ default_section = THIRDPARTY
44
include_trailing_comma = true
55
known_first_party = knox
66
multi_line_output = 5
7-
not_skip = __init__.py

.travis.yml

-30
This file was deleted.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
django-rest-knox
22
================
33

4-
[![image](https://travis-ci.org/James1345/django-rest-knox.svg?branch=develop)](https://travis-ci.org/James1345/django-rest-knox)
4+
[![image](https://github.com/James1345/django-rest-knox/workflows/Test/badge.svg?branch=develop)](https://github.com/James1345/django-rest-knox/actions)
55

66
Authentication Module for django rest auth
77

knox_project/settings.py

-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
'django.contrib.sessions',
1111
'rest_framework',
1212
'knox',
13-
'django_nose',
1413
)
1514

1615
MIDDLEWARE_CLASSES = (
@@ -54,5 +53,3 @@
5453
USE_TZ = True
5554

5655
STATIC_URL = '/static/'
57-
58-
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
# Pick your license as you wish (should match "license" above)
4848
'License :: OSI Approved :: MIT License',
4949
'Programming Language :: Python :: 3',
50-
'Programming Language :: Python :: 3.6',
5150
'Programming Language :: Python :: 3.7',
5251
'Programming Language :: Python :: 3.8',
5352
'Programming Language :: Python :: 3.9',
53+
'Programming Language :: Python :: 3.10',
5454
],
5555

5656
# What does your project relate to?
@@ -67,7 +67,7 @@
6767
# https://packaging.python.org/en/latest/requirements.html
6868
python_requires='>=3.6',
6969
install_requires=[
70-
'django>=2.2',
70+
'django>=3.2',
7171
'djangorestframework',
7272
'cryptography',
7373
],

tests/tests.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test_logout_all_deletes_only_targets_keys(self):
165165
def test_expired_tokens_login_fails(self):
166166
self.assertEqual(AuthToken.objects.count(), 0)
167167
instance, token = AuthToken.objects.create(
168-
user=self.user, expiry=timedelta(seconds=0))
168+
user=self.user, expiry=timedelta(seconds=-1))
169169
self.client.credentials(HTTP_AUTHORIZATION=('Token %s' % token))
170170
response = self.client.post(root_url, {}, format='json')
171171
self.assertEqual(response.status_code, 401)
@@ -174,9 +174,9 @@ def test_expired_tokens_login_fails(self):
174174
def test_expired_tokens_deleted(self):
175175
self.assertEqual(AuthToken.objects.count(), 0)
176176
for _ in range(10):
177-
# 0 TTL gives an expired token
177+
# -1 TTL gives an expired token
178178
instance, token = AuthToken.objects.create(
179-
user=self.user, expiry=timedelta(seconds=0))
179+
user=self.user, expiry=timedelta(seconds=-1))
180180
self.assertEqual(AuthToken.objects.count(), 10)
181181

182182
# Attempting a single logout should delete all tokens
@@ -318,7 +318,7 @@ def handler(sender, username, **kwargs):
318318

319319
token_expired.connect(handler)
320320

321-
instance, token = AuthToken.objects.create(user=self.user, expiry=timedelta(0))
321+
instance, token = AuthToken.objects.create(user=self.user, expiry=timedelta(seconds=-1))
322322
self.client.credentials(HTTP_AUTHORIZATION=('Token %s' % token))
323323
self.client.post(root_url, {}, format='json')
324324

@@ -346,7 +346,7 @@ def test_does_not_exceed_on_expired_keys(self):
346346
reload_module(views)
347347
for _ in range(9):
348348
AuthToken.objects.create(user=self.user)
349-
AuthToken.objects.create(user=self.user, expiry=timedelta(seconds=0))
349+
AuthToken.objects.create(user=self.user, expiry=timedelta(seconds=-1))
350350
# now 10 keys, but only 9 valid so request should succeed.
351351
url = reverse('knox_login')
352352
self.client.credentials(

tox.ini

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
[tox]
22
envlist =
3-
isort
3+
isort,
44
flake8,
5-
py{36,37,38,39}-django22,
6-
py{36,37,38,39}-django30,
7-
py{36,37,38,39}-django31,
5+
py{36,37,38,39,310}-django32,
6+
py{38,39,310}-django40,
87

98
[testenv:flake8]
109
deps = flake8
@@ -14,7 +13,7 @@ commands = flake8 knox
1413
[testenv:isort]
1514
deps = isort
1615
changedir = {toxinidir}
17-
commands = isort --recursive --check-only --diff \
16+
commands = isort --check-only --diff \
1817
knox \
1918
knox_project/views.py \
2019
setup.py \
@@ -28,12 +27,10 @@ setenv =
2827
DJANGO_SETTINGS_MODULE = knox_project.settings
2928
PIP_INDEX_URL = https://pypi.python.org/simple/
3029
deps =
31-
django22: Django>=2.2,<2.3
32-
django30: Django>=3.0,<3.1
33-
django31: Django>=3.1,<3.2
34-
django-nose
30+
django32: Django>=3.2,<3.3
31+
django40: Django>=4.0,<4.1
3532
markdown<3.0
36-
isort
33+
isort>=5.0
3734
djangorestframework
3835
freezegun
3936
mkdocs
@@ -42,3 +39,11 @@ deps =
4239
setuptools
4340
twine
4441
wheel
42+
43+
[gh-actions]
44+
python =
45+
3.6: py36
46+
3.7: py37
47+
3.8: py38
48+
3.9: py39, isort, flake8
49+
3.10: py310

0 commit comments

Comments
 (0)