from ..tokens import verification_email_token from django.test import TestCase, Client from django.urls import reverse from apps.user.models import LilcityUserProxy class VerificationEmailTest(TestCase): def setUp(self): self.client = Client() self.user_1 = LilcityUserProxy.objects.create_user(username='user_1@example.com', password='1234') self.token_user_1 = verification_email_token.make_token(self.user_1) self.url = reverse('lilcity:verification-email', kwargs={"token": self.token_user_1, "uid": self.user_1.id}) def test_should_verification_email_for_login_user(self): self.client.login(username=self.user_1.username, password='1234') response = self.client.get(f'{self.url}') self.assertEqual(response.status_code, 200) def test_should_is_verification_email_for_user(self): self.assertFalse(self.user_1.lilcity_user_settings.is_verification_email) self.client.login(username=self.user_1.username, password='1234') self.client.get(f'{self.url}') self.user_1.refresh_from_db() self.assertTrue(self.user_1.lilcity_user_settings.is_verification_email) def test_should_anonymous_user(self): response = self.client.get(f'{self.url}') self.assertEqual(response.status_code, 400) def test_should_error_if_token_is_not_valid(self): user_hacker = LilcityUserProxy.objects.create_user(username='hacker@example.com', password='1234') self.client.login(username=user_hacker.username, password='1234') response = self.client.get(f'{self.url}') self.assertEqual(response.status_code, 400)