From a734901b8096e0b057a7a924c5d649a43eb8418f Mon Sep 17 00:00:00 2001 From: Disco DeDisco Date: Thu, 29 Jan 2026 15:21:54 -0500 Subject: [PATCH] started lyric app (in earnest this time); added bootstrap-classed navbar w. login form to base.html; tweaked apps.dashboard.tests.test_views to accomodate multiple forms on same page --- src/apps/dashboard/tests/test_views.py | 61 ++++++++++++++------------ src/apps/dashboard/urls.py | 2 +- src/apps/lyric/__init__.py | 0 src/apps/lyric/admin.py | 3 ++ src/apps/lyric/apps.py | 5 +++ src/apps/lyric/migrations/__init__.py | 0 src/apps/lyric/models.py | 3 ++ src/apps/lyric/tests.py | 3 ++ src/apps/lyric/views.py | 3 ++ src/templates/core/base.html | 25 +++++++++-- 10 files changed, 72 insertions(+), 33 deletions(-) create mode 100644 src/apps/lyric/__init__.py create mode 100644 src/apps/lyric/admin.py create mode 100644 src/apps/lyric/apps.py create mode 100644 src/apps/lyric/migrations/__init__.py create mode 100644 src/apps/lyric/models.py create mode 100644 src/apps/lyric/tests.py create mode 100644 src/apps/lyric/views.py diff --git a/src/apps/dashboard/tests/test_views.py b/src/apps/dashboard/tests/test_views.py index 155d968..7814465 100644 --- a/src/apps/dashboard/tests/test_views.py +++ b/src/apps/dashboard/tests/test_views.py @@ -16,26 +16,27 @@ class HomePageTest(TestCase): def test_renders_input_form(self): response = self.client.get('/') 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('text', [input.get('name') for input in inputs]) + forms = parsed.cssselect('form[method=POST]') + self.assertIn("/apps/dashboard/new_list", [form.get("action") for form in forms]) + [form] = [form for form in forms if form.get("action") == "/apps/dashboard/new_list"] + inputs = form.cssselect("input") + self.assertIn("text", [input.get("name") for input in inputs]) class NewListTest(TestCase): def test_can_save_a_POST_request(self): - self. client.post('/apps/dashboard/newlist', data={'text': 'A new list item'}) + self. client.post("/apps/dashboard/new_list", data={"text": "A new list item"}) self.assertEqual(Item.objects.count(), 1) new_item = Item.objects.get() - self.assertEqual(new_item.text, 'A new list item') + self.assertEqual(new_item.text, "A new list item") def test_redirects_after_POST(self): - response = self.client.post('/apps/dashboard/newlist', data={'text': 'A new list item'}) + response = self.client.post("/apps/dashboard/new_list", data={"text": "A new list item"}) new_list = List.objects.get() - self.assertRedirects(response, f'/apps/dashboard/{new_list.id}/') + self.assertRedirects(response, f"/apps/dashboard/{new_list.id}/") # Post invalid input helper def post_invalid_input(self): - return self.client.post("/apps/dashboard/newlist", data={"text": ""}) + return self.client.post("/apps/dashboard/new_list", data={"text": ""}) def test_for_invalid_input_nothing_saved_to_db(self): self.post_invalid_input() @@ -53,44 +54,46 @@ class NewListTest(TestCase): class ListViewTest(TestCase): def test_uses_list_template(self): mylist = List.objects.create() - response = self.client.get(f'/apps/dashboard/{mylist.id}/') - self.assertTemplateUsed(response, 'apps/dashboard/list.html') + response = self.client.get(f"/apps/dashboard/{mylist.id}/") + self.assertTemplateUsed(response, "apps/dashboard/list.html") def test_renders_input_form(self): mylist = List.objects.create() - response = self.client.get(f'/apps/dashboard/{mylist.id}/') + url = f"/apps/dashboard/{mylist.id}/" + response = self.client.get(url) parsed = lxml.html.fromstring(response.content) - [form] = parsed.cssselect('form[method=POST]') - self.assertEqual(form.get('action'), f"/apps/dashboard/{mylist.id}/") - inputs = form.cssselect('input') - self.assertIn('text', [input.get('name') for input in inputs]) + forms = parsed.cssselect("form[method=POST]") + self.assertIn(url, [form.get("action") for form in forms]) + [form] = [form for form in forms if form.get("action") == url] + inputs = form.cssselect("input") + self.assertIn("text", [input.get("name") for input in inputs]) def test_displays_only_items_for_that_list(self): # Given/Arrange correct_list = List.objects.create() - Item.objects.create(text='itemey 1', list=correct_list) - Item.objects.create(text='itemey 2', list=correct_list) + Item.objects.create(text="itemey 1", list=correct_list) + Item.objects.create(text="itemey 2", list=correct_list) other_list = List.objects.create() - Item.objects.create(text='other list item', list=other_list) + Item.objects.create(text="other list item", list=other_list) # When/Act - response = self.client.get(f'/apps/dashboard/{correct_list.id}/') + response = self.client.get(f"/apps/dashboard/{correct_list.id}/") # Then/Assert - self.assertContains(response, 'itemey 1') - self.assertContains(response, 'itemey 2') - self.assertNotContains(response, 'other list item') + self.assertContains(response, "itemey 1") + self.assertContains(response, "itemey 2") + self.assertNotContains(response, "other list item") def test_can_save_a_POST_request_to_an_existing_list(self): other_list = List.objects.create() correct_list = List.objects.create() self.client.post( - f'/apps/dashboard/{correct_list.id}/', - data={'text': 'A new item for an existing list'}, + f"/apps/dashboard/{correct_list.id}/", + data={"text": "A new item for an existing list"}, ) self.assertEqual(Item.objects.count(), 1) new_item = Item.objects.get() - self.assertEqual(new_item.text, 'A new item for an existing list') + self.assertEqual(new_item.text, "A new item for an existing list") self.assertEqual(new_item.list, correct_list) def test_POST_redirects_to_list_view(self): @@ -98,11 +101,11 @@ class ListViewTest(TestCase): correct_list = List.objects.create() response = self.client.post( - f'/apps/dashboard/{correct_list.id}/', - data={'text': 'A new item for an existing list'}, + f"/apps/dashboard/{correct_list.id}/", + data={"text": "A new item for an existing list"}, ) - self.assertRedirects(response, f'/apps/dashboard/{correct_list.id}/') + self.assertRedirects(response, f"/apps/dashboard/{correct_list.id}/") # Post invalid input helper def post_invalid_input(self): diff --git a/src/apps/dashboard/urls.py b/src/apps/dashboard/urls.py index e0c6265..e04270e 100644 --- a/src/apps/dashboard/urls.py +++ b/src/apps/dashboard/urls.py @@ -2,6 +2,6 @@ from django.urls import path from . import views urlpatterns = [ - path('newlist', views.new_list, name='new_list'), + path('new_list', views.new_list, name='new_list'), path('/', views.view_list, name='view_list'), ] diff --git a/src/apps/lyric/__init__.py b/src/apps/lyric/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/apps/lyric/admin.py b/src/apps/lyric/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/src/apps/lyric/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/src/apps/lyric/apps.py b/src/apps/lyric/apps.py new file mode 100644 index 0000000..618476d --- /dev/null +++ b/src/apps/lyric/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class LyricConfig(AppConfig): + name = 'lyric' diff --git a/src/apps/lyric/migrations/__init__.py b/src/apps/lyric/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/apps/lyric/models.py b/src/apps/lyric/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/src/apps/lyric/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/src/apps/lyric/tests.py b/src/apps/lyric/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/src/apps/lyric/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/src/apps/lyric/views.py b/src/apps/lyric/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/src/apps/lyric/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/src/templates/core/base.html b/src/templates/core/base.html index b498c96..487f41a 100644 --- a/src/templates/core/base.html +++ b/src/templates/core/base.html @@ -6,16 +6,35 @@ - Dashboard | {% block title_text %}{% endblock title_text %} + Earthman RPG | {% block title_text %}{% endblock title_text %}
+ +
-

Dashboard

-

{% block header_text %}{% endblock header_text %}

+

{% block header_text %}{% endblock header_text %}

{% csrf_token %}