2010-10-11 17:41:44 +00:00
|
|
|
from django.test import TestCase
|
2012-07-20 12:48:51 +00:00
|
|
|
from django.utils import six
|
2010-10-11 17:41:44 +00:00
|
|
|
|
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",
|
|
|
|
])
|
|
|
|
|
|
|
|
self.assertQuerysetEqual(
|
|
|
|
Person.objects.all(), [
|
|
|
|
"John Smith",
|
|
|
|
],
|
2012-07-20 12:48:51 +00:00
|
|
|
six.text_type
|
2010-10-11 17:41:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
p.delete()
|
|
|
|
self.assertEqual(p.data, [
|
|
|
|
"Before save",
|
|
|
|
"After save",
|
|
|
|
"Before deletion",
|
|
|
|
"After deletion",
|
|
|
|
])
|
|
|
|
self.assertQuerysetEqual(Person.objects.all(), [])
|