From 71528fe43be6e5043f022c4c600bd1308b5a110f Mon Sep 17 00:00:00 2001 From: Zach Wolfenbarger Date: Wed, 22 May 2024 16:06:37 -0500 Subject: [PATCH] less flake8y --- panoptes_aggregation/batch_aggregation.py | 4 +++- .../tests/batch_aggregation/test_batch_aggregation.py | 11 ++++++----- .../tests/router_tests/test_routes.py | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/panoptes_aggregation/batch_aggregation.py b/panoptes_aggregation/batch_aggregation.py index 8db4e574..bf7f3c96 100644 --- a/panoptes_aggregation/batch_aggregation.py +++ b/panoptes_aggregation/batch_aggregation.py @@ -19,12 +19,13 @@ celery.conf.broker_url = os.environ.get("CELERY_BROKER_URL", "redis://localhost:6379") celery.conf.result_backend = os.environ.get("CELERY_RESULT_BACKEND", "redis://localhost:6379") + @celery.task(name="run_aggregation") def run_aggregation(project_id, workflow_id, user_id): ba = BatchAggregator(project_id, workflow_id, user_id) ba.save_exports() - wf_df = ba.process_wf_export(ba.wf_csv) + ba.process_wf_export(ba.wf_csv) cls_df = ba.process_cls_export(ba.cls_csv) extractor_config = workflow_extractor_config(ba.tasks) @@ -51,6 +52,7 @@ def run_aggregation(project_id, workflow_id, user_id): # hit up panoptes, let em know you're done + class BatchAggregator: """ Bunch of stuff to manage a batch aggregation run diff --git a/panoptes_aggregation/tests/batch_aggregation/test_batch_aggregation.py b/panoptes_aggregation/tests/batch_aggregation/test_batch_aggregation.py index 3e79914b..56ee9e08 100644 --- a/panoptes_aggregation/tests/batch_aggregation/test_batch_aggregation.py +++ b/panoptes_aggregation/tests/batch_aggregation/test_batch_aggregation.py @@ -1,11 +1,12 @@ import unittest -from unittest.mock import patch, Mock, MagicMock, call +from unittest.mock import patch, MagicMock, call from panoptes_aggregation.scripts import batch_utils from panoptes_aggregation.batch_aggregation import run_aggregation from panoptes_aggregation import batch_aggregation as batch_agg -wf_export = f'panoptes_aggregation/tests/batch_aggregation/wf_export.csv' -cls_export = f'panoptes_aggregation/tests/batch_aggregation/cls_export.csv' +wf_export = 'panoptes_aggregation/tests/batch_aggregation/wf_export.csv' +cls_export = 'panoptes_aggregation/tests/batch_aggregation/cls_export.csv' + @patch("panoptes_aggregation.batch_aggregation.BatchAggregator._connect_api_client", new=MagicMock()) class TestBatchAggregation(unittest.TestCase): @@ -16,7 +17,7 @@ def test_run_aggregation(self, mock_aggregator, mock_wf_ext_conf): mock_aggregator.process_cls_export.return_value = MagicMock() mock_df = MagicMock() - test_extracts = { 'question_extractor': mock_df } + test_extracts = {'question_extractor': mock_df} batch_utils.batch_extract = MagicMock(return_value=test_extracts) mock_reducer = MagicMock() batch_utils.batch_reduce = mock_reducer @@ -49,7 +50,7 @@ def test_run_aggregation(self, mock_aggregator, mock_wf_ext_conf): @patch("panoptes_aggregation.batch_aggregation.Panoptes.connect") def test_save_exports(self, mock_client, mock_project, mock_workflow, mock_mkdir): # Test that Panoptes calls are made and files are saved - csv_dict = {'media': [ {'src': 'http://zooniverse.org/123.csv'} ] } + csv_dict = {'media': [{'src': 'http://zooniverse.org/123.csv'}]} mock_project.return_value.describe_export.return_value = csv_dict mock_workflow.return_value.describe_export.return_value = csv_dict ba = batch_agg.BatchAggregator(1, 10, 100) diff --git a/panoptes_aggregation/tests/router_tests/test_routes.py b/panoptes_aggregation/tests/router_tests/test_routes.py index 5c81e2be..70db0aa5 100644 --- a/panoptes_aggregation/tests/router_tests/test_routes.py +++ b/panoptes_aggregation/tests/router_tests/test_routes.py @@ -70,6 +70,7 @@ def test_one_running_reducer_route(self): # Override json.dumps() for this test so it doesn't try to jsonify the mock import json + @patch("panoptes_aggregation.batch_aggregation.json.dumps", return_value=json.dumps({'project_id': 1, 'workflow_id': 10, 'user_id': 100, 'task_id': 'asdf'})) @patch("panoptes_aggregation.batch_aggregation.run_aggregation.delay") def test_run_aggregation_route(self, mocked_task, mocked_json):