Skip to content

Commit

Permalink
[BE] minor fixes and utility changes (#3)
Browse files Browse the repository at this point in the history
* [BE] minor fixes and utility changes

* Correct travis config

* Correct travis config

* Correct travis config

* Correct travis config

* Correct travis config

* Correct travis config

* drop py2.7
  • Loading branch information
poxip committed Jul 12, 2018
1 parent aa21fe3 commit 840cf58
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 65 deletions.
68 changes: 22 additions & 46 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,35 @@ language: python
cache: pip
sudo: false

env:
- TOX_ENV=py27-flake8

- TOX_ENV=py27-django1.8-drf3.1
- TOX_ENV=py27-django1.8-drf3.2
- TOX_ENV=py27-django1.8-drf3.3
- TOX_ENV=py27-django1.8-drf3.4
- TOX_ENV=py27-django1.8-drf3.5

- TOX_ENV=py27-django1.9-drf3.1
- TOX_ENV=py27-django1.9-drf3.2
- TOX_ENV=py27-django1.9-drf3.3
- TOX_ENV=py27-django1.9-drf3.4
- TOX_ENV=py27-django1.9-drf3.5

- TOX_ENV=py27-django1.10-drf3.4
- TOX_ENV=py27-django1.10-drf3.5

- TOX_ENV=py27-django1.11-drf3.4
- TOX_ENV=py27-django1.11-drf3.5

- TOX_ENV=py34-django1.8-drf3.1
- TOX_ENV=py34-django1.8-drf3.2
- TOX_ENV=py34-django1.8-drf3.3
- TOX_ENV=py34-django1.8-drf3.4
- TOX_ENV=py34-django1.8-drf3.5

- TOX_ENV=py34-django1.9-drf3.1
- TOX_ENV=py34-django1.9-drf3.2
- TOX_ENV=py34-django1.9-drf3.3
- TOX_ENV=py34-django1.9-drf3.4
- TOX_ENV=py34-django1.9-drf3.5

- TOX_ENV=py34-django1.10-drf3.4
- TOX_ENV=py34-django1.10-drf3.5

- TOX_ENV=py34-django1.11-drf3.4
- TOX_ENV=py34-django1.11-drf3.5

- TOX_ENV=py35-django1.10-drf3.4
- TOX_ENV=py35-django1.10-drf3.5

- TOX_ENV=py35-django1.11-drf3.4
- TOX_ENV=py35-django1.11-drf3.5

matrix:
fast_finish: true
include:
- python: 3.6
env: TOXENV=py36-flake8

- python: 3.5
env: TOXENV=py35-django1.11-drf3.5
- python: 3.5
env: TOXENV=py35-django1.11-drf3.6
- python: 3.5
env: TOXENV=py35-django1.11-drf3.7
- python: 3.5
env: TOXENV=py35-django1.11-drf3.8

- python: 3.6
env: TOXENV=py36-django1.11-drf3.5
- python: 3.6
env: TOXENV=py36-django1.11-drf3.6
- python: 3.6
env: TOXENV=py36-django1.11-drf3.7
- python: 3.6
env: TOXENV=py36-django1.11-drf3.8

install:
- pip install tox coverage coveralls

script:
- tox -e $TOX_ENV
- tox

after_success:
- coverage report -m
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Change Log
All notable changes to this project will be documented in this file.

## [1.2.0] - 2018-07-12
### Added
- few minor utilities to make the project be easier to extend
### Fixed
- passing custom serializer context to devices refresh view
### Removed
- support for Python 2.7

## [1.1.0] - 2017-08-14
### Added
- Device list in Django admin
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ To use the ``jwt_devices.middleware.PermittedHeadersMiddleware`` in your applica
Support
=======
* Django 1.8 - 1.11
* Django Rest Framework 3.1 - 3.5
* Python 2.7, 3.4, 3.5, 3.6
* Django Rest Framework 3.1 - 3.8
* Python 3.4 - 3.6

.. |travis| image:: https://secure.travis-ci.org/ArabellaTech/drf-jwt-devices.svg?branch=master
.. _travis: http://travis-ci.org/ArabellaTech/drf-jwt-devices
Expand Down
4 changes: 2 additions & 2 deletions jwt_devices/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
__title__ = "Django Rest Framework JWT Devices"
__version__ = "1.1.0"
__version__ = "1.2.0"
__author__ = "Michal Proszek"
__license__ = "MIT"
__copyright__ = "Copyright 2017 Arabella"
__copyright__ = "Copyright 2017-2018 Arabella"

# Version synonym
VERSION = __version__
6 changes: 5 additions & 1 deletion jwt_devices/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Meta:
class DeviceTokenRefreshSerializer(Serializer):
HTTP_PERMANENT_TOKEN = serializers.CharField(required=True)

def validate(self, attrs):
def _get_device(self, attrs):
permanent_token = attrs["HTTP_PERMANENT_TOKEN"]
try:
device = Device.objects.get(permanent_token=permanent_token)
Expand All @@ -85,6 +85,10 @@ def validate(self, attrs):
device.last_request_datetime = now
device.save()

return device

def validate(self, attrs):
device = self._get_device(attrs)
payload = jwt_devices_payload_handler(device.user, device=device)
return {
"token": jwt_devices_encode_handler(payload),
Expand Down
9 changes: 4 additions & 5 deletions jwt_devices/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
from django.utils.translation import ugettext_lazy as _
from rest_framework import mixins, status, viewsets
from rest_framework.exceptions import NotFound, ValidationError
from rest_framework.generics import DestroyAPIView
from rest_framework.generics import DestroyAPIView, GenericAPIView
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework_jwt.settings import api_settings as rfj_settings
from rest_framework_jwt.views import ObtainJSONWebToken as OriginalObtainJSONWebToken

Expand Down Expand Up @@ -54,16 +53,16 @@ def post(self, request, *args, **kwargs):
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class DeviceRefreshJSONWebToken(APIView):
class DeviceRefreshJSONWebToken(GenericAPIView):
"""Refresh JWT token
API View used to refresh JSON Web Token using permanent token.
The DeviceRefreshJSONWebToken view requires the Permanent-Token header to be set in the request headers.
"""
serializer_class = DeviceTokenRefreshSerializer
permission_classes = [AllowAny]

def post(self, request):
serializer = self.serializer_class(data=request.META)
def post(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.META)
if serializer.is_valid(raise_exception=True):
data = jwt_devices_response_payload_handler(request=request, **serializer.validated_data)
return Response(data, status=status.HTTP_200_OK)
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-codestyle.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flake8>=3.2.1
pycodestyle>=2.2.0
pycodestyle>=2.2.0,<2.4
isort>=4.2.5
14 changes: 6 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tox]
downloadcache = {toxworkdir}/cache/
envlist =
py{27,36}-flake8,
{py27,py34,py35,py36}-django{1.8,1.9,1.10,1.11}-drf{3.1,3.2,3.3,3.4,3.5}
py36-flake8,
{py34,py35,py36}-django{1.10,1.11}-drf{3.5,3.6,3.7,3.8}

[testenv]
commands = ./runtests.py --fast {posargs} --coverage
Expand All @@ -13,15 +13,13 @@ deps =
django1.9: Django<1.10
django1.10: Django<1.11
django1.11: Django<2.0
drf3.1: djangorestframework<3.2
drf3.2: djangorestframework<3.3
drf3.3: djangorestframework<3.4
drf3.4: djangorestframework<3.5
drf3.5: djangorestframework<3.6
py27-django{1.8,1.9}-drf{3.1,3.2,3.3,3.4}: djangorestframework-oauth==1.0.1
drf3.6: djangorestframework<3.7
drf3.7: djangorestframework<3.8
drf3.8: djangorestframework<3.9
-rrequirements/requirements-testing.txt

[testenv:py27-flake8]
[testenv:py36-flake8]
commands = ./runtests.py --lintonly
deps =
-rrequirements/requirements-codestyle.txt
Expand Down

0 comments on commit 840cf58

Please sign in to comment.