test(ingest): mock boto3 client in tests; fix FeedParser._parse_date to raise ValueError on invalid input

This commit is contained in:
KaifAhmad1
2026-01-28 14:13:15 +05:30
parent 15b32f49be
commit 400a70986d
2 changed files with 8 additions and 1 deletions
+6 -1
View File
@@ -359,9 +359,14 @@ class FeedParser:
return parser.parse(date_string)
except (ImportError, OSError):
# If dateutil isn't available, fall through to raising ValueError
pass
except Exception as e:
# If dateutil fails to parse, raise ValueError to signal invalid input
raise ValueError(f"Invalid date format: {date_string}") from e
return None
# No known formats matched and dateutil is unavailable; raise ValueError
raise ValueError(f"Invalid date format: {date_string}")
def validate_feed(self, feed_data: FeedData) -> bool:
"""
+2
View File
@@ -7,6 +7,7 @@ from unittest.mock import MagicMock
# and we must populate the attributes that the code tries to import/patch.
module_names = [
"boto3",
"google",
"google.cloud",
"google.cloud.storage",
@@ -23,6 +24,7 @@ for name in module_names:
# Explicitly add the classes that will be patched/used
sys.modules["google.cloud.storage"].Client = MagicMock()
sys.modules["azure.storage.blob"].BlobServiceClient = MagicMock()
sys.modules["boto3"].client = MagicMock()
from pathlib import Path # noqa: E402
from unittest.mock import patch # noqa: E402