You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sdap.apache.org by ea...@apache.org on 2020/06/11 00:24:25 UTC
[incubator-sdap-ingester] branch tests updated: unit tests
This is an automated email from the ASF dual-hosted git repository.
eamonford pushed a commit to branch tests
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-ingester.git
The following commit(s) were added to refs/heads/tests by this push:
new 2301078 unit tests
2301078 is described below
commit 23010787e43f168ec30b6e37229d9634b812046e
Author: Eamon Ford <ea...@jpl.nasa.gov>
AuthorDate: Wed Jun 10 17:20:01 2020 -0700
unit tests
---
.../services/CollectionProcessor.py | 2 +-
.../tests/services/test_CollectionProcessor.py | 91 ++++++++++++++++++++--
2 files changed, 86 insertions(+), 7 deletions(-)
diff --git a/collection_manager/collection_manager/services/CollectionProcessor.py b/collection_manager/collection_manager/services/CollectionProcessor.py
index 75a86e2..54d35a5 100644
--- a/collection_manager/collection_manager/services/CollectionProcessor.py
+++ b/collection_manager/collection_manager/services/CollectionProcessor.py
@@ -61,7 +61,7 @@ class CollectionProcessor:
return
dataset_config = self._fill_template(collection, config_template=self._config_template)
- self._publisher.publish_message(dataset_config, use_priority)
+ self._publisher.publish_message(body=dataset_config, priority=use_priority)
history_manager.push(granule)
@staticmethod
diff --git a/collection_manager/tests/services/test_CollectionProcessor.py b/collection_manager/tests/services/test_CollectionProcessor.py
index 73b67ba..ea7d0d0 100644
--- a/collection_manager/tests/services/test_CollectionProcessor.py
+++ b/collection_manager/tests/services/test_CollectionProcessor.py
@@ -1,10 +1,11 @@
import tempfile
-from unittest import mock
import unittest
+from unittest import mock
from collection_manager.entities import Collection
from collection_manager.services import CollectionProcessor
-from collection_manager.services.history_manager import FileIngestionHistoryBuilder, FileIngestionHistory
+from collection_manager.services.history_manager import FileIngestionHistoryBuilder
+from collection_manager.services.history_manager import GranuleStatus
class TestCollectionProcessor(unittest.TestCase):
@@ -60,7 +61,85 @@ class TestCollectionProcessor(unittest.TestCase):
filled = CollectionProcessor._fill_template(collection, template)
self.assertEqual(filled, expected)
- @mock.patch.object(FileIngestionHistory, 'push')
- @mock.patch.object(FileIngestionHistory, 'get_granule_status')
- def test_process_granule(self):
- history_manager_builder = FileIngestionHistoryBuilder('/foo')
+ @mock.patch('collection_manager.services.history_manager.FileIngestionHistory', autospec=True)
+ @mock.patch('collection_manager.services.history_manager.FileIngestionHistoryBuilder', autospec=True)
+ @mock.patch('collection_manager.services.MessagePublisher', autospec=True)
+ def test_process_granule_with_historical_granule(self, mock_publisher, mock_history_builder, mock_history):
+ mock_history.get_granule_status.return_value = GranuleStatus.DESIRED_HISTORICAL
+ mock_history_builder.build.return_value = mock_history
+
+ collection_processor = CollectionProcessor(mock_publisher, mock_history_builder)
+ collection = Collection(dataset_id="test_dataset",
+ path="test_path",
+ variable="test_variable",
+ historical_priority=1,
+ forward_processing_priority=2,
+ date_from=None,
+ date_to=None)
+
+ collection_processor.process_granule("test.nc", collection)
+
+ mock_publisher.publish_message.assert_called_with(body=mock.ANY, priority=1)
+ mock_history.push.assert_called()
+
+ @mock.patch('collection_manager.services.history_manager.FileIngestionHistory', autospec=True)
+ @mock.patch('collection_manager.services.history_manager.FileIngestionHistoryBuilder', autospec=True)
+ @mock.patch('collection_manager.services.MessagePublisher', autospec=True)
+ def test_process_granule_with_forward_processing_granule(self, mock_publisher, mock_history_builder, mock_history):
+ mock_history.get_granule_status.return_value = GranuleStatus.DESIRED_FORWARD_PROCESSING
+ mock_history_builder.build.return_value = mock_history
+
+ collection_processor = CollectionProcessor(mock_publisher, mock_history_builder)
+ collection = Collection(dataset_id="test_dataset",
+ path="test_path",
+ variable="test_variable",
+ historical_priority=1,
+ forward_processing_priority=2,
+ date_from=None,
+ date_to=None)
+
+ collection_processor.process_granule("test.nc", collection)
+
+ mock_publisher.publish_message.assert_called_with(body=mock.ANY, priority=2)
+ mock_history.push.assert_called()
+
+ @mock.patch('collection_manager.services.history_manager.FileIngestionHistory', autospec=True)
+ @mock.patch('collection_manager.services.history_manager.FileIngestionHistoryBuilder', autospec=True)
+ @mock.patch('collection_manager.services.MessagePublisher', autospec=True)
+ def test_process_granule_with_undesired_granule(self, mock_publisher, mock_history_builder, mock_history):
+ mock_history.get_granule_status.return_value = GranuleStatus.UNDESIRED
+ mock_history_builder.build.return_value = mock_history
+
+ collection_processor = CollectionProcessor(mock_publisher, mock_history_builder)
+ collection = Collection(dataset_id="test_dataset",
+ path="test_path",
+ variable="test_variable",
+ historical_priority=1,
+ forward_processing_priority=2,
+ date_from=None,
+ date_to=None)
+
+ collection_processor.process_granule("test.nc", collection)
+
+ mock_publisher.publish_message.assert_not_called()
+ mock_history.push.assert_not_called()
+
+ @mock.patch('collection_manager.services.history_manager.FileIngestionHistory', autospec=True)
+ @mock.patch('collection_manager.services.history_manager.FileIngestionHistoryBuilder', autospec=True)
+ @mock.patch('collection_manager.services.MessagePublisher', autospec=True)
+ def test_process_granule_with_unsupported_file_type(self, mock_publisher, mock_history_builder, mock_history):
+ mock_history_builder.build.return_value = mock_history
+
+ collection_processor = CollectionProcessor(mock_publisher, mock_history_builder)
+ collection = Collection(dataset_id="test_dataset",
+ path="test_path",
+ variable="test_variable",
+ historical_priority=1,
+ forward_processing_priority=2,
+ date_from=None,
+ date_to=None)
+
+ collection_processor.process_granule("test.foo", collection)
+
+ mock_publisher.publish_message.assert_not_called()
+ mock_history.push.assert_not_called()