reorganized and reclassified old 'unit tests' for ea. app into dirs for UTs & ITs; abandoning effort to refactor any test_views into UTs; all tests passing
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
50
src/apps/lyric/tests/integrated/test_authentication.py
Normal file
50
src/apps/lyric/tests/integrated/test_authentication.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import uuid
|
||||
from django.http import HttpRequest
|
||||
from django.test import TestCase
|
||||
|
||||
from apps.lyric.authentication import PasswordlessAuthenticationBackend
|
||||
from apps.lyric.models import Token, User
|
||||
|
||||
|
||||
class AuthenticateTest(TestCase):
|
||||
def test_returns_None_if_token_uuid_not_found(self):
|
||||
uid = uuid.uuid4()
|
||||
result = PasswordlessAuthenticationBackend().authenticate(
|
||||
HttpRequest(), uid
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_returns_new_user_with_correct_email_if_token_exists(self):
|
||||
email = "discoman@example.com"
|
||||
token = Token.objects.create(email=email)
|
||||
user = PasswordlessAuthenticationBackend().authenticate(
|
||||
HttpRequest(), token.uid
|
||||
)
|
||||
new_user = User.objects.get(email=email)
|
||||
self.assertEqual(user, new_user)
|
||||
|
||||
def test_returns_existing_user_with_correct_email_if_token_exists(self):
|
||||
email = "discoman@example.com"
|
||||
existing_user = User.objects.create(email=email)
|
||||
token = Token.objects.create(email=email)
|
||||
user = PasswordlessAuthenticationBackend().authenticate(
|
||||
HttpRequest(), token.uid
|
||||
)
|
||||
self.assertEqual(user, existing_user)
|
||||
|
||||
def test_can_retrieve_token_by_uuid(self):
|
||||
token = Token.objects.create(email="a@b.cde")
|
||||
fetched = Token.objects.get(pk=token.uid)
|
||||
self.assertEqual(fetched, token)
|
||||
|
||||
class GetUserTest(TestCase):
|
||||
def test_gets_user_by_uuid(self):
|
||||
User.objects.create(email="fantaman@example.com")
|
||||
desired_user = User.objects.create(email="discoman@example.com")
|
||||
found_user = PasswordlessAuthenticationBackend().get_user(desired_user.id)
|
||||
self.assertEqual(found_user, desired_user)
|
||||
|
||||
def test_returns_None_if_no_user_with_that_email(self):
|
||||
self.assertIsNone(
|
||||
PasswordlessAuthenticationBackend().get_user(999)
|
||||
)
|
||||
Reference in New Issue
Block a user