Skip to content

Commit

Permalink
feat: change datetime parser to use python-dateutil
Browse files Browse the repository at this point in the history
The datetime parser in DACITE_CONFIG has been updated to use python-dateutil's parse function instead of datetime.fromisoformat. This change provides more robust datetime parsing capabilities and better handles various datetime string formats.

Signed-off-by: Avelino <[email protected]>
  • Loading branch information
avelino committed Jan 9, 2025
1 parent 46c7ffe commit c564f40
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion barte/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from datetime import datetime
from typing import Optional, List, Dict, Any
from dacite import Config
from dateutil.parser import parse as parse_date

# Default config for dacite with datetime conversion
DACITE_CONFIG = Config(
type_hooks={
datetime: lambda x: datetime.fromisoformat(x.replace("Z", "+00:00")) if isinstance(x, str) else x
datetime: lambda x: parse_date(x) if isinstance(x, str) else x
}
)

Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pytest>=7.0.0
pytest-cov>=4.0.0
requests-mock>=1.10.0
requests-mock>=1.10.0
python-dateutil>=2.8.0
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
packages=find_packages(),
install_requires=[
"requests>=2.25.0",
"dacite>=1.8.0"
"dacite>=1.8.0",
"python-dateutil>=2.8.0"
],
python_requires=">=3.11",
classifiers=[
Expand Down
8 changes: 8 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ def test_pix_charge_get_qrcode(self, mock_get, mock_charge_response):

def test_client_singleton(self):
"""Test client singleton pattern"""
# Reset singleton for initial state
BarteClient._instance = None

# Test uninitialized state
with pytest.raises(RuntimeError) as exc_info:
BarteClient.get_instance()
assert "BarteClient not initialized" in str(exc_info.value)

# First initialization
client1 = BarteClient(api_key="test_key", environment="sandbox")
assert BarteClient.get_instance() == client1
Expand Down

0 comments on commit c564f40

Please sign in to comment.