mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
test: add unit tests for user account activation flow
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.contrib.auth.tokens import default_token_generator
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from django.utils.encoding import force_bytes
|
||||||
|
from django.utils.http import urlsafe_base64_encode
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
@@ -28,3 +31,20 @@ class AuthTests(APITestCase):
|
|||||||
self.assertIn(cookie_name, response.cookies)
|
self.assertIn(cookie_name, response.cookies)
|
||||||
# verify the cookie has a value
|
# verify the cookie has a value
|
||||||
self.assertTrue(response.cookies[cookie_name].value)
|
self.assertTrue(response.cookies[cookie_name].value)
|
||||||
|
|
||||||
|
|
||||||
|
class ActivationTests(APITestCase):
|
||||||
|
def test_user_activation(self):
|
||||||
|
# initial user state
|
||||||
|
user = User.objects.create_user(email="inactive@test.com", password="password1234", is_active=False)
|
||||||
|
# generate activation link
|
||||||
|
uidb64 = urlsafe_base64_encode(force_bytes(user.public_id))
|
||||||
|
token = default_token_generator.make_token(user)
|
||||||
|
# call activation url
|
||||||
|
activation_url = reverse("activate", kwargs={"uidb64": uidb64, "token": token})
|
||||||
|
response = self.client.get(activation_url)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
# check user is activated
|
||||||
|
user.refresh_from_db()
|
||||||
|
self.assertTrue(user.is_active)
|
||||||
|
|||||||
Reference in New Issue
Block a user