reorganized and reclassified old 'unit tests' for ea. app into dirs for UTs & ITs; abandoning effort to refactor any test_views into UTs; all tests passing
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
70
src/apps/dashboard/tests/integrated/test_models.py
Normal file
70
src/apps/dashboard/tests/integrated/test_models.py
Normal file
@@ -0,0 +1,70 @@
|
||||
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.lyric.models import User
|
||||
|
||||
|
||||
class ItemModelTest(TestCase):
|
||||
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())
|
||||
|
||||
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()
|
||||
|
||||
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
|
||||
|
||||
class ListModelTest(TestCase):
|
||||
def test_get_absolute_url(self):
|
||||
mylist = List.objects.create()
|
||||
self.assertEqual(mylist.get_absolute_url(), f"/apps/dashboard/{mylist.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")
|
||||
self.assertEqual(
|
||||
list(list1.item_set.all()),
|
||||
[item1, item2, item3],
|
||||
)
|
||||
|
||||
def test_lists_can_have_owners(self):
|
||||
user = User.objects.create(email="a@b.cde")
|
||||
mylist = List.objects.create(owner=user)
|
||||
self.assertIn(mylist, user.lists.all())
|
||||
|
||||
def test_list_owner_is_optional(self):
|
||||
List.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")
|
||||
Reference in New Issue
Block a user