Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to Django 2.2.1 & DRF 3.9 plus some other package upgrades with minor changes. #120

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ We build on the shoulders of giants with the following technologies:

* [Django](https://www.djangoproject.com/)
* [Django REST framework](http://www.django-rest-framework.org/) Django REST framework is a powerful and flexible toolkit for building Web APIs
* [Django REST Knox](https://github.com/James1345/django-rest-knox) Token based authentication for API endpoints
* [Django Rest Auth](https://github.com/Tivix/django-rest-auth) Authentication Methods for API endpoints
* [WhiteNoise](http://whitenoise.evans.io/en/latest/django.html) to serve files efficiently from Django
* [Prospector](http://prospector.landscape.io/en/master/) a complete Python static analysis tool
* [Bandit](https://github.com/openstack/bandit) a security linter from OpenStack Security
* [pytest](http://pytest.org/latest/) a mature full-featured Python testing tool
* [Mock](http://www.voidspace.org.uk/python/mock/) mocking and testing Library
* [Responses](https://github.com/getsentry/responses) a utility for mocking out the Python Requests library

* [Python Email Validator](https://github.com/JoshData/python-email-validator) Validation and Domain Check for Emails

## Readme Notes

Expand Down
29 changes: 19 additions & 10 deletions py-requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
Django==1.11.4
django-extensions==1.8.1

django-disposable-email-checker==1.2.1
Django==2.2.1
django-extensions==2.1.7

# PostgresSQL
psycopg2==2.7.3
psycopg2==2.8.2

# serve files
whitenoise==3.3.0
whitenoise==4.1.2

# Rest Framework
djangorestframework==3.6.4
djangorestframework==3.9.4

# Sentry
raven==6.1.0
raven==6.10.0

# for date processing
python-dateutil==2.6.1
python-dateutil==2.8.0

# Logging
git+https://github.com/Seedstars/django-rest-logger.git

django-rest-knox==3.0.3
# email validator
email-validator==1.0.4
dnspython==1.16.0
idna==2.8

# django rest auth
django-rest-auth==0.9.5
six==1.10.0
pycodestyle==2.5.0
pytz==2019.1
sqlparse==0.3.0

20 changes: 10 additions & 10 deletions py-requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
-r base.txt

mock==2.0.0
factory-boy==2.9.2
mock==3.0.5
factory-boy==2.12.0

prospector==0.12.7
bandit==1.4.0
prospector==1.1.6.2
bandit==1.6.0

pytest==3.2.1
pytest-cov==2.5.1
pytest-django==3.1.2
pytest-pythonpath==0.7.1
pytest-xdist==1.20.0
pytest==4.6.1
pytest-cov==2.7.1
pytest-django==3.4.8
pytest-pythonpath==0.7.3
pytest-xdist==1.28.0

ptpython==0.41
ptpython==2.0.4
26 changes: 13 additions & 13 deletions src/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from django.conf.urls import url
from django.urls import path
from django.utils.translation import ugettext_lazy as _

import accounts.views

urlpatterns = [
url(_(r'^register/$'),
accounts.views.UserRegisterView.as_view(),
name='register'),
url(_(r'^login/$'),
accounts.views.UserLoginView.as_view(),
name='login'),
url(_(r'^confirm/email/(?P<activation_key>.*)/$'),
accounts.views.UserConfirmEmailView.as_view(),
name='confirm_email'),
url(_(r'^status/email/$'),
accounts.views.UserEmailConfirmationStatusView.as_view(),
name='status'),
path(_('register/'),
accounts.views.UserRegisterView.as_view(),
name='register'),
path(_('login/'),
accounts.views.UserLoginView.as_view(),
name='login'),
path(_('confirm/email/<str:activation_key>/'),
accounts.views.UserConfirmEmailView.as_view(),
name='confirm_email'),
path(_('status/email/'),
accounts.views.UserEmailConfirmationStatusView.as_view(),
name='status'),

]
11 changes: 6 additions & 5 deletions src/accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.shortcuts import get_object_or_404
from django_rest_logger import log
from knox.auth import TokenAuthentication
from knox.models import AuthToken
from rest_framework.authentication import TokenAuthentication
from rest_framework.authtoken.models import Token as TokenModel
from rest_framework import status
from rest_framework.authentication import BasicAuthentication
from rest_framework.generics import GenericAPIView
Expand Down Expand Up @@ -30,10 +30,11 @@ class UserLoginView(GenericAPIView):

def post(self, request):
"""User login with username and password."""
token = AuthToken.objects.create(request.user)
token = TokenModel.objects.get_or_create(user=request.user)

return Response({
'user': self.get_serializer(request.user).data,
'token': token
'token': token[0].key
})


Expand All @@ -47,7 +48,7 @@ def get(self, request, activation_key):

Receive an activation key as parameter and confirm email.
"""
user = get_object_or_404(User, activation_key=str(activation_key))
user = get_object_or_404(User, activation_key=activation_key)
if user.confirm_email():
return Response(status=status.HTTP_200_OK)

Expand Down
8 changes: 4 additions & 4 deletions src/base/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.conf.urls import url
from django.urls import path

from base import views as base_views

urlpatterns = [
url(r'',
base_views.ProtectedDataView.as_view(),
name='protected_data'),
path('',
base_views.ProtectedDataView.as_view(),
name='protected_data'),
]
2 changes: 1 addition & 1 deletion src/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.conf import settings
from django.http import HttpResponse
from django.views.generic import View
from knox.auth import TokenAuthentication
from rest_framework.authentication import TokenAuthentication
from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.permissions import IsAuthenticated
Expand Down
17 changes: 6 additions & 11 deletions src/djangoreactredux/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

DEBUG = True

ALLOWED_HOSTS = ['localhost']
ALLOWED_HOSTS = ['localhost', '127.0.0.1']

# Application definition

Expand All @@ -22,14 +22,15 @@
'django.contrib.admin',

'rest_framework',
'knox',
'rest_framework.authtoken',
'rest_auth',
'django_extensions',

'accounts',
'base'
]

MIDDLEWARE_CLASSES = [
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.common.CommonMiddleware',
Expand All @@ -38,7 +39,6 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.common.CommonMiddleware'
]

TEMPLATES = [
Expand Down Expand Up @@ -90,7 +90,9 @@
'DEFAULT_PERMISSION_CLASSES': [],
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.BasicAuthentication',

],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 20,
Expand All @@ -100,10 +102,3 @@
'rest_framework.parsers.MultiPartParser',
],
}

# ############ REST KNOX ########################
REST_KNOX = {
'SECURE_HASH_ALGORITHM': 'cryptography.hazmat.primitives.hashes.SHA512',
'AUTH_TOKEN_CHARACTER_LENGTH': 64,
'USER_SERIALIZER': 'knox.serializers.UserSerializer'
}
10 changes: 6 additions & 4 deletions src/djangoreactredux/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls import include
from django.urls import path
from django.views.decorators.cache import cache_page

from base import views as base_views


urlpatterns = [
url(r'^api/v1/accounts/', include('accounts.urls', namespace='accounts')),
url(r'^api/v1/getdata/', include('base.urls', namespace='base')),
path('api/v1/accounts/', include(('accounts.urls', 'accounts'), namespace='accounts')),
path('api/v1/getdata/', include(('base.urls', 'base'), namespace='base')),

# catch all others because of how history is handled by react router - cache this page because it will never change
url(r'', cache_page(settings.PAGE_CACHE_SECONDS)(base_views.IndexView.as_view()), name='index'),
path('', cache_page(settings.PAGE_CACHE_SECONDS)(base_views.IndexView.as_view()), name='index'),
]
8 changes: 4 additions & 4 deletions src/lib/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from disposable_email_checker.validators import validate_disposable_email
from django.core.exceptions import ValidationError
from django.core.validators import validate_email as django_validate_email
from django.db import transaction
from email_validator import validate_email as existence_check, EmailNotValidError


def validate_email(value):
Expand All @@ -14,10 +14,10 @@ def validate_email(value):
except ValidationError:
return False
else:
# Check with the disposable list.
# Check if the domain name exists.
try:
validate_disposable_email(value)
except ValidationError:
existence_check(value)
except EmailNotValidError:
return False
else:
return True
Expand Down
2 changes: 1 addition & 1 deletion tests/python/accounts/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class UserRegistrationSerializerTest(CustomTestCase, APITestCase):
INVALID_DATA_DICT = [
{'data': {'email': 'test1@mailinator.com',
{'data': {'email': 'test1@FAKEmailinator.com',
'first_name': 'test',
'last_name': 'user',
'password': 'test'},
Expand Down
2 changes: 1 addition & 1 deletion tests/python/accounts/test_views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid

import base64
from django.core.urlresolvers import reverse
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APITestCase

Expand Down
2 changes: 1 addition & 1 deletion tests/python/base/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.test import override_settings
from rest_framework import status
from rest_framework.test import APITestCase
Expand Down
4 changes: 2 additions & 2 deletions tests/python/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class BaseTests(TestCase):
def test_validate_email(self):
self.assertEqual(validate_email('fail'), False)
self.assertEqual(validate_email(''), False)
self.assertEqual(validate_email('test@mailinator.com'), False)
self.assertEqual(validate_email('good.[email protected]'), False)
self.assertEqual(validate_email('test@mFAKEmailinator.com'), False)
self.assertEqual(validate_email('good([email protected]'), False)