From 948e64461b9ccd62b450dff54587126ffe89c10e Mon Sep 17 00:00:00 2001 From: Tom Eldar Date: Tue, 29 Aug 2023 12:01:22 -0400 Subject: [PATCH] Check folder instead of just folder name in path --- main.py | 22 +++++++++++----------- tests/test_main.py | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index b427d24..f6f9943 100644 --- a/main.py +++ b/main.py @@ -101,25 +101,25 @@ def create_product_from_file_path(file_path: str) -> Product: timezone.utc ) - if "images" in file_path: - if "EO" in file_path: + if "images/" in file_path: + if "EO/" in file_path: product = Product("image", "EO", last_modified_on) - if "HS" in file_path: + if "HS/" in file_path: product = Product("image", "HS", last_modified_on) - if "IR" in file_path: + if "IR/" in file_path: product = Product("image", "IR", last_modified_on) - elif "tactical" in file_path: - if "Detection" in file_path: + elif "tactical/" in file_path: + if "Detection/" in file_path: product = Product("tactical", "Detection", last_modified_on) - if "HeatPerimeter" in file_path: + if "HeatPerimeter/" in file_path: product = Product("tactical", "HeatPerimeter", last_modified_on) - if "IntenseHeat" in file_path: + if "IntenseHeat/" in file_path: product = Product("tactical", "IntenseHeat", last_modified_on) - if "IsolatedHeat" in file_path: + if "IsolatedHeat/" in file_path: product = Product("tactical", "IsolatedHeat", last_modified_on) - if "ScatteredHeat" in file_path: + if "ScatteredHeat/" in file_path: product = Product("tactical", "ScatteredHeat", last_modified_on) - elif "videos" in file_path: + elif "videos/" in file_path: product = Product("video", None, last_modified_on) if product is None: diff --git a/tests/test_main.py b/tests/test_main.py index 3550909..10f0399 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -42,6 +42,21 @@ def test_create_product_from_file_path_image(self, mock_getmtime): mock_getmtime.assert_called_once_with(file_path) + @patch("os.path.getmtime", return_value=1234567890.0) + def test_create_product_from_file_path_image_with_wrong_type_in_path( + self, mock_getmtime + ): + file_path = "images/EO/IRimage.tif" + expected_product = Product( + "image", "EO", datetime.fromtimestamp(1234567890.0, tz=timezone.utc) + ) + created_product = create_product_from_file_path(file_path) + print(created_product) + print(expected_product) + self.assertEqual(created_product, expected_product) + + mock_getmtime.assert_called_once_with(file_path) + @patch("os.path.getmtime", return_value=1234567890.0) def test_create_product_from_file_path_tactical(self, mock_getmtime): file_path = "tactical/Detection/some_detection.kml"