def test_run_action_email_no_filter(self): """Run sequence of request to send email without filtering users.""" action = self.workflow.actions.get(name='Midterm comments') column = action.workflow.columns.get(name='email') # Step 1 invoke the form resp = self.get_response('action:run', url_params={'pk': action.id}) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(action.id == payload['action_id']) self.assertTrue(payload['prev_url'] == reverse( 'action:run', kwargs={'pk': action.id})) self.assertTrue(payload['post_url'] == reverse('action:run_done')) self.assertTrue('post_url' in payload.keys()) self.assertTrue(status.is_success(resp.status_code)) # Step 2 send POST resp = self.get_response('action:run', url_params={'pk': action.id}, method='POST', req_params={ 'cc_email': '[email protected] [email protected]', 'bcc_email': '[email protected] [email protected]', 'item_column': column.pk, 'subject': 'message subject' }) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(payload == {}) self.assertTrue(len(mail.outbox) == action.get_rows_selected()) self._verify_content() self.assertTrue(status.is_success(resp.status_code))
def test_run_json_report_action(self): """Test JSON action using the filter execution.""" OnTaskSharedState.json_outbox = None action = self.workflow.actions.get(name='Send JSON report') # Step 1 invoke the form resp = self.get_response('action:run', url_params={'pk': action.id}) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(action.id == payload['action_id']) self.assertTrue(payload['prev_url'] == reverse( 'action:run', kwargs={'pk': action.id})) self.assertTrue(payload['post_url'] == reverse('action:run_done')) self.assertTrue('post_url' in payload.keys()) self.assertTrue(status.is_success(resp.status_code)) # Step 2 send POST resp = self.get_response('action:run', url_params={'pk': action.id}, method='POST', req_params={'token': 'fake token'}) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(payload == {}) self.assertTrue(len(OnTaskSharedState.json_outbox) == 1) self.assertTrue( OnTaskSharedState.json_outbox[0]['auth'] == 'Bearer fake token') self.assertTrue(status.is_success(resp.status_code))
def test_run_json_action_no_filter(self): """Test JSON action using the filter execution.""" OnTaskSharedState.json_outbox = None action = self.workflow.actions.get(name='Send JSON to remote server') column = action.workflow.columns.get(name='email') # Step 1 invoke the form resp = self.get_response('action:run', url_params={'pk': action.id}) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(action.id == payload['action_id']) self.assertTrue(payload['prev_url'] == reverse( 'action:run', kwargs={'pk': action.id})) self.assertTrue(payload['post_url'] == reverse('action:run_done')) self.assertTrue('post_url' in payload.keys()) self.assertTrue(status.is_success(resp.status_code)) # Step 2 send POST resp = self.get_response('action:run', url_params={'pk': action.id}, method='POST', req_params={ 'item_column': column.pk, 'token': 'fake token' }) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(payload == {}) self.assertTrue( len(OnTaskSharedState.json_outbox) == action.get_rows_selected()) self._verify_content() self.assertTrue(status.is_success(resp.status_code))
def test_run_action_email_no_filter(self): """Run sequence of request to send email list .""" action = self.workflow.actions.get(name='Send Email with report') # Step 1 invoke the form resp = self.get_response('action:run', url_params={'pk': action.id}) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(action.id == payload['action_id']) self.assertTrue(payload['prev_url'] == reverse( 'action:run', kwargs={'pk': action.id})) self.assertTrue(payload['post_url'] == reverse('action:run_done')) self.assertTrue('post_url' in payload.keys()) self.assertTrue(status.is_success(resp.status_code)) # Step 2 send POST resp = self.get_response('action:run', url_params={'pk': action.id}, method='POST', req_params={ 'email_to': '*****@*****.**', 'cc_email': '[email protected] [email protected]', 'bcc_email': '[email protected] [email protected]', 'subject': 'Email to instructor' }) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(payload == {}) self.assertTrue(len(mail.outbox) == 1) self.assertTrue(status.is_success(resp.status_code))
def test_email_with_filter(self): """Run sequence of request to send email without filtering users.""" action = self.workflow.actions.get(name='Midterm comments') column = action.workflow.columns.get(name='email') exclude_values = ['*****@*****.**', '*****@*****.**'] # Step 1 invoke the form resp = self.get_response('action:run', url_params={'pk': action.id}) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(action.id == payload['action_id']) self.assertTrue(payload['prev_url'] == reverse( 'action:run', kwargs={'pk': action.id})) self.assertTrue(payload['post_url'] == reverse('action:run_done')) self.assertTrue('post_url' in payload.keys()) self.assertTrue(status.is_success(resp.status_code)) # Step 2 send POST resp = self.get_response('action:run', url_params={'pk': action.id}, method='POST', req_params={ 'item_column': column.pk, 'cc_email': '[email protected] [email protected]', 'bcc_email': '[email protected] [email protected]', 'confirm_items': True, 'subject': 'message subject' }) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(payload['confirm_items']) self.assertEqual(resp.status_code, status.HTTP_302_FOUND) # Load the Filter page with a GET resp = self.get_response('action:item_filter', session_payload=payload) self.assertTrue(status.is_success(resp.status_code)) # Emulate the filter page with a POST resp = self.get_response('action:item_filter', method='POST', req_params={'exclude_values': exclude_values}) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(payload['exclude_values'] == exclude_values) self.assertEqual(resp.status_code, status.HTTP_302_FOUND) self.assertEqual(resp.url, payload['post_url']) # Emulate the redirection to run_done resp = self.get_response('action:run_done') payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(payload == {}) self._verify_content() self.assertTrue( len(mail.outbox) == (action.get_rows_selected() - len(exclude_values))) self.assertTrue(status.is_success(resp.status_code))
def test_json_action_with_filter(self): """Test JSON action without using the filter execution.""" OnTaskSharedState.json_outbox = None action = self.workflow.actions.get(name='Send JSON to remote server') column = action.workflow.columns.get(name='email') exclude_values = ['*****@*****.**', '*****@*****.**'] # Step 1 invoke the form resp = self.get_response('action:run', url_params={'pk': action.id}) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(action.id == payload['action_id']) self.assertTrue(payload['prev_url'] == reverse( 'action:run', kwargs={'pk': action.id})) self.assertTrue(payload['post_url'] == reverse('action:run_done')) self.assertTrue('post_url' in payload.keys()) self.assertTrue(status.is_success(resp.status_code)) # Step 2 send POST resp = self.get_response('action:run', url_params={'pk': action.id}, method='POST', req_params={ 'item_column': column.pk, 'confirm_items': True, 'token': 'fake token' }) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(payload['confirm_items']) self.assertEqual(resp.status_code, status.HTTP_302_FOUND) # Load the Filter page with a GET resp = self.get_response('action:item_filter', session_payload=payload) self.assertTrue(status.is_success(resp.status_code)) # Emulate the filter page with a POST resp = self.get_response('action:item_filter', method='POST', req_params={'exclude_values': exclude_values}) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(payload['exclude_values'] == exclude_values) self.assertEqual(resp.status_code, status.HTTP_302_FOUND) self.assertEqual(resp.url, payload['post_url']) # Emulate the redirection to run_done resp = self.get_response('action:run_done') payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(payload == {}) self.assertTrue( len(OnTaskSharedState.json_outbox) == (action.get_rows_selected() - len(exclude_values))) self.assertTrue(status.is_success(resp.status_code))
def test_send_with_incorrect_email(self): """Test the do_import_action functionality.""" user = get_user_model().objects.get(email='*****@*****.**') wflow = models.Workflow.objects.get(name=self.workflow_name) email_column = wflow.columns.get(name='email') action = wflow.actions.first() # POST a send operation with the wrong email resp = self.get_response( 'action:run', url_params={'pk': action.id}, method='POST', req_params={ 'item_column': email_column.pk, 'subject': 'message subject'}) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(status.is_success(resp.status_code)) self.assertTrue( 'Incorrect email address ' in str(resp.content)) self.assertTrue( 'incorrectemail.com' in str(resp.content))