|
|
|
@ -1,16 +1,15 @@ |
|
|
|
from django.contrib.auth import get_user_model |
|
|
|
|
|
|
|
from ..tokens import verification_email_token |
|
|
|
from ..tokens import verification_email_token |
|
|
|
from django.test import TestCase, Client |
|
|
|
from django.test import TestCase, Client |
|
|
|
from django.urls import reverse |
|
|
|
from django.urls import reverse |
|
|
|
|
|
|
|
|
|
|
|
User = get_user_model() |
|
|
|
from apps.user.models import LilcityUserProxy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VerificationEmailTest(TestCase): |
|
|
|
class VerificationEmailTest(TestCase): |
|
|
|
def setUp(self): |
|
|
|
def setUp(self): |
|
|
|
self.client = Client() |
|
|
|
self.client = Client() |
|
|
|
|
|
|
|
|
|
|
|
self.user_1 = User.objects.create_user(username='user_1@example.com', password='1234') |
|
|
|
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.token_user_1 = verification_email_token.make_token(self.user_1) |
|
|
|
|
|
|
|
|
|
|
|
self.url = reverse('lilcity:verification-email', kwargs={"token": self.token_user_1}) |
|
|
|
self.url = reverse('lilcity:verification-email', kwargs={"token": self.token_user_1}) |
|
|
|
@ -21,13 +20,22 @@ class VerificationEmailTest(TestCase): |
|
|
|
response = self.client.get(f'{self.url}') |
|
|
|
response = self.client.get(f'{self.url}') |
|
|
|
self.assertEqual(response.status_code, 200) |
|
|
|
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): |
|
|
|
def test_should_anonymous_user(self): |
|
|
|
response = self.client.get(f'{self.url}') |
|
|
|
response = self.client.get(f'{self.url}') |
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 400) |
|
|
|
self.assertEqual(response.status_code, 400) |
|
|
|
|
|
|
|
|
|
|
|
def test_should_error_if_token_is_not_valid(self): |
|
|
|
def test_should_error_if_token_is_not_valid(self): |
|
|
|
user_hacker = User.objects.create_user(username='hacker@example.com', password='1234') |
|
|
|
user_hacker = LilcityUserProxy.objects.create_user(username='hacker@example.com', password='1234') |
|
|
|
|
|
|
|
|
|
|
|
self.client.login(username=user_hacker.username, password='1234') |
|
|
|
self.client.login(username=user_hacker.username, password='1234') |
|
|
|
response = self.client.get(f'{self.url}') |
|
|
|
response = self.client.get(f'{self.url}') |
|
|
|
|