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

@ -150,4 +150,3 @@ class TestSocialAuth(TestCase, BaseAPITestCase):
self.assertIn('user', self.response.json.keys())
self.assertEqual(get_user_model().objects.all().count(), users_count + 1)

View File

@ -15,6 +15,7 @@ def default_create_token(token_model, user, serializer):
token, _ = token_model.objects.get_or_create(user=user)
return token
def jwt_encode(user):
try:
from rest_framework_jwt.settings import api_settings

View File

@ -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()