def setup_exporter(app): """Setup exporter.""" global csv_exporter global json_exporter from pybossa.exporter.csv_export import CsvExporter from pybossa.exporter.json_export import JsonExporter csv_exporter = CsvExporter() json_exporter = JsonExporter()
def setup_exporter(app): """Setup exporter.""" global csv_exporter global task_csv_exporter global json_exporter global task_json_exporter global project_csv_exporter from pybossa.exporter.csv_export import CsvExporter from pybossa.exporter.task_csv_export import TaskCsvExporter from pybossa.exporter.json_export import JsonExporter from pybossa.exporter.task_json_export import TaskJsonExporter from pybossa.exporter.project_csv_export import ProjectCsvExporter csv_exporter = CsvExporter() task_csv_exporter = TaskCsvExporter() json_exporter = JsonExporter() task_json_exporter = TaskJsonExporter() project_csv_exporter = ProjectCsvExporter()
def test_exporters_generates_zip(self, json_uploader, csv_uploader): """Test that CsvExporter and JsonExporter generate zip works.""" user = UserFactory.create(admin=True) project = ProjectFactory.create(name='test_project') task = TaskFactory.create(project=project) task_run = TaskRunFactory.create(project=project, task=task) csv_exporter = CsvExporter() json_exporter = JsonExporter() csv_exporter.pregenerate_zip_files(project) call_csv_params = csv_uploader.upload_file.call_args_list expected_csv_params = set(['1_project1_task_run_csv.zip', '1_project1_result_csv.zip', '1_project1_task_csv.zip']) assert self._check_func_called_with_params(call_csv_params, expected_csv_params) json_exporter.pregenerate_zip_files(project) call_json_params = json_uploader.upload_file.call_args_list expected_json_params = set(['1_project1_task_run_json.zip', '1_project1_result_json.zip', '1_project1_task_json.zip']) assert self._check_func_called_with_params(call_json_params, expected_json_params)
def test_exporters_generates_zip(self, json_uploader, csv_uploader, dataframe): """Test that CsvExporter and JsonExporter generate zip works.""" user = UserFactory.create(admin=True) project = ProjectFactory.create(name='test_project') expected_gold_answer = { 'best_job': 'software developer', 'best_boss': 'Juan' } task1 = TaskFactory.create(project=project, gold_answers=expected_gold_answer) task2 = TaskFactory.create(project=project) task_run = TaskRunFactory.create(project=project, task=task1) task_run = TaskRunFactory.create(project=project, task=task2) csv_exporter = CsvExporter() json_exporter = JsonExporter() csv_exporter.pregenerate_zip_files(project) call_dataframe = dataframe.call_args_list call_csv_params = csv_uploader.upload_file.call_args_list expected_csv_params = set([ '1_project1_task_run_csv.zip', '1_project1_result_csv.zip', '1_project1_task_csv.zip' ]) assert self._check_func_called_with_params(call_csv_params, expected_csv_params) task1_data = call_dataframe[0][0][0][0] task2_data = call_dataframe[0][0][0][1] expected_headers = [ 'info', 'fav_user_ids', 'user_pref', 'n_answers', 'quorum', 'calibration', 'created', 'state', 'gold_answers_best_job', 'gold_answers_best_boss', 'exported', 'project_id', 'id', 'priority_0', 'expiration' ] obj_keys = task1_data.keys() self._compare_object_keys(obj_keys, expected_headers) assert task1_data['gold_answers_best_job'] == expected_gold_answer[ 'best_job'] assert task1_data['gold_answers_best_boss'] == expected_gold_answer[ 'best_boss'] expected_headers = [ 'info', 'fav_user_ids', 'user_pref', 'n_answers', 'quorum', 'calibration', 'created', 'state', 'gold_answers', 'exported', 'project_id', 'id', 'priority_0', 'expiration' ] obj_keys = task2_data.keys() self._compare_object_keys(obj_keys, expected_headers) assert task2_data['gold_answers'] == None json_exporter.pregenerate_zip_files(project) call_json_params = json_uploader.upload_file.call_args_list expected_json_params = set([ '1_project1_task_run_json.zip', '1_project1_result_json.zip', '1_project1_task_json.zip' ]) assert self._check_func_called_with_params(call_json_params, expected_json_params)