refactored to green: all references in urlpatterns thruout project to apps/ dir now skip it & point directly to the app contained w.in (i.e., not apps/lyric/ or apps/dashboard/, but lyric/ or dashboard/ now
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Disco DeDisco
2026-02-22 22:08:34 -05:00
parent a8c199b719
commit 94f3120add
5 changed files with 39 additions and 39 deletions

View File

@@ -21,26 +21,26 @@ class HomePageTest(TestCase):
response = self.client.get('/')
parsed = lxml.html.fromstring(response.content)
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"]
self.assertIn("/dashboard/new_list", [form.get("action") for form in forms])
[form] = [form for form in forms if form.get("action") == "/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/new_list", data={"text": "A new list item"})
self. client.post("/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")
def test_redirects_after_POST(self):
response = self.client.post("/apps/dashboard/new_list", data={"text": "A new list item"})
response = self.client.post("/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"/dashboard/{new_list.id}/")
# Post invalid input helper
def post_invalid_input(self):
return self.client.post("/apps/dashboard/new_list", data={"text": ""})
return self.client.post("/dashboard/new_list", data={"text": ""})
def test_for_invalid_input_nothing_saved_to_db(self):
self.post_invalid_input()
@@ -58,12 +58,12 @@ 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}/")
response = self.client.get(f"/dashboard/{mylist.id}/")
self.assertTemplateUsed(response, "apps/dashboard/list.html")
def test_renders_input_form(self):
mylist = List.objects.create()
url = f"/apps/dashboard/{mylist.id}/"
url = f"/dashboard/{mylist.id}/"
response = self.client.get(url)
parsed = lxml.html.fromstring(response.content)
forms = parsed.cssselect("form[method=POST]")
@@ -80,7 +80,7 @@ class ListViewTest(TestCase):
other_list = List.objects.create()
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"/dashboard/{correct_list.id}/")
# Then/Assert
self.assertContains(response, "itemey 1")
self.assertContains(response, "itemey 2")
@@ -91,7 +91,7 @@ class ListViewTest(TestCase):
correct_list = List.objects.create()
self.client.post(
f"/apps/dashboard/{correct_list.id}/",
f"/dashboard/{correct_list.id}/",
data={"text": "A new item for an existing list"},
)
@@ -105,16 +105,16 @@ class ListViewTest(TestCase):
correct_list = List.objects.create()
response = self.client.post(
f"/apps/dashboard/{correct_list.id}/",
f"/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"/dashboard/{correct_list.id}/")
# Post invalid input helper
def post_invalid_input(self):
mylist = List.objects.create()
return self.client.post(f"/apps/dashboard/{mylist.id}/", data={"text": ""})
return self.client.post(f"/dashboard/{mylist.id}/", data={"text": ""})
def test_for_invalid_input_nothing_saved_to_db(self):
self.post_invalid_input()
@@ -140,7 +140,7 @@ class ListViewTest(TestCase):
Item.objects.create(list=list1, text="lorem ipsum")
response = self.client.post(
f"/apps/dashboard/{list1.id}/",
f"/dashboard/{list1.id}/",
data={"text": "lorem ipsum"},
)
@@ -153,26 +153,26 @@ class MyListsTest(TestCase):
def test_my_lists_url_renders_my_lists_template(self):
user = User.objects.create(email="a@b.cde")
self.client.force_login(user)
response = self.client.get(f"/apps/dashboard/users/{user.id}/")
response = self.client.get(f"/dashboard/users/{user.id}/")
self.assertTemplateUsed(response, "apps/dashboard/my_lists.html")
def test_passes_correct_owner_to_template(self):
User.objects.create(email="wrongowner@example.com")
correct_user = User.objects.create(email="a@b.cde")
self.client.force_login(correct_user)
response = self.client.get(f"/apps/dashboard/users/{correct_user.id}/")
response = self.client.get(f"/dashboard/users/{correct_user.id}/")
self.assertEqual(response.context["owner"], correct_user)
def test_list_owner_is_saved_if_user_is_authenticated(self):
user = User.objects.create(email="a@b.cde")
self.client.force_login(user)
self.client.post("/apps/dashboard/new_list", data={"text": "new item"})
self.client.post("/dashboard/new_list", data={"text": "new item"})
new_list = List.objects.get()
self.assertEqual(new_list.owner, user)
def test_my_lists_redirects_if_not_logged_in(self):
user = User.objects.create(email="a@b.cde")
response = self.client.get(f"/apps/dashboard/users/{user.id}/")
response = self.client.get(f"/dashboard/users/{user.id}/")
self.assertRedirects(response, "/")
def test_my_lists_returns_403_for_wrong_user(self):
@@ -180,7 +180,7 @@ class MyListsTest(TestCase):
user1 = User.objects.create(email="a@b.cde")
user2 = User.objects.create(email="wrongowner@example.com")
self.client.force_login(user2)
response = self.client.get(f"/apps/dashboard/users/{user1.id}/")
response = self.client.get(f"/dashboard/users/{user1.id}/")
# assert 403
self.assertEqual(response.status_code, 403)
@@ -189,16 +189,16 @@ class ShareListTest(TestCase):
our_list = List.objects.create()
alice = User.objects.create(email="alice@example.com")
response = self.client.post(
f"/apps/dashboard/{our_list.id}/share_list",
f"/dashboard/{our_list.id}/share_list",
data={"recipient": "alice@example.com"},
)
self.assertRedirects(response, f"/apps/dashboard/{our_list.id}/")
self.assertRedirects(response, f"/dashboard/{our_list.id}/")
def test_post_with_email_adds_user_to_shared_with(self):
our_list = List.objects.create()
alice = User.objects.create(email="alice@example.com")
self.client.post(
f"/apps/dashboard/{our_list.id}/share_list",
f"/dashboard/{our_list.id}/share_list",
data={"recipient": "alice@example.com"},
)
self.assertIn(alice, our_list.shared_with.all())
@@ -206,10 +206,10 @@ class ShareListTest(TestCase):
def test_post_with_nonexistent_email_redirects_to_list(self):
our_list = List.objects.create()
response = self.client.post(
f"/apps/dashboard/{our_list.id}/share_list",
f"/dashboard/{our_list.id}/share_list",
data={"recipient": "nobody@example.com"},
)
self.assertRedirects(response, f"/apps/dashboard/{our_list.id}/")
self.assertRedirects(response, f"/dashboard/{our_list.id}/")
def test_share_list_does_not_add_owner_as_recipient(self):
owner = User.objects.create(email="owner@example.com")