diff --git a/core/api/auth.py b/core/api/auth.py index 4e2da3e54182eb2d74aa6985a19fbe498dfaa0ee..218450dd0143a0f70f40824719547ef9751ae8b2 100644 --- a/core/api/auth.py +++ b/core/api/auth.py @@ -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 diff --git a/core/signals.py b/core/signals.py index 107318cfc542baa92120b7647480159ffd5a97e2..565a0a81729237eb4d3d9b50d16cb0605c0332fe 100644 --- a/core/signals.py +++ b/core/signals.py @@ -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) diff --git a/core/tests.py b/core/tests.py index 7ce503c2dd97ba78597f6ff6e4393132753573f6..10cbc14cc3ad6d17b3f45744b488bf50888cf87f 100644 --- a/core/tests.py +++ b/core/tests.py @@ -1,3 +1,33 @@ -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")