rename: Note→Post/Line (dashboard); Recognition→Note (drama); new-post/my-posts to billboard

- dashboard: Note→Post, Item→Line across models, forms, views, API, urls & tests
- new-post (9×3) & my-posts (3×3) applets migrate from dashboard→billboard context; billboard view passes form & recent_posts
- drama: Recognition→Note, related_name notes; billboard URL /recognition/→/my-notes/, set-palette at /note/<slug>/set-palette
- recognition.js→note.js (module Note, data.note key); recognition-page.js→note-page.js; .recog-*→.note-*
- _recognition.scss→_note.scss; BillNotes page header; applet slug billboard-recognition→billboard-notes (My Notes)
- NoteSpec.js replaces RecognitionSpec.js; test_recognition.py→test_applet_my_notes.py
- 4 migrations applied: dashboard 0004, applets 0011+0012, drama 0005; 683 ITs green

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Disco DeDisco
2026-04-22 22:32:34 -04:00
parent 6d9d3d4f54
commit 473e6bc45a
54 changed files with 1373 additions and 1283 deletions

View File

@@ -9,11 +9,11 @@ from django.utils import html, timezone
from apps.applets.models import Applet, UserApplet
from apps.dashboard.forms import (
DUPLICATE_ITEM_ERROR,
EMPTY_ITEM_ERROR,
DUPLICATE_LINE_ERROR,
EMPTY_LINE_ERROR,
)
from apps.dashboard.models import Item, Note
from apps.drama.models import Recognition
from apps.dashboard.models import Line, Post
from apps.drama.models import Note
from apps.lyric.models import User
@@ -21,64 +21,59 @@ class HomePageTest(TestCase):
def setUp(self):
self.user = User.objects.create(email="disco@test.io")
self.client.force_login(self.user)
Applet.objects.get_or_create(slug="new-note", defaults={"name": "New Note"})
def test_uses_home_template(self):
response = self.client.get('/')
self.assertTemplateUsed(response, 'apps/dashboard/home.html')
def test_renders_input_form(self):
response = self.client.get('/')
parsed = lxml.html.fromstring(response.content)
forms = parsed.cssselect('form[method=POST]')
self.assertIn("/dashboard/new_note", [form.get("action") for form in forms])
[form] = [form for form in forms if form.get("action") == "/dashboard/new_note"]
inputs = form.cssselect("input")
self.assertIn("text", [input.get("name") for input in inputs])
class NewNoteTest(TestCase):
@override_settings(COMPRESS_ENABLED=False)
class NewPostTest(TestCase):
def setUp(self):
user = User.objects.create(email="disco@test.io")
self.client.force_login(user)
self.user = User.objects.create(email="disco@test.io")
self.client.force_login(self.user)
Applet.objects.get_or_create(
slug="new-post",
defaults={"name": "New Post", "context": "billboard", "grid_cols": 9, "grid_rows": 3},
)
def test_can_save_a_POST_request(self):
self.client.post("/dashboard/new_note", data={"text": "A new note item"})
self.assertEqual(Item.objects.count(), 1)
new_item = Item.objects.get()
self.assertEqual(new_item.text, "A new note item")
self.client.post("/dashboard/new_post", data={"text": "A new post line"})
self.assertEqual(Line.objects.count(), 1)
new_line = Line.objects.get()
self.assertEqual(new_line.text, "A new post line")
def test_redirects_after_POST(self):
response = self.client.post("/dashboard/new_note", data={"text": "A new note item"})
new_note = Note.objects.get()
self.assertRedirects(response, f"/dashboard/note/{new_note.id}/")
response = self.client.post("/dashboard/new_post", data={"text": "A new post line"})
new_post = Post.objects.get()
self.assertRedirects(response, f"/dashboard/post/{new_post.id}/")
# Post invalid input helper
def post_invalid_input(self):
return self.client.post("/dashboard/new_note", data={"text": ""})
return self.client.post("/dashboard/new_post", data={"text": ""})
def test_for_invalid_input_nothing_saved_to_db(self):
self.post_invalid_input()
self.assertEqual(Item.objects.count(), 0)
self.assertEqual(Line.objects.count(), 0)
def test_for_invalid_input_renders_home_template(self):
def test_for_invalid_input_renders_billboard_template(self):
response = self.post_invalid_input()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "apps/dashboard/home.html")
self.assertTemplateUsed(response, "apps/billboard/billboard.html")
def test_for_invalid_input_shows_error_on_page(self):
response = self.post_invalid_input()
self.assertContains(response, html.escape(EMPTY_ITEM_ERROR))
self.assertContains(response, html.escape(EMPTY_LINE_ERROR))
@override_settings(COMPRESS_ENABLED=False)
class NoteViewTest(TestCase):
def test_uses_note_template(self):
mynote = Note.objects.create()
response = self.client.get(f"/dashboard/note/{mynote.id}/")
self.assertTemplateUsed(response, "apps/dashboard/note.html")
class PostViewTest(TestCase):
def test_uses_post_template(self):
mypost = Post.objects.create()
response = self.client.get(f"/dashboard/post/{mypost.id}/")
self.assertTemplateUsed(response, "apps/dashboard/post.html")
def test_renders_input_form(self):
mynote = Note.objects.create()
url = f"/dashboard/note/{mynote.id}/"
mypost = Post.objects.create()
url = f"/dashboard/post/{mypost.id}/"
response = self.client.get(url)
parsed = lxml.html.fromstring(response.content)
forms = parsed.cssselect("form[method=POST]")
@@ -87,62 +82,62 @@ class NoteViewTest(TestCase):
inputs = form.cssselect("input")
self.assertIn("text", [input.get("name") for input in inputs])
def test_displays_only_items_for_that_note(self):
def test_displays_only_lines_for_that_post(self):
# Given/Arrange
correct_note = Note.objects.create()
Item.objects.create(text="itemey 1", note=correct_note)
Item.objects.create(text="itemey 2", note=correct_note)
other_note = Note.objects.create()
Item.objects.create(text="other note item", note=other_note)
correct_post = Post.objects.create()
Line.objects.create(text="itemey 1", post=correct_post)
Line.objects.create(text="itemey 2", post=correct_post)
other_post = Post.objects.create()
Line.objects.create(text="other post line", post=other_post)
# When/Act
response = self.client.get(f"/dashboard/note/{correct_note.id}/")
response = self.client.get(f"/dashboard/post/{correct_post.id}/")
# Then/Assert
self.assertContains(response, "itemey 1")
self.assertContains(response, "itemey 2")
self.assertNotContains(response, "other note item")
self.assertNotContains(response, "other post line")
def test_can_save_a_POST_request_to_an_existing_note(self):
other_note = Note.objects.create()
correct_note = Note.objects.create()
def test_can_save_a_POST_request_to_an_existing_post(self):
other_post = Post.objects.create()
correct_post = Post.objects.create()
self.client.post(
f"/dashboard/note/{correct_note.id}/",
data={"text": "A new item for an existing note"},
f"/dashboard/post/{correct_post.id}/",
data={"text": "A new line for an existing post"},
)
self.assertEqual(Item.objects.count(), 1)
new_item = Item.objects.get()
self.assertEqual(new_item.text, "A new item for an existing note")
self.assertEqual(new_item.note, correct_note)
self.assertEqual(Line.objects.count(), 1)
new_line = Line.objects.get()
self.assertEqual(new_line.text, "A new line for an existing post")
self.assertEqual(new_line.post, correct_post)
def test_POST_redirects_to_note_view(self):
other_note = Note.objects.create()
correct_note = Note.objects.create()
def test_POST_redirects_to_post_view(self):
other_post = Post.objects.create()
correct_post = Post.objects.create()
response = self.client.post(
f"/dashboard/note/{correct_note.id}/",
data={"text": "A new item for an existing note"},
f"/dashboard/post/{correct_post.id}/",
data={"text": "A new line for an existing post"},
)
self.assertRedirects(response, f"/dashboard/note/{correct_note.id}/")
self.assertRedirects(response, f"/dashboard/post/{correct_post.id}/")
# Post invalid input helper
def post_invalid_input(self):
mynote = Note.objects.create()
return self.client.post(f"/dashboard/note/{mynote.id}/", data={"text": ""})
mypost = Post.objects.create()
return self.client.post(f"/dashboard/post/{mypost.id}/", data={"text": ""})
def test_for_invalid_input_nothing_saved_to_db(self):
self.post_invalid_input()
self.assertEqual(Item.objects.count(), 0)
self.assertEqual(Line.objects.count(), 0)
def test_for_invalid_input_renders_note_template(self):
def test_for_invalid_input_renders_post_template(self):
response = self.post_invalid_input()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "apps/dashboard/note.html")
self.assertTemplateUsed(response, "apps/dashboard/post.html")
def test_for_invalid_input_shows_error_on_page(self):
response = self.post_invalid_input()
self.assertContains(response, html.escape(EMPTY_ITEM_ERROR))
self.assertContains(response, html.escape(EMPTY_LINE_ERROR))
def test_for_invalid_input_sets_is_invalid_class(self):
response = self.post_invalid_input()
@@ -150,26 +145,26 @@ class NoteViewTest(TestCase):
[input] = parsed.cssselect("input[name=text]")
self.assertIn("is-invalid", set(input.classes))
def test_duplicate_item_validation_errors_end_up_on_note_page(self):
note1 = Note.objects.create()
Item.objects.create(note=note1, text="lorem ipsum")
def test_duplicate_line_validation_errors_end_up_on_post_page(self):
post1 = Post.objects.create()
Line.objects.create(post=post1, text="lorem ipsum")
response = self.client.post(
f"/dashboard/note/{note1.id}/",
f"/dashboard/post/{post1.id}/",
data={"text": "lorem ipsum"},
)
expected_error = html.escape(DUPLICATE_ITEM_ERROR)
expected_error = html.escape(DUPLICATE_LINE_ERROR)
self.assertContains(response, expected_error)
self.assertTemplateUsed(response, "apps/dashboard/note.html")
self.assertEqual(Item.objects.all().count(), 1)
self.assertTemplateUsed(response, "apps/dashboard/post.html")
self.assertEqual(Line.objects.all().count(), 1)
class MyNotesTest(TestCase):
def test_my_notes_url_renders_my_notes_template(self):
class MyPostsTest(TestCase):
def test_my_posts_url_renders_my_posts_template(self):
user = User.objects.create(email="a@b.cde")
self.client.force_login(user)
response = self.client.get(f"/dashboard/users/{user.id}/")
self.assertTemplateUsed(response, "apps/dashboard/my_notes.html")
self.assertTemplateUsed(response, "apps/dashboard/my_posts.html")
def test_passes_correct_owner_to_template(self):
User.objects.create(email="wrongowner@example.com")
@@ -178,71 +173,69 @@ class MyNotesTest(TestCase):
response = self.client.get(f"/dashboard/users/{correct_user.id}/")
self.assertEqual(response.context["owner"], correct_user)
def test_note_owner_is_saved_if_user_is_authenticated(self):
def test_post_owner_is_saved_if_user_is_authenticated(self):
user = User.objects.create(email="a@b.cde")
self.client.force_login(user)
self.client.post("/dashboard/new_note", data={"text": "new item"})
new_note = Note.objects.get()
self.assertEqual(new_note.owner, user)
self.client.post("/dashboard/new_post", data={"text": "new line"})
new_post = Post.objects.get()
self.assertEqual(new_post.owner, user)
def test_my_notes_redirects_if_not_logged_in(self):
user = User.objects.create(email="a@b.cde")
def test_my_posts_redirects_if_not_logged_in(self):
user = User.objects.create(email="a@b.cde")
response = self.client.get(f"/dashboard/users/{user.id}/")
self.assertRedirects(response, "/")
def test_my_notes_returns_403_for_wrong_user(self):
# create two users, login as user_a, request user_b's my_notes url
def test_my_posts_returns_403_for_wrong_user(self):
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"/dashboard/users/{user1.id}/")
# assert 403
self.assertEqual(response.status_code, 403)
class ShareNoteTest(TestCase):
def test_post_to_share_note_url_redirects_to_note(self):
our_note = Note.objects.create()
class SharePostTest(TestCase):
def test_post_to_share_post_url_redirects_to_post(self):
our_post = Post.objects.create()
alice = User.objects.create(email="alice@example.com")
response = self.client.post(
f"/dashboard/note/{our_note.id}/share_note",
f"/dashboard/post/{our_post.id}/share_post",
data={"recipient": "alice@example.com"},
)
self.assertRedirects(response, f"/dashboard/note/{our_note.id}/")
self.assertRedirects(response, f"/dashboard/post/{our_post.id}/")
def test_post_with_email_adds_user_to_shared_with(self):
our_note = Note.objects.create()
our_post = Post.objects.create()
alice = User.objects.create(email="alice@example.com")
self.client.post(
f"/dashboard/note/{our_note.id}/share_note",
f"/dashboard/post/{our_post.id}/share_post",
data={"recipient": "alice@example.com"},
)
self.assertIn(alice, our_note.shared_with.all())
self.assertIn(alice, our_post.shared_with.all())
def test_post_with_nonexistent_email_redirects_to_note(self):
our_note = Note.objects.create()
def test_post_with_nonexistent_email_redirects_to_post(self):
our_post = Post.objects.create()
response = self.client.post(
f"/dashboard/note/{our_note.id}/share_note",
f"/dashboard/post/{our_post.id}/share_post",
data={"recipient": "nobody@example.com"},
)
self.assertRedirects(
response,
f"/dashboard/note/{our_note.id}/",
f"/dashboard/post/{our_post.id}/",
fetch_redirect_response=False,
)
def test_share_note_does_not_add_owner_as_recipient(self):
def test_share_post_does_not_add_owner_as_recipient(self):
owner = User.objects.create(email="owner@example.com")
our_note = Note.objects.create(owner=owner)
our_post = Post.objects.create(owner=owner)
self.client.force_login(owner)
self.client.post(reverse("share_note", args=[our_note.id]),
self.client.post(reverse("share_post", args=[our_post.id]),
data={"recipient": "owner@example.com"})
self.assertNotIn(owner, our_note.shared_with.all())
self.assertNotIn(owner, our_post.shared_with.all())
@override_settings(MESSAGE_STORAGE='django.contrib.messages.storage.session.SessionStorage')
def test_share_note_shows_privacy_safe_message(self):
our_note = Note.objects.create()
def test_share_post_shows_privacy_safe_message(self):
our_post = Post.objects.create()
response = self.client.post(
f"/dashboard/note/{our_note.id}/share_note",
f"/dashboard/post/{our_post.id}/share_post",
data={"recipient": "nobody@example.com"},
follow=True,
)
@@ -252,26 +245,26 @@ class ShareNoteTest(TestCase):
"An invite has been sent if that address is registered.",
)
class ViewAuthNoteTest(TestCase):
class ViewAuthPostTest(TestCase):
def setUp(self):
self.owner = User.objects.create(email="disco@example.com")
self.our_note = Note.objects.create(owner=self.owner)
self.our_post = Post.objects.create(owner=self.owner)
def test_anonymous_user_is_redirected(self):
response = self.client.get(reverse("view_note", args=[self.our_note.id]))
response = self.client.get(reverse("view_post", args=[self.our_post.id]))
self.assertRedirects(response, "/", fetch_redirect_response=False)
def test_non_owner_non_shared_user_gets_403(self):
stranger = User.objects.create(email="stranger@example.com")
self.client.force_login(stranger)
response = self.client.get(reverse("view_note", args=[self.our_note.id]))
response = self.client.get(reverse("view_post", args=[self.our_post.id]))
self.assertEqual(response.status_code, 403)
def test_shared_with_user_can_access_note(self):
def test_shared_with_user_can_access_post(self):
guest = User.objects.create(email="guest@example.com")
self.our_note.shared_with.add(guest)
self.our_post.shared_with.add(guest)
self.client.force_login(guest)
response = self.client.get(reverse("view_note", args=[self.our_note.id]))
response = self.client.get(reverse("view_post", args=[self.our_post.id]))
self.assertEqual(response.status_code, 200)
@override_settings(COMPRESS_ENABLED=False)
@@ -349,14 +342,14 @@ class SetPaletteTest(TestCase):
swatches = parsed.cssselect(".swatch")
self.assertEqual(len(swatches), len(response.context["palettes"]))
class RecognitionPaletteContextTest(TestCase):
class NotePaletteContextTest(TestCase):
def setUp(self):
self.user = User.objects.create(email="recog_palette@test.io")
self.client.force_login(self.user)
Applet.objects.get_or_create(slug="palette", defaults={"name": "Palette"})
def test_recognition_palette_unlocks_swatch_in_context(self):
Recognition.objects.create(
def test_note_palette_unlocks_swatch_in_context(self):
Note.objects.create(
user=self.user, slug="stargazer", earned_at=timezone.now(),
palette="palette-bardo",
)
@@ -365,8 +358,8 @@ class RecognitionPaletteContextTest(TestCase):
bardo = next(p for p in palettes if p["name"] == "palette-bardo")
self.assertFalse(bardo["locked"])
def test_recognition_palette_shoptalk_contains_recognition_title(self):
Recognition.objects.create(
def test_note_palette_shoptalk_contains_note_title(self):
Note.objects.create(
user=self.user, slug="stargazer", earned_at=timezone.now(),
palette="palette-bardo",
)
@@ -375,8 +368,8 @@ class RecognitionPaletteContextTest(TestCase):
bardo = next(p for p in palettes if p["name"] == "palette-bardo")
self.assertIn("Stargazer", bardo["shoptalk"])
def test_recognition_without_palette_field_keeps_swatch_locked(self):
Recognition.objects.create(
def test_note_without_palette_field_keeps_swatch_locked(self):
Note.objects.create(
user=self.user, slug="stargazer", earned_at=timezone.now(),
palette=None,
)
@@ -385,8 +378,8 @@ class RecognitionPaletteContextTest(TestCase):
bardo = next(p for p in palettes if p["name"] == "palette-bardo")
self.assertTrue(bardo["locked"])
def test_recognition_palette_allows_set_palette_via_view(self):
Recognition.objects.create(
def test_note_palette_allows_set_palette_via_view(self):
Note.objects.create(
user=self.user, slug="stargazer", earned_at=timezone.now(),
palette="palette-bardo",
)