def test_report_fails_if_error(self): with patch('instructor_task.tasks_helper.collect_email_ora2_data') as mock_collect_data: mock_collect_data.side_effect = KeyError with patch('instructor_task.tasks_helper._get_current_task') as mock_current_task: mock_current_task.return_value = self.current_task self.assertEqual(push_ora2_responses_to_s3(None, None, self.course.id, {'include_email': 'True'}, 'generated'), UPDATE_STATUS_FAILED)
def test_report_stores_results(self, mock_time): start_time = datetime.now(UTC) mock_time.now.return_value = start_time test_header = ['field1', 'field2'] test_rows = [['row1_field1', 'row1_field2'], ['row2_field1', 'row2_field2']] with patch('instructor_task.tasks_helper._get_current_task') as mock_current_task: mock_current_task.return_value = self.current_task with patch('instructor_task.tasks_helper.collect_email_ora2_data') as mock_collect_data: mock_collect_data.return_value = (test_header, test_rows) with patch('instructor_task.models.LocalFSReportStore.store_rows') as mock_store_rows: timestamp_str = start_time.strftime('%Y-%m-%d-%H%M') course_id_string = urllib.quote(self.course.id.to_deprecated_string().replace('/', '_')) filename = u'{}_ORA2_responses_including_email_{}.csv'.format(course_id_string, timestamp_str) return_val = push_ora2_responses_to_s3(None, None, self.course.id, {'include_email': 'True'}, 'generated') self.assertEqual(return_val, UPDATE_STATUS_SUCCEEDED) mock_store_rows.assert_called_once_with(self.course.id, filename, [test_header] + test_rows)