|
4 | 4 | import unittest
|
5 | 5 | from unittest.mock import patch, MagicMock
|
6 | 6 | from pathlib import Path
|
7 |
| - |
| 7 | +from datetime import date |
8 | 8 | import requests
|
9 | 9 | import logging
|
10 | 10 | sys.path.insert(0, '.')
|
@@ -198,12 +198,23 @@ def test_022_date_with_creation_date(self):
|
198 | 198 | self.document.metadata = {"creationDate": "2023-01-01"}
|
199 | 199 | self.assertEqual(self.postbox_item.date(), "2023-01-01")
|
200 | 200 |
|
201 |
| - def test_023_date_invalid(self): |
| 201 | + @patch("dkb_robo.postbox.datetime.date") |
| 202 | + def test_023_date_invalid(self, mock_today): |
202 | 203 | """ Test that the date method raises an exception if no valid date field is found in the metadata."""
|
203 | 204 | self.document.metadata = {}
|
204 |
| - with self.assertRaises(AttributeError): |
205 |
| - self.postbox_item.date() |
| 205 | + mock_today.today.return_value = date(2025, 3, 23) |
| 206 | + with self.assertLogs('dkb_robo', level='INFO') as lcm: |
| 207 | + self.assertEqual('2025-03-23', self.postbox_item.date()) |
| 208 | + self.assertIn("ERROR:dkb_robo.postbox:No valid date field found in document metadata. Using today's date as fallback.", lcm.output) |
206 | 209 |
|
| 210 | + @patch("dkb_robo.postbox.datetime.date") |
| 211 | + def test_024_date_invalid(self, mock_today): |
| 212 | + """ Test that the date method raises an exception if no valid date field is found in the metadata.""" |
| 213 | + self.document.metadata = {"subject": "subject"} |
| 214 | + mock_today.today.return_value = date(2025, 3, 23) |
| 215 | + with self.assertLogs('dkb_robo', level='INFO') as lcm: |
| 216 | + self.assertEqual('2025-03-23', self.postbox_item.date()) |
| 217 | + self.assertIn('ERROR:dkb_robo.postbox:"subject" is missing a valid date field found in metadata. Using today\'s date as fallback.', lcm.output) |
207 | 218 |
|
208 | 219 | class TestPostBox(unittest.TestCase):
|
209 | 220 | """ Tests for the PostBox class. """
|
|
0 commit comments