Skip to content

Commit

Permalink
Refacotor package namespace according to new conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
nezhar committed Oct 14, 2022
1 parent 5aac628 commit 745acda
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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/
Expand Down
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -11,30 +11,30 @@ 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 = (
...
'django.contrib.auth',
...
'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',
...
],
...
Expand All @@ -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')),
...
]
```
Expand Down Expand Up @@ -93,17 +93,31 @@ 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 |
| 1.2.* | 2.7, 3.4+ | 1.8, 1.11, 2.0 | 3.6, 3.7, 3.8 |

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.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.conf import settings

Expand Down
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
@@ -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()):
Expand Down Expand Up @@ -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()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand All @@ -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=[
Expand Down
4 changes: 2 additions & 2 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'rest_framework',

# include multi token auth
'django_rest_multitokenauth'
'drf_multitokenauth'
]

MIDDLEWARE = [
Expand Down Expand Up @@ -127,6 +127,6 @@
# REST Framework Configuration
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'django_rest_multitokenauth.coreauthentication.MultiTokenAuthentication'
'drf_multitokenauth.coreauthentication.MultiTokenAuthentication'
]
}
6 changes: 3 additions & 3 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
]

0 comments on commit 745acda

Please sign in to comment.