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 9477a40  tests
9477a40 is described below

commit 9477a40dc206377f7f9f32fa4a02c7de7aef7a4d
Author: Eamon Ford <[email protected]>
AuthorDate: Mon Jun 15 18:04:32 2020 -0700

    tests
---
 .../{history_manager => entities}/__init__.py      |  0
 .../test_datasetingestionhistoryfile.py            | 64 ----------------------
 .../{ => services}/history_manager/__init__.py     |  0
 .../history_manager/test_FileIngestionHistory.py   | 52 ++++++++++++++++++
 .../history_manager/test_SolrIngestionHistory.py}  |  3 +-
 5 files changed, 54 insertions(+), 65 deletions(-)

diff --git a/collection_manager/tests/history_manager/__init__.py 
b/collection_manager/tests/entities/__init__.py
similarity index 100%
copy from collection_manager/tests/history_manager/__init__.py
copy to collection_manager/tests/entities/__init__.py
diff --git 
a/collection_manager/tests/history_manager/test_datasetingestionhistoryfile.py 
b/collection_manager/tests/history_manager/test_datasetingestionhistoryfile.py
deleted file mode 100644
index 0edeafb..0000000
--- 
a/collection_manager/tests/history_manager/test_datasetingestionhistoryfile.py
+++ /dev/null
@@ -1,64 +0,0 @@
-import unittest
-import os
-import sys
-import pathlib
-from collection_manager.services.history_manager import FileIngestionHistory
-from collection_manager.services.history_manager import md5sum_from_filepath
-
-HISTORY_ROOT_PATH = os.path.join(sys.prefix,
-                                 ".collection_manager",
-                                 "tmp/history")
-DATASET_ID = "zobi_la_mouche"
-
-
-class DatasetIngestionHistoryFileTestCase(unittest.TestCase):
-    ingestion_history = None
-
-    # @unittest.skip("does not work without a solr server for history_manager")
-    def test_get_md5sum(self):
-        self.ingestion_history = FileIngestionHistory(HISTORY_ROOT_PATH, 
DATASET_ID, md5sum_from_filepath)
-        self.ingestion_history._push_record("blue", "12weeukrhbwerqu7wier")
-        result = self.ingestion_history._get_signature("blue")
-        self.assertEqual(result, "12weeukrhbwerqu7wier")
-
-    # @unittest.skip("does not work without a solr server for history_manager")
-    def test_get_missing_md5sum(self):
-        self.ingestion_history = FileIngestionHistory(HISTORY_ROOT_PATH, 
DATASET_ID, md5sum_from_filepath)
-        self.ingestion_history._push_record("blue", "12weeukrhbwerqu7wier")
-        result = self.ingestion_history._get_signature("green")
-        self.assertEqual(result, None)
-
-    def test_has_valid_cache(self):
-        self.ingestion_history = FileIngestionHistory(HISTORY_ROOT_PATH, 
DATASET_ID, md5sum_from_filepath)
-        # history_manager with this file
-        current_file_path = pathlib.Path(__file__)
-        self.ingestion_history.push(str(current_file_path))
-        
self.assertEqual(self.ingestion_history.already_ingested(str(current_file_path)),
 True)
-
-    def test_has_valid_cache_with_latest_modifcation_signature(self):
-        self.ingestion_history = FileIngestionHistory(HISTORY_ROOT_PATH, 
DATASET_ID, os.path.getmtime)
-        # history_manager with this file
-        current_file_path = pathlib.Path(__file__)
-        self.ingestion_history.push(str(current_file_path))
-        
self.assertEqual(self.ingestion_history.already_ingested(str(current_file_path)),
 True)
-
-    def test_has_not_valid_cache(self):
-        self.ingestion_history = FileIngestionHistory(HISTORY_ROOT_PATH, 
DATASET_ID, md5sum_from_filepath)
-        # history_manager with this file
-        current_file_path = pathlib.Path(__file__)
-        
self.assertEqual(self.ingestion_history.already_ingested(str(current_file_path)),
 False)
-
-    @unittest.skip("skip before history_manager dataset is not available")
-    def test_purge(self):
-        self.ingestion_history = 
FileIngestionHistory("/Users/loubrieu/PycharmProjects/collection_manager/venv/.collection_manager/tmp/history/",
-                                                             
"avhrr-oi-analysed-sst-toto",
-                                                      lambda x : 
str(os.path.getmtime(x)))
-        self.ingestion_history.purge()
-
-    def tearDown(self):
-        self.ingestion_history.reset_cache()
-        del self.ingestion_history
-
-
-if __name__ == '__main__':
-    unittest.main()
diff --git a/collection_manager/tests/history_manager/__init__.py 
b/collection_manager/tests/services/history_manager/__init__.py
similarity index 100%
rename from collection_manager/tests/history_manager/__init__.py
rename to collection_manager/tests/services/history_manager/__init__.py
diff --git 
a/collection_manager/tests/services/history_manager/test_FileIngestionHistory.py
 
b/collection_manager/tests/services/history_manager/test_FileIngestionHistory.py
new file mode 100644
index 0000000..dd5b491
--- /dev/null
+++ 
b/collection_manager/tests/services/history_manager/test_FileIngestionHistory.py
@@ -0,0 +1,52 @@
+import os
+import pathlib
+import tempfile
+import unittest
+
+from collection_manager.services.history_manager import FileIngestionHistory, 
md5sum_from_filepath
+
+DATASET_ID = "zobi_la_mouche"
+
+
+class TestFileIngestionHistory(unittest.TestCase):
+
+    def test_get_md5sum(self):
+        with tempfile.TemporaryDirectory() as history_dir:
+            ingestion_history = FileIngestionHistory(history_dir, DATASET_ID, 
md5sum_from_filepath)
+            ingestion_history._push_record("blue", "12weeukrhbwerqu7wier")
+            result = ingestion_history._get_signature("blue")
+            self.assertEqual(result, "12weeukrhbwerqu7wier")
+
+    def test_get_missing_md5sum(self):
+        with tempfile.TemporaryDirectory() as history_dir:
+            ingestion_history = FileIngestionHistory(history_dir, DATASET_ID, 
md5sum_from_filepath)
+            ingestion_history._push_record("blue", "12weeukrhbwerqu7wier")
+            result = ingestion_history._get_signature("green")
+            self.assertIsNone(result)
+
+    def test_already_ingested(self):
+        with tempfile.TemporaryDirectory() as history_dir:
+            ingestion_history = FileIngestionHistory(history_dir, DATASET_ID, 
md5sum_from_filepath)
+            # history_manager with this file
+            current_file_path = pathlib.Path(__file__)
+            ingestion_history.push(str(current_file_path))
+            
self.assertTrue(ingestion_history.already_ingested(str(current_file_path)))
+
+    def test_already_ingested_with_latest_modifcation_signature(self):
+        with tempfile.TemporaryDirectory() as history_dir:
+            ingestion_history = FileIngestionHistory(history_dir, DATASET_ID, 
os.path.getmtime)
+            # history_manager with this file
+            current_file_path = pathlib.Path(__file__)
+            ingestion_history.push(str(current_file_path))
+            
self.assertTrue(ingestion_history.already_ingested(str(current_file_path)))
+
+    def test_already_ingested_is_false(self):
+        with tempfile.TemporaryDirectory() as history_dir:
+            ingestion_history = FileIngestionHistory(history_dir, DATASET_ID, 
md5sum_from_filepath)
+            # history_manager with this file
+            current_file_path = pathlib.Path(__file__)
+            
self.assertFalse(ingestion_history.already_ingested(str(current_file_path)))
+
+
+if __name__ == '__main__':
+    unittest.main()
diff --git 
a/collection_manager/tests/history_manager/test_datasetingestionhistorysolr.py 
b/collection_manager/tests/services/history_manager/test_SolrIngestionHistory.py
similarity index 94%
rename from 
collection_manager/tests/history_manager/test_datasetingestionhistorysolr.py
rename to 
collection_manager/tests/services/history_manager/test_SolrIngestionHistory.py
index 57b2bd1..deab42d 100644
--- 
a/collection_manager/tests/history_manager/test_datasetingestionhistorysolr.py
+++ 
b/collection_manager/tests/services/history_manager/test_SolrIngestionHistory.py
@@ -5,7 +5,8 @@ SOLR_URL = "http://localhost:8984/solr";
 DATASET_ID = "zobi_la_mouche"
 
 
-class DatasetIngestionHistorySolrTestCase(unittest.TestCase):
+# TODO: mock solr and fix these tests
+class TestSolrIngestionHistory(unittest.TestCase):
     @unittest.skip("does not work without a solr server for history_manager")
     def test_get(self):
         ingestion_history = SolrIngestionHistory(SOLR_URL, DATASET_ID)

Reply via email to