fixed code quality

This commit is contained in:
mjaworski 2016-03-01 11:51:01 +00:00
parent eda3d7b6d2
commit 2572475971
6 changed files with 11 additions and 11 deletions

View File

@ -23,6 +23,7 @@ from .app_settings import RegisterSerializer
from rest_auth.utils import jwt_encode
class RegisterView(CreateAPIView):
serializer_class = RegisterSerializer
permission_classes = (AllowAny, )

View File

@ -118,6 +118,7 @@ class TokenSerializer(serializers.ModelSerializer):
model = TokenModel
fields = ('key',)
class UserDetailsSerializer(serializers.ModelSerializer):
"""
@ -128,6 +129,7 @@ class UserDetailsSerializer(serializers.ModelSerializer):
fields = ('username', 'email', 'first_name', 'last_name')
read_only_fields = ('email', )
class JWTSerializer(serializers.Serializer):
"""
Serializer for JWT authentication.
@ -135,6 +137,7 @@ class JWTSerializer(serializers.Serializer):
token = serializers.CharField()
user = UserDetailsSerializer()
class PasswordResetSerializer(serializers.Serializer):
"""

View File

@ -97,13 +97,12 @@ class APITestCase1(TestCase, BaseAPITestCase):
"username": self.USERNAME,
"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.assertEqual('token' in self.response.json.keys(), True)
self.token = self.response.json['token']
def test_login_by_email(self):
# starting test without allauth app
settings.INSTALLED_APPS.remove('allauth')
@ -335,7 +334,6 @@ class APITestCase1(TestCase, BaseAPITestCase):
user = get_user_model().objects.get(pk=user.pk)
self.assertEqual(user.email, self.response.json['email'])
def test_registration(self):
user_count = get_user_model().objects.all().count()
@ -365,7 +363,6 @@ class APITestCase1(TestCase, BaseAPITestCase):
self._login()
self._logout()
def test_registration_with_invalid_password(self):
data = self.REGISTRATION_DATA.copy()
data['password2'] = 'foobar'
@ -430,7 +427,7 @@ class APITestCase1(TestCase, BaseAPITestCase):
}
# 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.get(self.logout_url, status=status.HTTP_200_OK)
@ -443,7 +440,7 @@ class APITestCase1(TestCase, BaseAPITestCase):
}
# 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.get(self.logout_url, status_code=status.HTTP_405_METHOD_NOT_ALLOWED)

View File

@ -148,6 +148,5 @@ class TestSocialAuth(TestCase, BaseAPITestCase):
self.post(self.fb_login_url, data=payload, status_code=200)
self.assertIn('token', 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)

View File

@ -15,8 +15,9 @@ def default_create_token(token_model, user, serializer):
token, _ = token_model.objects.get_or_create(user=user)
return token
def jwt_encode(user):
try:
try:
from rest_framework_jwt.settings import api_settings
except ImportError:
raise ImportError('rest_framework_jwt needs to be installed')

View File

@ -46,7 +46,7 @@ class LoginView(GenericAPIView):
def login(self):
self.user = self.serializer.validated_data['user']
if getattr(settings, 'REST_USE_JWT', False):
self.token = jwt_encode(self.user)
else:
@ -55,7 +55,6 @@ class LoginView(GenericAPIView):
if getattr(settings, 'REST_SESSION_LOGIN', True):
login(self.request, self.user)
def get_response(self):
serializer_class = self.get_response_serializer()