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