- 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>
71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
from django.core.exceptions import ValidationError
|
|
from django.db.utils import IntegrityError
|
|
from django.test import TestCase
|
|
|
|
from apps.dashboard.models import Line, Post
|
|
from apps.lyric.models import User
|
|
|
|
|
|
class LineModelTest(TestCase):
|
|
def test_line_is_related_to_post(self):
|
|
mypost = Post.objects.create()
|
|
line = Line()
|
|
line.post = mypost
|
|
line.save()
|
|
self.assertIn(line, mypost.lines.all())
|
|
|
|
def test_cannot_save_null_post_lines(self):
|
|
mypost = Post.objects.create()
|
|
line = Line(post=mypost, text=None)
|
|
with self.assertRaises(IntegrityError):
|
|
line.save()
|
|
|
|
def test_cannot_save_empty_post_lines(self):
|
|
mypost = Post.objects.create()
|
|
line = Line(post=mypost, text="")
|
|
with self.assertRaises(ValidationError):
|
|
line.full_clean()
|
|
|
|
def test_duplicate_lines_are_invalid(self):
|
|
mypost = Post.objects.create()
|
|
Line.objects.create(post=mypost, text="jklol")
|
|
with self.assertRaises(ValidationError):
|
|
line = Line(post=mypost, text="jklol")
|
|
line.full_clean()
|
|
|
|
def test_still_can_save_same_line_to_different_posts(self):
|
|
post1 = Post.objects.create()
|
|
post2 = Post.objects.create()
|
|
Line.objects.create(post=post1, text="nojk")
|
|
line = Line(post=post2, text="nojk")
|
|
line.full_clean() # should not raise
|
|
|
|
class PostModelTest(TestCase):
|
|
def test_get_absolute_url(self):
|
|
mypost = Post.objects.create()
|
|
self.assertEqual(mypost.get_absolute_url(), f"/dashboard/post/{mypost.id}/")
|
|
|
|
def test_post_lines_order(self):
|
|
post1 = Post.objects.create()
|
|
line1 = Line.objects.create(post=post1, text="i1")
|
|
line2 = Line.objects.create(post=post1, text="line 2")
|
|
line3 = Line.objects.create(post=post1, text="3")
|
|
self.assertEqual(
|
|
list(post1.lines.all()),
|
|
[line1, line2, line3],
|
|
)
|
|
|
|
def test_posts_can_have_owners(self):
|
|
user = User.objects.create(email="a@b.cde")
|
|
mypost = Post.objects.create(owner=user)
|
|
self.assertIn(mypost, user.posts.all())
|
|
|
|
def test_post_owner_is_optional(self):
|
|
Post.objects.create()
|
|
|
|
def test_post_name_is_first_line_text(self):
|
|
post = Post.objects.create()
|
|
Line.objects.create(post=post, text="first line")
|
|
Line.objects.create(post=post, text="second line")
|
|
self.assertEqual(post.name, "first line")
|