2010-10-11 19:41:44 +02:00
|
|
|
from django.test import TestCase
|
|
|
|
|
2011-10-13 20:04:12 +02:00
|
|
|
from .models import Person
|
2010-10-11 19:41:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
class SaveDeleteHookTests(TestCase):
|
|
|
|
def test_basic(self):
|
|
|
|
p = Person(first_name="John", last_name="Smith")
|
|
|
|
self.assertEqual(p.data, [])
|
|
|
|
p.save()
|
|
|
|
self.assertEqual(
|
|
|
|
p.data,
|
|
|
|
[
|
|
|
|
"Before save",
|
|
|
|
"After save",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2022-09-24 12:29:58 +02:00
|
|
|
self.assertQuerySetEqual(
|
2010-10-11 19:41:44 +02:00
|
|
|
Person.objects.all(),
|
|
|
|
[
|
|
|
|
"John Smith",
|
|
|
|
],
|
2016-12-29 16:27:49 +01:00
|
|
|
str,
|
2010-10-11 19:41:44 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
p.delete()
|
|
|
|
self.assertEqual(
|
|
|
|
p.data,
|
|
|
|
[
|
|
|
|
"Before save",
|
|
|
|
"After save",
|
|
|
|
"Before deletion",
|
|
|
|
"After deletion",
|
|
|
|
],
|
|
|
|
)
|
2022-09-24 12:29:58 +02:00
|
|
|
self.assertQuerySetEqual(Person.objects.all(), [])
|