2013-07-30 01:19:04 +08:00
|
|
|
from __future__ import unicode_literals
|
2011-10-14 02:04:12 +08:00
|
|
|
|
2010-10-12 01:41:44 +08:00
|
|
|
from django.test import TestCase
|
2012-07-20 20:48:51 +08:00
|
|
|
from django.utils import six
|
2010-10-12 01:41:44 +08:00
|
|
|
|
2011-10-14 02:04:12 +08:00
|
|
|
from .models import Person
|
2010-10-12 01:41:44 +08: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 20:48:51 +08:00
|
|
|
six.text_type
|
2010-10-12 01:41:44 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
p.delete()
|
|
|
|
self.assertEqual(p.data, [
|
|
|
|
"Before save",
|
|
|
|
"After save",
|
|
|
|
"Before deletion",
|
|
|
|
"After deletion",
|
|
|
|
])
|
|
|
|
self.assertQuerysetEqual(Person.objects.all(), [])
|