<s> from __future__ import absolute_import <EOL> from django . db import models <EOL> from django . test import TestCase <EOL> from . models import Author , Book <EOL> signal_output = [ ] <EOL> def pre_save_test ( signal , sender , instance , ** kwargs ) : <EOL> signal_output . append ( '<STR_LIT>' % instance ) <EOL> if kwargs . get ( '<STR_LIT>' ) : <EOL> signal_output . append ( '<STR_LIT>' ) <EOL> def post_save_test ( signal , sender , instance , ** kwargs ) : <EOL> signal_output . append ( '<STR_LIT>' % instance ) <EOL> if '<STR_LIT>' in kwargs : <EOL> if kwargs [ '<STR_LIT>' ] : <EOL> signal_output . append ( '<STR_LIT>' ) <EOL> else : <EOL> signal_output . append ( '<STR_LIT>' ) <EOL> if kwargs . get ( '<STR_LIT>' ) : <EOL> signal_output . append ( '<STR_LIT>' ) <EOL> def pre_delete_test ( signal , sender , instance , ** kwargs ) : <EOL> signal_output . append ( '<STR_LIT>' % instance ) <EOL> signal_output . append ( '<STR_LIT>' % ( instance . id != None ) ) <EOL> def post_delete_test ( signal , sender , instance , ** kwargs ) : <EOL> signal_output . append ( '<STR_LIT>' % instance ) <EOL> signal_output . append ( '<STR_LIT>' % ( instance . id != None ) ) <EOL> class SignalsRegressTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def get_signal_output ( self , fn , * args , ** kwargs ) : <EOL> global signal_output <EOL> signal_output = [ ] <EOL> fn ( * args , ** kwargs ) <EOL> return signal_output <EOL> def setUp ( self ) : <EOL> self . pre_signals = ( len ( models . signals . pre_save . receivers ) , <EOL> len ( models . signals . post_save . receivers ) , <EOL> len ( models . signals . pre_delete . receivers ) , <EOL> len ( models . signals . post_delete . receivers ) ) <EOL> models . signals . pre_save . connect ( pre_save_test ) <EOL> models . signals . post_save . connect ( post_save_test ) <EOL> models . signals . pre_delete . connect ( pre_delete_test ) <EOL> models . signals . post_delete . connect ( post_delete_test ) <EOL> def tearDown ( self ) : <EOL> models . signals . post_delete . disconnect ( post_delete_test ) <EOL> models . signals . pre_delete . disconnect ( pre_delete_test ) <EOL> models . signals . post_save . disconnect ( post_save_test ) <EOL> models . signals . pre_save . disconnect ( pre_save_test ) <EOL> post_signals = ( len ( models . signals . pre_save . receivers ) , <EOL> len ( models . signals . post_save . receivers ) , <EOL> len ( models . signals . pre_delete . receivers ) , <EOL> len ( models . signals . post_delete . receivers ) ) <EOL> self . assertEqual ( self . pre_signals , post_signals ) <EOL> def test_model_signals ( self ) : <EOL> """<STR_LIT>""" <EOL> a1 = Author ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( self . get_signal_output ( a1 . save ) , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] ) <EOL> b1 = Book ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( self . get_signal_output ( b1 . save ) , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] ) <EOL> def test_m2m_signals ( self ) : <EOL> """<STR_LIT>""" <EOL> b1 = Book ( name = '<STR_LIT>' ) <EOL> self . get_signal_output ( b1 . save ) <EOL> a1 = Author ( name = '<STR_LIT>' ) <EOL> self . get_signal_output ( a1 . save ) <EOL> self . assertEqual ( self . get_signal_output ( setattr , b1 , '<STR_LIT>' , [ a1 ] ) , [ ] ) <EOL> self . assertEqual ( self . get_signal_output ( setattr , b1 , '<STR_LIT>' , [ ] ) , [ ] ) </s>
