renamed List to Note everywhere thru-out project in preparation for complete overhaul of applet capabilities
This commit is contained in:
@@ -2,69 +2,69 @@ from django.core.exceptions import ValidationError
|
||||
from django.db.utils import IntegrityError
|
||||
from django.test import TestCase
|
||||
|
||||
from apps.dashboard.models import Item, List
|
||||
from apps.dashboard.models import Item, Note
|
||||
from apps.lyric.models import User
|
||||
|
||||
|
||||
class ItemModelTest(TestCase):
|
||||
def test_item_is_related_to_list(self):
|
||||
mylist = List.objects.create()
|
||||
def test_item_is_related_to_note(self):
|
||||
mynote = Note.objects.create()
|
||||
item = Item()
|
||||
item.list = mylist
|
||||
item.note = mynote
|
||||
item.save()
|
||||
self.assertIn(item, mylist.item_set.all())
|
||||
self.assertIn(item, mynote.item_set.all())
|
||||
|
||||
def test_cannot_save_null_list_items(self):
|
||||
mylist = List.objects.create()
|
||||
item = Item(list=mylist, text=None)
|
||||
def test_cannot_save_null_note_items(self):
|
||||
mynote = Note.objects.create()
|
||||
item = Item(note=mynote, text=None)
|
||||
with self.assertRaises(IntegrityError):
|
||||
item.save()
|
||||
|
||||
def test_cannot_save_empty_list_items(self):
|
||||
mylist = List.objects.create()
|
||||
item = Item(list=mylist, text="")
|
||||
def test_cannot_save_empty_note_items(self):
|
||||
mynote = Note.objects.create()
|
||||
item = Item(note=mynote, text="")
|
||||
with self.assertRaises(ValidationError):
|
||||
item.full_clean()
|
||||
|
||||
def test_duplicate_items_are_invalid(self):
|
||||
mylist = List.objects.create()
|
||||
Item.objects.create(list=mylist, text="jklol")
|
||||
mynote = Note.objects.create()
|
||||
Item.objects.create(note=mynote, text="jklol")
|
||||
with self.assertRaises(ValidationError):
|
||||
item = Item(list=mylist, text="jklol")
|
||||
item = Item(note=mynote, text="jklol")
|
||||
item.full_clean()
|
||||
|
||||
def test_still_can_save_same_item_to_different_lists(self):
|
||||
list1 = List.objects.create()
|
||||
list2 = List.objects.create()
|
||||
Item.objects.create(list=list1, text="nojk")
|
||||
item = Item(list=list2, text="nojk")
|
||||
def test_still_can_save_same_item_to_different_notes(self):
|
||||
note1 = Note.objects.create()
|
||||
note2 = Note.objects.create()
|
||||
Item.objects.create(note=note1, text="nojk")
|
||||
item = Item(note=note2, text="nojk")
|
||||
item.full_clean() # should not raise
|
||||
|
||||
class ListModelTest(TestCase):
|
||||
class NoteModelTest(TestCase):
|
||||
def test_get_absolute_url(self):
|
||||
mylist = List.objects.create()
|
||||
self.assertEqual(mylist.get_absolute_url(), f"/dashboard/list/{mylist.id}/")
|
||||
mynote = Note.objects.create()
|
||||
self.assertEqual(mynote.get_absolute_url(), f"/dashboard/note/{mynote.id}/")
|
||||
|
||||
def test_list_items_order(self):
|
||||
list1 = List.objects.create()
|
||||
item1 = Item.objects.create(list=list1, text="i1")
|
||||
item2 = Item.objects.create(list=list1, text="item 2")
|
||||
item3 = Item.objects.create(list=list1, text="3")
|
||||
def test_note_items_order(self):
|
||||
note1 = Note.objects.create()
|
||||
item1 = Item.objects.create(note=note1, text="i1")
|
||||
item2 = Item.objects.create(note=note1, text="item 2")
|
||||
item3 = Item.objects.create(note=note1, text="3")
|
||||
self.assertEqual(
|
||||
list(list1.item_set.all()),
|
||||
list(note1.item_set.all()),
|
||||
[item1, item2, item3],
|
||||
)
|
||||
|
||||
def test_lists_can_have_owners(self):
|
||||
def test_notes_can_have_owners(self):
|
||||
user = User.objects.create(email="a@b.cde")
|
||||
mylist = List.objects.create(owner=user)
|
||||
self.assertIn(mylist, user.lists.all())
|
||||
mynote = Note.objects.create(owner=user)
|
||||
self.assertIn(mynote, user.notes.all())
|
||||
|
||||
def test_list_owner_is_optional(self):
|
||||
List.objects.create()
|
||||
def test_note_owner_is_optional(self):
|
||||
Note.objects.create()
|
||||
|
||||
def test_list_name_is_first_item_text(self):
|
||||
list_ = List.objects.create()
|
||||
Item.objects.create(list=list_, text="first item")
|
||||
Item.objects.create(list=list_, text="second item")
|
||||
self.assertEqual(list_.name, "first item")
|
||||
def test_note_name_is_first_item_text(self):
|
||||
note = Note.objects.create()
|
||||
Item.objects.create(note=note, text="first item")
|
||||
Item.objects.create(note=note, text="second item")
|
||||
self.assertEqual(note.name, "first item")
|
||||
|
||||
Reference in New Issue
Block a user