Skip to content

Commit

Permalink
Merge branch 'develop' into remove_legacy_py2
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamDonna authored Sep 25, 2023
2 parents 0309612 + 678d20a commit 5cb9fe6
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 29 deletions.
11 changes: 11 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
coverage:
status:
project:
default: false
tests:
paths: tests
informational: true
knox:
paths: knox
informational: true
patch: off
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[run]
branch = True
source = knox
omit =
*/migrations/*
18 changes: 12 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ jobs:
fail-fast: false
max-parallel: 5
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key:
Expand All @@ -36,8 +36,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade tox tox-gh-actions
python -m pip install --upgrade tox tox-gh-actions coverage
- name: Tox tests
run: |
tox -v
- name: Generate coverage XML report
run: coverage xml

- name: Codecov
uses: codecov/codecov-action@v3
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[![Jazzband](https://jazzband.co/static/img/jazzband.svg)](https://jazzband.co/)

This is a [Jazzband](https://jazzband.co/) project. By contributing you agree to abide by the [Contributor Code of Conduct](https://jazzband.co/about/conduct) and follow the [guidelines](https://jazzband.co/about/guidelines).
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
django-rest-knox
================

[![image](https://github.com/James1345/django-rest-knox/workflows/Test/badge.svg?branch=develop)](https://github.com/James1345/django-rest-knox/actions)
[![Jazzband](https://jazzband.co/static/img/badge.svg)](https://jazzband.co/)
[![image](https://github.com/jazzband/django-rest-knox/workflows/Test/badge.svg?branch=develop)](https://github.com/jazzband/django-rest-knox/actions)

Authentication Module for django rest auth

Expand Down Expand Up @@ -39,7 +40,7 @@ default implementation:
the app settings (default is 10 hours.)

More information can be found in the
[Documentation](https://james1345.github.io/django-rest-knox/)
[Documentation](https://jazzband.github.io/django-rest-knox/)

# Run the tests locally

Expand Down
18 changes: 8 additions & 10 deletions docs/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,17 @@ If it is your only default authentication class, remember to overwrite knox's Lo

For instance, you can authenticate users using Basic Authentication by simply overwriting knox's LoginView and setting BasicAuthentication as one of the acceptable authentication classes, as follows:

**views.py:**
```python

views.py:

from knox.views import LoginView as KnoxLoginView
from rest_framework.authentication import BasicAuthentication

class LoginView(KnoxLoginView):
authentication_classes = [BasicAuthentication]
```

urls.py:

**urls.py:**
```python
from knox import views as knox_views
from yourapp.api.views import LoginView

Expand All @@ -75,10 +74,8 @@ You can use any number of authentication classes if you want to be able to authe

If you decide to use Token Authentication as your only authentication class, you can overwrite knox's login view as such:

**views.py:**
```python

views.py:

from django.contrib.auth import login

from rest_framework import permissions
Expand All @@ -94,9 +91,10 @@ class LoginView(KnoxLoginView):
user = serializer.validated_data['user']
login(request, user)
return super(LoginView, self).post(request, format=None)
```

urls.py:

**urls.py:**
```python
from knox import views as knox_views
from yourapp.api.views import LoginView

Expand Down
2 changes: 1 addition & 1 deletion knox_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_L10N = True # Deprecated since django 4.0.
USE_TZ = True

STATIC_URL = '/static/'
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
site_name: Django-Rest-Knox
repo_url: https://github.com/James1345/django-rest-knox
repo_url: https://github.com/jazzband/django-rest-knox
theme: readthedocs
nav:
- Home: 'index.md'
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
long_description_content_type='text/markdown',

# The project's main homepage.
url='https://github.com/James1345/django-rest-knox',
url='https://github.com/jazzband/django-rest-knox',

# Author details
author='James McMahon',
Expand Down Expand Up @@ -51,6 +51,7 @@
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
],

# What does your project relate to?
Expand Down
16 changes: 12 additions & 4 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def get_basic_auth_header(username, password):
token_prefix_too_long_knox = knox_settings.defaults.copy()
token_prefix_too_long_knox["TOKEN_PREFIX"] = token_prefix_too_long


class AuthTestCase(TestCase):

def setUp(self):
Expand Down Expand Up @@ -325,7 +326,10 @@ def handler(sender, username, **kwargs):

token_expired.connect(handler)

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

Expand Down Expand Up @@ -461,13 +465,15 @@ def test_token_with_prefix_returns_200(self):
)
self.assertEqual(response.status_code, 200)
self.assertTrue(response.data['token'].startswith(token_prefix))
self.client.credentials(HTTP_AUTHORIZATION=('Token %s' % response.data['token']))
self.client.credentials(
HTTP_AUTHORIZATION=('Token %s' % response.data['token'])
)
response = self.client.get(root_url, {}, format='json')
self.assertEqual(response.status_code, 200)
reload(views)

def test_prefix_set_longer_than_max_length_raises_valueerror(self):
with self.assertRaises(ValueError):
with self.assertRaises(ValueError):
with override_settings(REST_KNOX=token_prefix_too_long_knox):
pass

Expand All @@ -484,7 +490,9 @@ def test_tokens_created_before_prefix_still_work(self):
self.assertFalse(response.data['token'].startswith(token_prefix))
with override_settings(REST_KNOX=token_prefix_knox):
reload(views)
self.client.credentials(HTTP_AUTHORIZATION=('Token %s' % response.data['token']))
self.client.credentials(
HTTP_AUTHORIZATION=('Token %s' % response.data['token'])
)
response = self.client.get(root_url, {}, format='json')
self.assertEqual(response.status_code, 200)
reload(views)
13 changes: 9 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ envlist =
flake8,
py{36,37,38,39,310}-django32,
py{38,39,310}-django40,
py{38,39,310,311}-django41,

[testenv:flake8]
deps = flake8
Expand All @@ -22,14 +23,16 @@ commands = isort --check-only --diff \
[testenv]
commands =
python manage.py migrate
python manage.py test
coverage run manage.py test
coverage report
setenv =
DJANGO_SETTINGS_MODULE = knox_project.settings
PIP_INDEX_URL = https://pypi.python.org/simple/
deps =
django32: Django>=3.2,<3.3
django40: Django>=4.0,<4.1
markdown<3.0
django41: Django>=4.1.3,<4.2
markdown>=3.0
isort>=5.0
djangorestframework
freezegun
Expand All @@ -38,11 +41,13 @@ deps =
setuptools
twine
wheel
coverage

[gh-actions]
python =
3.6: py36
3.7: py37
3.8: py38
3.9: py39, isort, flake8
3.10: py310
3.9: py39
3.10: py310, isort, flake8
3.11: py311

0 comments on commit 5cb9fe6

Please sign in to comment.