added lxml & cssselect to req'ments; this allowed more precise targeting of html attrs in apps.dashboard.tests'

This commit is contained in:
Disco DeDisco
2026-01-03 21:12:28 -05:00
parent 08305532c2
commit e3e753369f
2 changed files with 11 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
from django.test import TestCase
from .models import Item, List
import lxml.html
class HomePageTest(TestCase):
def test_uses_home_template(self):
@@ -8,12 +9,11 @@ class HomePageTest(TestCase):
def test_renders_input_form(self):
response = self.client.get('/')
self.assertContains(response, '<form method="POST" action="/apps/dashboard/newlist">')
self.assertContains(
response,
'<input name="item_text" id="id-new-item" placeholder="Enter a to-do item" />',
html=True,
)
parsed = lxml.html.fromstring(response.content)
[form] = parsed.cssselect('form[method=POST]')
self.assertEqual(form.get('action'), '/apps/dashboard/newlist')
inputs = form.cssselect('input')
self.assertIn('item_text', [input.get('name') for input in inputs])
class ListAndItemModelsTest(TestCase):
def test_saving_and_retrieving_items(self):
@@ -52,15 +52,11 @@ class DashViewTest(TestCase):
def test_renders_input_form(self):
mylist = List.objects.create()
response = self.client.get(f'/apps/dashboard/{mylist.id}/')
self.assertContains(
response,
f'<form method="POST" action="/apps/dashboard/{mylist.id}/add-item">',
)
self.assertContains(
response,
'<input name="item_text" id="id-new-item" placeholder="Enter a to-do item" />',
html=True,
)
parsed = lxml.html.fromstring(response.content)
[form] = parsed.cssselect('form[method=POST]')
self.assertEqual(form.get('action'), f"/apps/dashboard/{mylist.id}/add-item")
inputs = form.cssselect('input')
self.assertIn('item_text', [input.get('name') for input in inputs])
def test_displays_only_items_for_that_list(self):
# Given/Arrange