diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d23c8f5..7082107 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -72,10 +72,10 @@ jobs: ln -s ./tests/settings.py settings.py ln -s ./tests/urls.py urls.py # run tests with coverage - coverage run --source='./django_rest_multitokenauth' manage.py test + coverage run --source='./drf_multitokenauth' manage.py test coverage xml - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 - name: Run tests run: cd tests && python manage.py test \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d8d28a..7ab7220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog -## [Unreleased] +## [2.0.0] + +- Rename package namesapce +- `2.0.0` migration guide + +## [1.5.0] - Added setting for disabling superuser login - Added Django 4.0 support @@ -53,7 +58,8 @@ - Internal release -[Unreleased]: https://github.com/anexia-it/django-rest-multitokenauth/compare/1.4.0...HEAD +[Unreleased]: https://github.com/anexia/drf-multitokenauth/compare/1.5.0...HEAD +[1.5.0]: https://pypi.org/project/django-rest-multitokenauth/1.5.0/ [1.4.0]: https://pypi.org/project/django-rest-multitokenauth/1.4.0/ [1.3.3]: https://pypi.org/project/django-rest-multitokenauth/1.3.3/ [1.3.2]: https://pypi.org/project/django-rest-multitokenauth/1.3.2/ diff --git a/README.md b/README.md index fa06b46..3b7d2ba 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Django Rest Multi Token Auth -[![PyPI](https://img.shields.io/pypi/v/django-rest-multitokenauth)](https://pypi.org/project/django-rest-multitokenauth/) -[![Build Status](https://travis-ci.org/anexia-it/django-rest-multitokenauth.svg?branch=master)](https://travis-ci.org/anexia-it/django-rest-multitokenauth) -[![Codecov](https://img.shields.io/codecov/c/gh/anexia-it/django-rest-multitokenauth)](https://codecov.io/gh/anexia-it/django-rest-multitokenauth) +[![PyPI](https://img.shields.io/pypi/v/drf-multitokenauth)](https://pypi.org/project/drf-multitokenauth/) +[![Test status](https://github.com/anexia-it/drf-multitokenauth/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/anexia-it/drf-multitokenauth/actions/workflows/test.yml) +[![Codecov](https://img.shields.io/codecov/c/gh/anexia/drf-multitokenauth)](https://codecov.io/gh/anexia/drf-multitokenauth) This django app is an extension for the Django Rest Framework. It tries to overcome the limitation of Token Authentication, which only uses a single token per user. @@ -11,10 +11,10 @@ It tries to overcome the limitation of Token Authentication, which only uses a s Install: ```bash -pip install django-rest-multitokenauth +pip install drf-multitokenauth ``` -Add ``'django_rest_multitokenauth'`` to your ``INSTALLED_APPS`` in your Django settings file: +Add ``'drf_multitokenauth'`` to your ``INSTALLED_APPS`` in your Django settings file: ```python INSTALLED_APPS = ( ... @@ -22,19 +22,19 @@ INSTALLED_APPS = ( ... 'rest_framework', ... - 'django_rest_multitokenauth', + 'drf_multitokenauth', ... ) ``` -Configure Django REST Framework to use ``'django_rest_multitokenauth.coreauthentication.MultiTokenAuthentication'``: +Configure Django REST Framework to use ``'drf_multitokenauth.coreauthentication.MultiTokenAuthentication'``: ```python REST_FRAMEWORK = { ... 'DEFAULT_AUTHENTICATION_CLASSES': [ ... - 'django_rest_multitokenauth.coreauthentication.MultiTokenAuthentication', + 'drf_multitokenauth.coreauthentication.MultiTokenAuthentication', ... ], ... @@ -50,7 +50,7 @@ from django.urls import re_path urlpatterns = [ ... - re_path(r'^api/auth/', include('django_rest_multitokenauth.urls', namespace='multi_token_auth')), + re_path(r'^api/auth/', include('drf_multitokenauth.urls', namespace='multi_token_auth')), ... ] ``` @@ -93,6 +93,7 @@ If your project uses an older verison of Django or Django Rest Framework, you ca | This Project | Python Version | Django Version | Django Rest Framework | |--------------|----------------|----------------|-----------------------| +| 2.0.* | 3.7+ | 3.2, 4.0, 4.1 | 3.12, 3.13 | | 1.5.* | 3.7+ | 3.2, 4.0, 4.1 | 3.12, 3.13 | | 1.4.* | 3.6+ | 2.2, 3.2 | 3.9, 3.10, 3.11, 3.12 | | 1.3.* | 2.7, 3.4+ | 1.11, 2.0 | 3.6, 3.7, 3.8 | @@ -100,10 +101,23 @@ If your project uses an older verison of Django or Django Rest Framework, you ca Make sure to use at least `DRF 3.10` when using `Django 3.0` or newer. +Releases prior to `2.0.0` where published as [django-rest-multitokenauth](https://pypi.org/project/django-rest-multitokenauth/). +Newer releases are published as [drf-multitokenauth](https://pypi.org/project/drf-multitokenauth/). + +## Migrating from 1.x to 2.x + +1. Uninstall `django-rest-multitokenauth` +2. Install `drf-multitokenauth` +3. Run the migration SQL bellow: + ``` + ALTER TABLE django_rest_multitokenauth_multitoken RENAME to drf_multitokenauth_multitoken; + UPDATE django_migrations SET app = 'drf_multitokenauth' WHERE app = 'django_rest_multitokenauth'; + ``` +4. Run Django migrations ## Changelog / Releases -All releases should be listed in the [releases tab on github](https://github.com/anexia-it/django-rest-multitokenauth/releases). +All releases should be listed in the [releases tab on github](https://github.com/anexia/drf-multitokenauth/releases). See [CHANGELOG.md](CHANGELOG.md) for a more detailed listing. diff --git a/django_rest_multitokenauth/__init__.py b/drf_multitokenauth/__init__.py similarity index 100% rename from django_rest_multitokenauth/__init__.py rename to drf_multitokenauth/__init__.py diff --git a/django_rest_multitokenauth/admin.py b/drf_multitokenauth/admin.py similarity index 78% rename from django_rest_multitokenauth/admin.py rename to drf_multitokenauth/admin.py index e986b2f..cf07738 100644 --- a/django_rest_multitokenauth/admin.py +++ b/drf_multitokenauth/admin.py @@ -1,6 +1,6 @@ """ contains basic admin views for MultiToken """ from django.contrib import admin -from django_rest_multitokenauth.models import MultiToken +from drf_multitokenauth.models import MultiToken @admin.register(MultiToken) diff --git a/django_rest_multitokenauth/coreauthentication.py b/drf_multitokenauth/coreauthentication.py similarity index 92% rename from django_rest_multitokenauth/coreauthentication.py rename to drf_multitokenauth/coreauthentication.py index c1a547a..d49a44f 100644 --- a/django_rest_multitokenauth/coreauthentication.py +++ b/drf_multitokenauth/coreauthentication.py @@ -1,11 +1,9 @@ """ Provides our custom MultiToken Authentication (based on normal Token Authentication) """ -from __future__ import unicode_literals - from rest_framework.authentication import TokenAuthentication -from django_rest_multitokenauth.models import MultiToken +from drf_multitokenauth.models import MultiToken # try to import memoize memoize = None diff --git a/django_rest_multitokenauth/migrations/0001_initial.py b/drf_multitokenauth/migrations/0001_initial.py similarity index 94% rename from django_rest_multitokenauth/migrations/0001_initial.py rename to drf_multitokenauth/migrations/0001_initial.py index 254aad4..d65ca61 100644 --- a/django_rest_multitokenauth/migrations/0001_initial.py +++ b/drf_multitokenauth/migrations/0001_initial.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models, migrations from django.conf import settings diff --git a/django_rest_multitokenauth/migrations/0002_rename_ip_address_20160426.py b/drf_multitokenauth/migrations/0002_rename_ip_address_20160426.py similarity index 70% rename from django_rest_multitokenauth/migrations/0002_rename_ip_address_20160426.py rename to drf_multitokenauth/migrations/0002_rename_ip_address_20160426.py index 3d1b274..c45ddf6 100644 --- a/django_rest_multitokenauth/migrations/0002_rename_ip_address_20160426.py +++ b/drf_multitokenauth/migrations/0002_rename_ip_address_20160426.py @@ -1,13 +1,10 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models, migrations class Migration(migrations.Migration): dependencies = [ - ('django_rest_multitokenauth', '0001_initial'), + ('drf_multitokenauth', '0001_initial'), ] operations = [ diff --git a/django_rest_multitokenauth/migrations/0003_pk_migration.py b/drf_multitokenauth/migrations/0003_pk_migration.py similarity index 92% rename from django_rest_multitokenauth/migrations/0003_pk_migration.py rename to drf_multitokenauth/migrations/0003_pk_migration.py index 47776b4..4185432 100644 --- a/django_rest_multitokenauth/migrations/0003_pk_migration.py +++ b/drf_multitokenauth/migrations/0003_pk_migration.py @@ -1,13 +1,10 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.conf import settings from django.db import migrations, models import django.db.models.deletion def populate_auto_incrementing_pk_field(apps, schema_editor): - MultiToken = apps.get_model('django_rest_multitokenauth', 'MultiToken') + MultiToken = apps.get_model('drf_multitokenauth', 'MultiToken') # Generate values for the new id column for i, o in enumerate(MultiToken.objects.all()): @@ -83,7 +80,7 @@ def get_migrations_based_on_django_version(): class Migration(migrations.Migration): dependencies = [ - ('django_rest_multitokenauth', '0002_rename_ip_address_20160426',), + ('drf_multitokenauth', '0002_rename_ip_address_20160426',), ] operations = get_migrations_based_on_django_version() diff --git a/django_rest_multitokenauth/migrations/__init__.py b/drf_multitokenauth/migrations/__init__.py similarity index 100% rename from django_rest_multitokenauth/migrations/__init__.py rename to drf_multitokenauth/migrations/__init__.py diff --git a/django_rest_multitokenauth/models.py b/drf_multitokenauth/models.py similarity index 96% rename from django_rest_multitokenauth/models.py rename to drf_multitokenauth/models.py index e7e47b7..9c526b6 100644 --- a/django_rest_multitokenauth/models.py +++ b/drf_multitokenauth/models.py @@ -57,7 +57,7 @@ class Meta: # # Also see corresponding ticket: # https://github.com/tomchristie/django-rest-framework/issues/705 - abstract = 'django_rest_multitokenauth' not in settings.INSTALLED_APPS + abstract = 'drf_multitokenauth' not in settings.INSTALLED_APPS verbose_name = _("Token") verbose_name_plural = _("Tokens") diff --git a/django_rest_multitokenauth/serializers.py b/drf_multitokenauth/serializers.py similarity index 100% rename from django_rest_multitokenauth/serializers.py rename to drf_multitokenauth/serializers.py diff --git a/django_rest_multitokenauth/signals.py b/drf_multitokenauth/signals.py similarity index 100% rename from django_rest_multitokenauth/signals.py rename to drf_multitokenauth/signals.py diff --git a/django_rest_multitokenauth/urls.py b/drf_multitokenauth/urls.py similarity index 68% rename from django_rest_multitokenauth/urls.py rename to drf_multitokenauth/urls.py index db656ef..2757dc5 100644 --- a/django_rest_multitokenauth/urls.py +++ b/drf_multitokenauth/urls.py @@ -1,10 +1,10 @@ """ URL Configuration for core auth """ from django.conf.urls import include -from django_rest_multitokenauth.views import login_and_obtain_auth_token, logout_and_delete_auth_token +from drf_multitokenauth.views import login_and_obtain_auth_token, logout_and_delete_auth_token from django.urls import re_path -app_name = 'django_rest_multitokenauth' +app_name = 'drf_multitokenauth' urlpatterns = [ re_path(r'^login', login_and_obtain_auth_token, name="auth-login"), # normal login with session diff --git a/django_rest_multitokenauth/views.py b/drf_multitokenauth/views.py similarity index 94% rename from django_rest_multitokenauth/views.py rename to drf_multitokenauth/views.py index 5c7aac8..73b163d 100644 --- a/django_rest_multitokenauth/views.py +++ b/drf_multitokenauth/views.py @@ -12,9 +12,9 @@ from rest_framework.views import APIView from rest_framework.authentication import get_authorization_header -from django_rest_multitokenauth.models import MultiToken -from django_rest_multitokenauth.serializers import EmailSerializer -from django_rest_multitokenauth.signals import pre_auth, post_auth +from drf_multitokenauth.models import MultiToken +from drf_multitokenauth.serializers import EmailSerializer +from drf_multitokenauth.signals import pre_auth, post_auth __all__ = [ 'LogoutAndDeleteAuthToken', diff --git a/setup.py b/setup.py index 0725a0f..e89d3d0 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ README = '\n' + f.read() setup( - name='django-rest-multitokenauth', + name='drf-multitokenauth', version=os.getenv('PACKAGE_VERSION', '0.0.0').replace('refs/tags/', ''), packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]), install_requires=[ @@ -19,7 +19,7 @@ description='An extension of django rest frameworks token auth, providing multiple authentication tokens per user', long_description=README, long_description_content_type='text/markdown', - url='https://github.com/anexia-it/django-rest-multitokenauth', + url='https://github.com/anexia/drf-multitokenauth', author='Harald Nezbeda', author_email='hnezbeda@anexia-it.com', classifiers=[ diff --git a/tests/settings.py b/tests/settings.py index ee4884d..3a25c43 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -42,7 +42,7 @@ 'rest_framework', # include multi token auth - 'django_rest_multitokenauth' + 'drf_multitokenauth' ] MIDDLEWARE = [ @@ -127,6 +127,6 @@ # REST Framework Configuration REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [ - 'django_rest_multitokenauth.coreauthentication.MultiTokenAuthentication' + 'drf_multitokenauth.coreauthentication.MultiTokenAuthentication' ] } \ No newline at end of file diff --git a/tests/test.py b/tests/test.py index 99d8977..b4b2de9 100644 --- a/tests/test.py +++ b/tests/test.py @@ -4,7 +4,7 @@ from django.test import override_settings from rest_framework import status from rest_framework.test import APITestCase -from django_rest_multitokenauth.models import MultiToken +from drf_multitokenauth.models import MultiToken from unittest.mock import patch from django.urls import reverse @@ -244,8 +244,8 @@ def test_logout_without_token(self): response = self.rest_do_logout(None) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) - @patch('django_rest_multitokenauth.signals.pre_auth.send') - @patch('django_rest_multitokenauth.signals.post_auth.send') + @patch('drf_multitokenauth.signals.pre_auth.send') + @patch('drf_multitokenauth.signals.post_auth.send') def test_signals(self, mock_pre_auth, mock_post_auth): """ checks whether the signal handlers are called or not""" # verify that signal handlers have not yet been called diff --git a/tests/urls.py b/tests/urls.py index e616e2a..95c77d3 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -3,5 +3,5 @@ from django.urls import re_path urlpatterns = [ - re_path(r'^api/auth/', include('django_rest_multitokenauth.urls', namespace='multi_token_auth')), + re_path(r'^api/auth/', include('drf_multitokenauth.urls', namespace='multi_token_auth')), ]