2026-01-19 16:35:00 -05:00
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
|
from django.db.utils import IntegrityError
|
2026-01-14 13:56:21 -05:00
|
|
|
from django.test import TestCase
|
|
|
|
|
from ..models import Item, List
|
|
|
|
|
|
2026-01-23 21:50:49 -05:00
|
|
|
class ItemModelsTest(TestCase):
|
|
|
|
|
def test_default_text(self):
|
|
|
|
|
item = Item()
|
|
|
|
|
self.assertEqual(item.text, "")
|
|
|
|
|
|
|
|
|
|
def test_item_is_related_to_list(self):
|
|
|
|
|
mylist = List.objects.create()
|
|
|
|
|
item = Item()
|
|
|
|
|
item.list = mylist
|
|
|
|
|
item.save()
|
|
|
|
|
self.assertIn(item, mylist.item_set.all())
|
2026-01-19 16:35:00 -05:00
|
|
|
|
|
|
|
|
def test_cannot_save_null_list_items(self):
|
|
|
|
|
mylist = List.objects.create()
|
|
|
|
|
item = Item(list=mylist, 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="")
|
|
|
|
|
with self.assertRaises(ValidationError):
|
|
|
|
|
item.full_clean()
|
2026-01-19 19:25:04 -05:00
|
|
|
|
2026-01-21 15:29:47 -05:00
|
|
|
def test_duplicate_items_are_invalid(self):
|
|
|
|
|
mylist = List.objects.create()
|
|
|
|
|
Item.objects.create(list=mylist, text="jklol")
|
|
|
|
|
with self.assertRaises(ValidationError):
|
|
|
|
|
item = Item(list=mylist, 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")
|
|
|
|
|
item.full_clean() # should not raise
|
2026-01-23 21:50:49 -05:00
|
|
|
|
|
|
|
|
class ListModelTest(TestCase):
|
|
|
|
|
def test_get_absolute_url(self):
|
|
|
|
|
mylist = List.objects.create()
|
|
|
|
|
self.assertEqual(mylist.get_absolute_url(), f"/apps/dashboard/{mylist.id}/")
|