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()
|
2022-02-03 19:24:19 +00:00
|
|
|
self.assertEqual(
|
|
|
|
p.data,
|
|
|
|
[
|
|
|
|
"Before save",
|
|
|
|
"After save",
|
|
|
|
],
|
|
|
|
)
|
2010-10-11 17:41:44 +00:00
|
|
|
|
2022-09-24 10:29:58 +00:00
|
|
|
self.assertQuerySetEqual(
|
2022-02-03 19:24:19 +00:00
|
|
|
Person.objects.all(),
|
|
|
|
[
|
2010-10-11 17:41:44 +00:00
|
|
|
"John Smith",
|
|
|
|
],
|
2022-02-03 19:24:19 +00:00
|
|
|
str,
|
2010-10-11 17:41:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
p.delete()
|
2022-02-03 19:24:19 +00:00
|
|
|
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(), [])
|