Skip to content
Snippets Groups Projects
Commit fab1e0e1 authored by Chris Li's avatar Chris Li
Browse files

Fix bug for is_valid setting to False, add test cases.

parent eaf055c9
No related branches found
No related tags found
1 merge request!1User Authentication Feature Added
......@@ -15,6 +15,8 @@ class RegisterAPI(generics.GenericAPIView):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
user = serializer.save()
user.is_active = False
user.save()
token = AuthToken.objects.create(user)
return Response({
"user": UserSerializer(user, context=self.get_serializer_context()).data,
......@@ -37,8 +39,6 @@ class LoginAPI(generics.GenericAPIView):
def verify_user_and_activate(request, token):
#print(AuthToken.objects.filter(pk=token).first())
print(AuthToken.objects.all())
try:
auth = AuthToken.objects.filter(digest=token).first()
auth.user.is_active = True
......
......@@ -15,8 +15,6 @@ def create_related_profile(sender, instance, created, *args, **kwargs):
if instance and created:
# create profile for new user
instance.profile = Profile.objects.create(user=instance)
# reset user's status to inactive
instance.is_active = False
@receiver(post_save, sender=User)
......
from django.test import TestCase
from django.contrib.auth.models import User
from rest_framework.test import APIClient
from rest_framework.test import APITestCase
from rest_framework import status
# Create your tests here.
from .models.profile import Profile
class ProfileTestCase(APITestCase):
"""
Test suite for Contact
"""
def setUp(self):
self.client = APIClient()
self.data = {
"username": "xjhmlcy",
"email": "xjhmlcy@gmail.com",
"password": "abcdefg123"
}
self.url = "/api/auth/register"
def test_create_contact(self):
'''
test ContactViewSet create method
'''
data = self.data
response = self.client.post(self.url, data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(User.objects.count(), 1)
self.assertEqual(Profile.objects.count(), 1)
self.assertEqual(User.objects.get().username, "xjhmlcy")
self.assertEqual(Profile.objects.get().user.email, "xjhmlcy@gmail.com")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment