Skip to content

Commit eae1250

Browse files
committed
Merge branch 'devel'
2 parents ac704a2 + 2e64437 commit eae1250

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

CHANGES.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33

44
This is a high-level summary of the most important changes. For a full list of changes, see the [git commit log](https://github.com/grindsa/dkb-robo/commits) and pick the appropriate release branch.
55

6-
# Changes in 0.29-3
6+
# Changes in 0.29.4
7+
8+
**Bugfixes**:
9+
10+
- [#80](https://github.com/grindsa/dkb-robo/issues/80) - Download documents without date field in metadata
11+
12+
# Changes in 0.29.3
713

814
**Bugfixes**:
915

dkb_robo/postbox.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ def date(self) -> str:
150150
date = datetime.date.fromisoformat(self.document.metadata['creationDate'])
151151

152152
if date is None:
153-
raise AttributeError("No valid date field found in document metadata.")
153+
if 'subject' in self.document.metadata:
154+
logger.error("\"%s\" is missing a valid date field found in metadata. Using today\'s date as fallback.", self.document.metadata['subject'])
155+
else:
156+
logger.error("No valid date field found in document metadata. Using today's date as fallback.")
157+
date = datetime.date.today()
154158

155159
logger.debug("PostboxItem.date() for document %s ended with %s", self.id, date)
156160
return date.strftime('%Y-%m-%d')

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ authors = [{ name = "grindsa", email = "grindelsack@gmail.com" }]
33
name = "dkb_robo"
44
description = "Download transactions from the website of Deutsche Kreditbak AG"
55
keywords = ["Deutsche Kreditbank", "DKB"]
6-
version = "0.29.3"
6+
version = "0.29.4"
77
readme = "README.md"
88
classifiers = [
99
# Keep in sync with the Python version matrix in test_lint.yaml GitHub workflow.

test/test_postbox.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import unittest
55
from unittest.mock import patch, MagicMock
66
from pathlib import Path
7-
7+
from datetime import date
88
import requests
99
import logging
1010
sys.path.insert(0, '.')
@@ -198,12 +198,23 @@ def test_022_date_with_creation_date(self):
198198
self.document.metadata = {"creationDate": "2023-01-01"}
199199
self.assertEqual(self.postbox_item.date(), "2023-01-01")
200200

201-
def test_023_date_invalid(self):
201+
@patch("dkb_robo.postbox.datetime.date")
202+
def test_023_date_invalid(self, mock_today):
202203
""" Test that the date method raises an exception if no valid date field is found in the metadata."""
203204
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)
206209

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)
207218

208219
class TestPostBox(unittest.TestCase):
209220
""" Tests for the PostBox class. """

0 commit comments

Comments
 (0)