#NEWLINE# def test_error_cases_for_email_sending( self ) : #NEWLINE# #INDENT# with self . swap ( feconf , 'REQUIRE_EMAIL_ON_MODERATOR_ACTION' , True ) , self . swap ( feconf , 'CAN_SEND_EMAILS_TO_USERS' , False ) : #NEWLINE# #INDENT# self . login ( self . MODERATOR_EMAIL ) #NEWLINE# response = self . testapp . get ( ( '/create/%s' % self . EXP_ID ) ) #NEWLINE# self . assertEqual ( response . status_int , 200 ) #NEWLINE# csrf_token = self . get_csrf_token_from_response ( response ) #NEWLINE# response_dict = self . put_json ( ( '/createhandler/moderatorrights/%s' % self . EXP_ID ) , { #NEWLINE# #INDENT# 'action' : 'random_action' , #NEWLINE# 'email_body' : None , #NEWLINE# 'version' : 1 , #NEWLINE# #UNINDENT# } , csrf_token , expect_errors = True , expected_status_int = 400 ) #NEWLINE# self . assertEqual ( response_dict [ 'error' ] , 'Invalid moderator action.' ) #NEWLINE# response_dict = self . put_json ( ( '/createhandler/moderatorrights/%s' % self . EXP_ID ) , { #NEWLINE# #INDENT# 'action' : feconf . MODERATOR_ACTION_PUBLICIZE_EXPLORATION , #NEWLINE# 'email_body' : None , #NEWLINE# 'version' : 1 , #NEWLINE# #UNINDENT# } , csrf_token , expect_errors = True , expected_status_int = 400 ) #NEWLINE# self . assertIn ( 'Moderator actions should include an email' , response_dict [ 'error' ] ) #NEWLINE# response_dict = self . put_json ( ( '/createhandler/moderatorrights/%s' % self . EXP_ID ) , { #NEWLINE# #INDENT# 'action' : feconf . MODERATOR_ACTION_PUBLICIZE_EXPLORATION , #NEWLINE# 'email_body' : '' , #NEWLINE# 'version' : 1 , #NEWLINE# #UNINDENT# } , csrf_token , expect_errors = True , expected_status_int = 400 ) #NEWLINE# self . assertIn ( 'Moderator actions should include an email' , response_dict [ 'error' ] ) #NEWLINE# valid_payload = { #NEWLINE# #INDENT# 'action' : feconf . MODERATOR_ACTION_PUBLICIZE_EXPLORATION , #NEWLINE# 'email_body' : 'Your exploration is featured!' , #NEWLINE# 'version' : 1 , #NEWLINE# #UNINDENT# } #NEWLINE# self . put_json ( ( '/createhandler/moderatorrights/%s' % self . EXP_ID ) , valid_payload , csrf_token , expect_errors = True , expected_status_int = 500 ) #NEWLINE# with self . swap ( feconf , 'CAN_SEND_EMAILS_TO_USERS' , True ) : #NEWLINE# #INDENT# self . put_json ( ( '/createhandler/moderatorrights/%s' % self . EXP_ID ) , valid_payload , csrf_token ) #NEWLINE# #UNINDENT# self . logout ( )