apps.lyric.views updated with simpler FBV & test functionality for user login & authentication (some mocking employed); FT in test_simple_list_creation updated for new base.html content from several commits previous, now only FT not passing (to be expected) is under test_login

This commit is contained in:
Disco DeDisco
2026-01-31 15:16:34 -05:00
parent 9c102ac0f5
commit d236ab9d69
4 changed files with 17 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
from django.contrib import auth
from django.test import TestCase
from unittest import mock
from ..models import Token, User
from ..models import Token
class SendLoginEmailViewTest(TestCase):
def test_redirects_to_home_page(self):
@@ -78,6 +78,14 @@ class LoginViewTest(TestCase):
message = list(response.context["messages"])[0]
self.assertEqual(
message.message,
"Invalid login link!—please request a new one",
"Invalid login link!—please request another",
)
self.assertEqual(message.tags, "error")
@mock.patch("apps.lyric.views.auth")
def test_calls_authenticate_with_uid_from_get_request(self, mock_auth):
self.client.get("/apps/lyric/login?token=abc123")
self.assertEqual(
mock_auth.authenticate.call_args,
mock.call(uid="abc123")
)

View File

@@ -24,11 +24,8 @@ def send_login_email(request):
return redirect("/")
def login(request):
uid = request.GET.get("token")
user = auth.authenticate(request, uid=uid)
if user is not None:
user.backend = "apps.lyric.authentication.PasswordlessAuthenticationBackend"
if user := auth.authenticate(uid=request.GET["token"]):
auth.login(request, user)
else:
messages.error(request, "Invalid login link!—please request a new one")
messages.error(request, "Invalid login link!—please request another")
return redirect("/")

View File

@@ -10,9 +10,9 @@ class NewVisitorTest(FunctionalTest):
def test_can_start_a_todo_list(self):
self.browser.get(self.live_server_url)
self.assertIn('Dashboard', self.browser.title)
self.assertIn('Earthman RPG', self.browser.title)
header_text = self.browser.find_element(By.TAG_NAME, 'h1').text
self.assertIn('Dashboard', header_text)
self.assertIn('Welcome', header_text)
inputbox = self.get_item_input_box()
self.assertEqual(inputbox.get_attribute('placeholder'), 'Enter a to-do item')

View File

@@ -14,7 +14,9 @@
<div class="container">
<nav class="navbar">
<div class="container-fluid">
<a href="/" class="navbar-brand">Welcome, Earthman</a>
<a href="/" class="navbar-brand">
<h1>Welcome, Earthman</h1>
</a>
<form method="POST" action="{% url "send_login_email" %}">
<div class="input-group">
<label for="id_email_input" class="navbar-text me-2">