emancipated hardcoded form views & html from base.html, apps.dashboard.views, apps.dashboard.tests.test_views; added get_item_input_box() helper method to functional_tests.base & retrofitted the other FTs to utilize it

This commit is contained in:
Disco DeDisco
2026-01-20 15:14:05 -05:00
parent 93cc6632c4
commit 1d96871d7b
7 changed files with 59 additions and 54 deletions

View File

@@ -1,5 +1,6 @@
from django.test import TestCase
from django.utils import html
from ..forms import EMPTY_ITEM_ERROR
from ..models import Item, List
import lxml.html
@@ -28,17 +29,22 @@ 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={"text": ""})
# Post invalid input helper
def post_invalid_input(self):
return self.client.post("/apps/dashboard/newlist", data={"text": ""})
def test_for_invalid_input_nothing_saved_to_db(self):
self.post_invalid_input()
self.assertEqual(Item.objects.count(), 0)
def test_for_invalid_input_renders_list_template(self):
response = self.post_invalid_input()
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={"text": ""})
self.assertEqual(List.objects.count(), 0)
self.assertEqual(Item.objects.count(), 0)
def test_for_invalid_input_shows_error_on_page(self):
response = self.post_invalid_input()
self.assertContains(response, html.escape(EMPTY_ITEM_ERROR))
class DashViewTest(TestCase):
def test_uses_list_template(self):
@@ -94,13 +100,20 @@ class DashViewTest(TestCase):
self.assertRedirects(response, f'/apps/dashboard/{correct_list.id}/')
def test_validation_errors_end_up_on_lists_page(self):
list_ = List.objects.create()
response = self.client.post(
f"/apps/dashboard/{list_.id}/",
data={"text": ""},
)
# Post invalid input helper
def post_invalid_input(self):
mylist = List.objects.create()
return self.client.post(f"/apps/dashboard/{mylist.id}/", data={"text": ""})
def test_for_invalid_input_nothing_saved_to_db(self):
self.post_invalid_input()
self.assertEqual(Item.objects.count(), 0)
def test_for_invalid_input_renders_list_template(self):
response = self.post_invalid_input()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "apps/dashboard/list.html")
expected_error = html.escape("You can't have an empty list item")
self.assertContains(response, expected_error)
def test_for_invalid_input_shows_error_on_page(self):
response = self.post_invalid_input()
self.assertContains(response, html.escape(EMPTY_ITEM_ERROR))