#NEWLINE# def test_generic_hook( self ) : #NEWLINE# #INDENT# 'Testing that a generic e-mail hook works for all e-mail signals' #NEWLINE# hook = EmailHook ( self . extension , signals = [ review_request_published , review_published , reply_published , review_request_closed ] ) #NEWLINE# self . spy_on ( hook . get_to_field ) #NEWLINE# self . spy_on ( hook . get_cc_field ) #NEWLINE# review_request = self . create_review_request ( public = True ) #NEWLINE# review = self . create_review ( review_request ) #NEWLINE# reply = self . create_reply ( review ) #NEWLINE# siteconfig_settings = { #NEWLINE# #INDENT# 'mail_send_review_mail' : True , #NEWLINE# 'mail_send_review_close_mail' : True , #NEWLINE# #UNINDENT# } #NEWLINE# with set_siteconfig_settings ( siteconfig_settings ) : #NEWLINE# #INDENT# self . assertEqual ( len ( mail . outbox ) , 0 ) #NEWLINE# review . publish ( ) #NEWLINE# call_kwargs = { #NEWLINE# #INDENT# 'user' : review . user , #NEWLINE# 'review' : review , #NEWLINE# 'review_request' : review_request , #NEWLINE# #UNINDENT# } #NEWLINE# self . assertEqual ( len ( mail . outbox ) , 1 ) #NEWLINE# self . assertEqual ( len ( hook . get_to_field . spy . calls ) , 1 ) #NEWLINE# self . assertEqual ( len ( hook . get_cc_field . spy . calls ) , 1 ) #NEWLINE# self . assertEqual ( hook . get_to_field . spy . calls [ ( - 1 ) ] . kwargs , call_kwargs ) #NEWLINE# self . assertEqual ( hook . get_cc_field . spy . calls [ ( - 1 ) ] . kwargs , call_kwargs ) #NEWLINE# reply . publish ( reply . user ) #NEWLINE# call_kwargs [ 'reply' ] = reply #NEWLINE# call_kwargs [ 'user' ] = reply . user #NEWLINE# self . assertEqual ( len ( mail . outbox ) , 2 ) #NEWLINE# self . assertEqual ( len ( hook . get_to_field . spy . calls ) , 2 ) #NEWLINE# self . assertEqual ( len ( hook . get_cc_field . spy . calls ) , 2 ) #NEWLINE# self . assertEqual ( hook . get_to_field . spy . calls [ ( - 1 ) ] . kwargs , call_kwargs ) #NEWLINE# self . assertEqual ( hook . get_cc_field . spy . calls [ ( - 1 ) ] . kwargs , call_kwargs ) #NEWLINE# review_request . close ( ReviewRequest . DISCARDED ) #NEWLINE# call_kwargs = { #NEWLINE# #INDENT# 'review_request' : review_request , #NEWLINE# 'user' : review_request . submitter , #NEWLINE# 'close_type' : ReviewRequest . DISCARDED , #NEWLINE# #UNINDENT# } #NEWLINE# self . assertEqual ( len ( mail . outbox ) , 3 ) #NEWLINE# self . assertEqual ( len ( hook . get_to_field . spy . calls ) , 3 ) #NEWLINE# self . assertEqual ( len ( hook . get_cc_field . spy . calls ) , 3 ) #NEWLINE# self . assertEqual ( hook . get_to_field . spy . calls [ ( - 1 ) ] . kwargs , call_kwargs ) #NEWLINE# self . assertEqual ( hook . get_cc_field . spy . calls [ ( - 1 ) ] . kwargs , call_kwargs ) #NEWLINE# review_request . reopen ( ) #NEWLINE# review_request . publish ( review_request . submitter ) #NEWLINE# call_kwargs = { #NEWLINE# #INDENT# 'review_request' : review_request , #NEWLINE# 'user' : review_request . submitter , #NEWLINE# #UNINDENT# } #NEWLINE# self . assertEqual ( len ( mail . outbox ) , 4 ) #NEWLINE# self . assertEqual ( len ( hook . get_to_field . spy . calls ) , 4 ) #NEWLINE# self . assertEqual ( len ( hook . get_cc_field . spy . calls ) , 4 ) #NEWLINE# self . assertEqual ( hook . get_to_field . spy . calls [ ( - 1 ) ] . kwargs , call_kwargs ) #NEWLINE# self . assertEqual ( hook . get_cc_field . spy . calls [ ( - 1 ) ] . kwargs , call_kwargs ) #NEWLINE# review_request . close ( ReviewRequest . SUBMITTED ) #NEWLINE# call_kwargs [ 'close_type' ] = ReviewRequest . SUBMITTED #NEWLINE# self . assertEqual ( len ( mail . outbox ) , 5 ) #NEWLINE# self . assertEqual ( len ( hook . get_to_field . spy . calls ) , 5 ) #NEWLINE# self . assertEqual ( len ( hook . get_cc_field . spy . calls ) , 5 ) #NEWLINE# self . assertEqual ( hook . get_to_field . spy . calls [ ( - 1 ) ] . kwargs , call_kwargs ) #NEWLINE# self . assertEqual ( hook . get_cc_field . spy . calls [ ( - 1 ) ] . kwargs , call_kwargs )