2010-10-11 17:41:44 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
2011-10-13 18:04:12 +00:00
|
|
|
from .models import Person
|
2010-10-11 17:41:44 +00: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 10:29:58 +00:00
|
|
|
self.assertQuerySetEqual(
|
2010-10-11 17:41:44 +00:00
|
|
|
Person.objects.all(),
|
|
|
|
[
|
|
|
|
"John Smith",
|
|
|
|
],
|
2016-12-29 15:27:49 +00:00
|
|
|
str,
|
2010-10-11 17:41:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
p.delete()
|
|
|
|
self.assertEqual(
|
|
|
|
p.data,
|
|
|
|
[
|
|
|
|
"Before save",
|
|
|
|
"After save",
|
|
|
|
"Before deletion",
|
|
|
|
"After deletion",
|
|
|
|
],
|
|
|
|
)
|
2022-09-24 10:29:58 +00:00
|
|
|
self.assertQuerySetEqual(Person.objects.all(), [])
|