mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-11-22 09:06:40 +03:00
fixed code quality
This commit is contained in:
parent
eda3d7b6d2
commit
2572475971
|
@ -23,6 +23,7 @@ from .app_settings import RegisterSerializer
|
||||||
|
|
||||||
from rest_auth.utils import jwt_encode
|
from rest_auth.utils import jwt_encode
|
||||||
|
|
||||||
|
|
||||||
class RegisterView(CreateAPIView):
|
class RegisterView(CreateAPIView):
|
||||||
serializer_class = RegisterSerializer
|
serializer_class = RegisterSerializer
|
||||||
permission_classes = (AllowAny, )
|
permission_classes = (AllowAny, )
|
||||||
|
|
|
@ -118,6 +118,7 @@ class TokenSerializer(serializers.ModelSerializer):
|
||||||
model = TokenModel
|
model = TokenModel
|
||||||
fields = ('key',)
|
fields = ('key',)
|
||||||
|
|
||||||
|
|
||||||
class UserDetailsSerializer(serializers.ModelSerializer):
|
class UserDetailsSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -128,6 +129,7 @@ class UserDetailsSerializer(serializers.ModelSerializer):
|
||||||
fields = ('username', 'email', 'first_name', 'last_name')
|
fields = ('username', 'email', 'first_name', 'last_name')
|
||||||
read_only_fields = ('email', )
|
read_only_fields = ('email', )
|
||||||
|
|
||||||
|
|
||||||
class JWTSerializer(serializers.Serializer):
|
class JWTSerializer(serializers.Serializer):
|
||||||
"""
|
"""
|
||||||
Serializer for JWT authentication.
|
Serializer for JWT authentication.
|
||||||
|
@ -135,6 +137,7 @@ class JWTSerializer(serializers.Serializer):
|
||||||
token = serializers.CharField()
|
token = serializers.CharField()
|
||||||
user = UserDetailsSerializer()
|
user = UserDetailsSerializer()
|
||||||
|
|
||||||
|
|
||||||
class PasswordResetSerializer(serializers.Serializer):
|
class PasswordResetSerializer(serializers.Serializer):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -97,13 +97,12 @@ class APITestCase1(TestCase, BaseAPITestCase):
|
||||||
"username": self.USERNAME,
|
"username": self.USERNAME,
|
||||||
"password": self.PASS
|
"password": self.PASS
|
||||||
}
|
}
|
||||||
user = get_user_model().objects.create_user(self.USERNAME, '', self.PASS)
|
get_user_model().objects.create_user(self.USERNAME, '', self.PASS)
|
||||||
|
|
||||||
self.post(self.login_url, data=payload, status_code=200)
|
self.post(self.login_url, data=payload, status_code=200)
|
||||||
self.assertEqual('token' in self.response.json.keys(), True)
|
self.assertEqual('token' in self.response.json.keys(), True)
|
||||||
self.token = self.response.json['token']
|
self.token = self.response.json['token']
|
||||||
|
|
||||||
|
|
||||||
def test_login_by_email(self):
|
def test_login_by_email(self):
|
||||||
# starting test without allauth app
|
# starting test without allauth app
|
||||||
settings.INSTALLED_APPS.remove('allauth')
|
settings.INSTALLED_APPS.remove('allauth')
|
||||||
|
@ -335,7 +334,6 @@ class APITestCase1(TestCase, BaseAPITestCase):
|
||||||
user = get_user_model().objects.get(pk=user.pk)
|
user = get_user_model().objects.get(pk=user.pk)
|
||||||
self.assertEqual(user.email, self.response.json['email'])
|
self.assertEqual(user.email, self.response.json['email'])
|
||||||
|
|
||||||
|
|
||||||
def test_registration(self):
|
def test_registration(self):
|
||||||
user_count = get_user_model().objects.all().count()
|
user_count = get_user_model().objects.all().count()
|
||||||
|
|
||||||
|
@ -365,7 +363,6 @@ class APITestCase1(TestCase, BaseAPITestCase):
|
||||||
self._login()
|
self._login()
|
||||||
self._logout()
|
self._logout()
|
||||||
|
|
||||||
|
|
||||||
def test_registration_with_invalid_password(self):
|
def test_registration_with_invalid_password(self):
|
||||||
data = self.REGISTRATION_DATA.copy()
|
data = self.REGISTRATION_DATA.copy()
|
||||||
data['password2'] = 'foobar'
|
data['password2'] = 'foobar'
|
||||||
|
@ -430,7 +427,7 @@ class APITestCase1(TestCase, BaseAPITestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
# create user
|
# create user
|
||||||
user = get_user_model().objects.create_user(self.USERNAME, '', self.PASS)
|
get_user_model().objects.create_user(self.USERNAME, '', self.PASS)
|
||||||
|
|
||||||
self.post(self.login_url, data=payload, status_code=200)
|
self.post(self.login_url, data=payload, status_code=200)
|
||||||
self.get(self.logout_url, status=status.HTTP_200_OK)
|
self.get(self.logout_url, status=status.HTTP_200_OK)
|
||||||
|
@ -443,7 +440,7 @@ class APITestCase1(TestCase, BaseAPITestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
# create user
|
# create user
|
||||||
user = get_user_model().objects.create_user(self.USERNAME, '', self.PASS)
|
get_user_model().objects.create_user(self.USERNAME, '', self.PASS)
|
||||||
|
|
||||||
self.post(self.login_url, data=payload, status_code=status.HTTP_200_OK)
|
self.post(self.login_url, data=payload, status_code=status.HTTP_200_OK)
|
||||||
self.get(self.logout_url, status_code=status.HTTP_405_METHOD_NOT_ALLOWED)
|
self.get(self.logout_url, status_code=status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||||
|
|
|
@ -150,4 +150,3 @@ class TestSocialAuth(TestCase, BaseAPITestCase):
|
||||||
self.assertIn('user', self.response.json.keys())
|
self.assertIn('user', self.response.json.keys())
|
||||||
|
|
||||||
self.assertEqual(get_user_model().objects.all().count(), users_count + 1)
|
self.assertEqual(get_user_model().objects.all().count(), users_count + 1)
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ def default_create_token(token_model, user, serializer):
|
||||||
token, _ = token_model.objects.get_or_create(user=user)
|
token, _ = token_model.objects.get_or_create(user=user)
|
||||||
return token
|
return token
|
||||||
|
|
||||||
|
|
||||||
def jwt_encode(user):
|
def jwt_encode(user):
|
||||||
try:
|
try:
|
||||||
from rest_framework_jwt.settings import api_settings
|
from rest_framework_jwt.settings import api_settings
|
||||||
|
|
|
@ -55,7 +55,6 @@ class LoginView(GenericAPIView):
|
||||||
if getattr(settings, 'REST_SESSION_LOGIN', True):
|
if getattr(settings, 'REST_SESSION_LOGIN', True):
|
||||||
login(self.request, self.user)
|
login(self.request, self.user)
|
||||||
|
|
||||||
|
|
||||||
def get_response(self):
|
def get_response(self):
|
||||||
serializer_class = self.get_response_serializer()
|
serializer_class = self.get_response_serializer()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user