not getting the same precise error message, but perhaps the intent is the same?; anyway, updated views & some FTs, base.html for more dynamic error handling (tho incomplete)

This commit is contained in:
Disco DeDisco
2026-01-19 16:35:00 -05:00
parent d05d296f65
commit 8d23d9f2c2
6 changed files with 56 additions and 20 deletions

View File

@@ -1,4 +1,5 @@
from django.test import TestCase
from django.utils import html
from ..models import Item, List
import lxml.html
@@ -56,6 +57,18 @@ class NewListTest(TestCase):
new_list = List.objects.get()
self.assertRedirects(response, f'/apps/dashboard/{new_list.id}/')
def test_validation_errors_are_sent_back_to_home_page_template(self):
response = self.client.post("/apps/dashboard/newlist", data={"item_text": ""})
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "apps/dashboard/home.html")
expected_error = html.escape("You can't have an empty list item")
self.assertContains(response, expected_error)
def test_invalid_list_items_never_save(self):
self.client.post("/apps/dashboard/newlist", data={"item_text": ""})
self.assertEqual(List.objects.count(), 0)
self.assertEqual(Item.objects.count(), 0)
class NewItemTest(TestCase):
def test_can_save_a_POST_request_to_an_existing_list(self):
other_list = List.objects.create()