Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SP-770 Review Python dependency updates #71

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ name = "pypi"
[packages]
ecdsa = "==0.18.0"
requests = "==2.31.0"
pydantic = "==2.3.0"
pydantic = "==2.5.2"

[dev-packages]
black = "==23.7.0"
pytest = "==7.4.0"
black = "==23.11.0"
pytest = "==7.4.3"
pytest-mock = "==3.11.1"
mypy = "==1.5.1"
pytest-mypy-plugins = "==1.11.1"
mypy = "==1.7.1"
pytest-mypy-plugins = "==3.0.0"
pytest-cov = "==4.1.0"

[requires]
Expand Down
952 changes: 521 additions & 431 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "bitpay"
version = "5.0.1"
version = "6.0.0"
authors = [
{ name="Antonio Buedo", email="[email protected]" },
]
Expand Down
9 changes: 8 additions & 1 deletion src/bitpay/models/bill/bill.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""
Bill
"""
from datetime import datetime
from datetime import datetime, timezone
from typing import List, Union

from pydantic import field_serializer

from .item import Item
from ..bitpay_model import BitPayModel

Expand Down Expand Up @@ -35,3 +38,7 @@ class Bill(BitPayModel):
created_date: Union[datetime, None] = None
id: Union[str, None] = None
merchant: Union[str, None] = None

@field_serializer("due_date", "created_date")
def serialize_datetime(self, dt: datetime) -> str:
return super().serialize_datetime_to_iso8601(dt)
4 changes: 4 additions & 0 deletions src/bitpay/models/bitpay_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from typing import Union

from pydantic import BaseModel, field_validator, ConfigDict
Expand All @@ -19,6 +20,9 @@ def to_json(self) -> dict:
"""
return self.model_dump(exclude_unset=True, by_alias=True)

def serialize_datetime_to_iso8601(self, dt: datetime) -> str:
return dt.isoformat(timespec="microseconds")[:-4] + "Z"

@field_validator("currency", check_fields=False)
def validate_currency(cls, currency_code: Union[str, None]) -> Union[str, None]:
"""
Expand Down
6 changes: 5 additions & 1 deletion src/bitpay/models/invoice/refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime
from typing import Union

from pydantic import Field
from pydantic import Field, field_serializer

from bitpay.models.bitpay_model import BitPayModel

Expand Down Expand Up @@ -36,3 +36,7 @@ class Refund(BitPayModel):
transaction_refund_fee: Union[float, None] = None
txid: Union[str, None] = None
type: Union[str, None] = None

@field_serializer("request_date", "last_refund_notification")
def serialize_datetime(self, dt: datetime) -> str:
return super().serialize_datetime_to_iso8601(dt)
6 changes: 6 additions & 0 deletions src/bitpay/models/invoice/refund_webhook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from datetime import datetime
from typing import Union

from pydantic import field_serializer

from bitpay.models.bitpay_model import BitPayModel


Expand All @@ -16,3 +18,7 @@ class RefundWebhook(BitPayModel):
request_date: Union[datetime, None] = None
status: Union[str, None] = None
support_request: Union[str, None] = None

@field_serializer("request_date", "last_refund_notification")
def serialize_datetime(self, dt: datetime) -> str:
return super().serialize_datetime_to_iso8601(dt)
6 changes: 6 additions & 0 deletions src/bitpay/models/invoice/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from typing import Union, Dict
from bitpay.models.bitpay_model import BitPayModel

from pydantic import field_serializer


class Transaction(BitPayModel):
amount: Union[float, None] = None
Expand All @@ -11,3 +13,7 @@ class Transaction(BitPayModel):
txid: Union[str, None] = None
ex_rates: Union[Dict[str, float], None] = None
output_index: Union[int, None] = None

@field_serializer("time", "received_time")
def serialize_datetime_to_iso8601(self, dt: datetime) -> str:
return super().serialize_datetime_to_iso8601(dt)
6 changes: 5 additions & 1 deletion src/bitpay/models/ledger/ledger_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from datetime import datetime
from typing import Union
from pydantic import field_validator
from pydantic import field_validator, field_serializer
from bitpay.models.bitpay_model import BitPayModel
from bitpay.models.ledger.buyer import Buyer

Expand Down Expand Up @@ -37,3 +37,7 @@ def convert_to_str(cls, value: Union[int, float, None]) -> Union[float, None]:
if value is None:
return None
return float(value)

@field_serializer("timestamp")
def serialize_datetime_to_iso8601(self, dt: datetime) -> str:
return super().serialize_datetime_to_iso8601(dt)
6 changes: 5 additions & 1 deletion src/bitpay/models/payout/payout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from datetime import datetime
from typing import List, Union, Dict
from pydantic import Field
from pydantic import Field, field_serializer
from .payout_transaction import PayoutTransaction
from ..bitpay_model import BitPayModel

Expand Down Expand Up @@ -37,6 +37,10 @@ class Payout(BitPayModel):
account_id: Union[str, None] = None
group_id: Union[str, None] = None

@field_serializer("effective_date", "request_date", "date_executed")
def serialize_datetime_to_iso8601(self, dt: datetime) -> str:
return super().serialize_datetime_to_iso8601(dt)

def to_json(self) -> dict:
"""
:return: data in json
Expand Down
5 changes: 5 additions & 0 deletions src/bitpay/models/payout/payout_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
PayoutTransaction
"""
from datetime import datetime
from pydantic import field_serializer
from typing import Union
from bitpay.models.bitpay_model import BitPayModel

Expand All @@ -15,3 +16,7 @@ class PayoutTransaction(BitPayModel):
amount: Union[float, None] = None
date: Union[datetime, None] = None
confirmations: Union[str, None] = None

@field_serializer("date")
def serialize_datetime_to_iso8601(self, dt: datetime) -> str:
return super().serialize_datetime_to_iso8601(dt)
5 changes: 5 additions & 0 deletions src/bitpay/models/settlement/invoice_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
InvoiceData: Object containing relevant information from the paid invoice
"""
from datetime import datetime
from pydantic import field_serializer
from typing import Union, Dict
from bitpay.models.bitpay_model import BitPayModel
from bitpay.models.settlement.refund_info import RefundInfo
Expand All @@ -20,3 +21,7 @@ class InvoiceData(BitPayModel):
overpaid_amount: Union[float, None] = None
payout_percentage: Union[Dict[str, int], None] = None
refund_info: Union[RefundInfo, None] = None

@field_serializer("date")
def serialize_datetime_to_iso8601(self, dt: datetime) -> str:
return super().serialize_datetime_to_iso8601(dt)
5 changes: 5 additions & 0 deletions src/bitpay/models/settlement/settlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
endpoint exposes reports detailing these settlements.
"""
from datetime import datetime
from pydantic import field_serializer
from typing import List, Union
from .payout_info import PayoutInfo
from .settlement_ledger_entry import SettlementLedgerEntry
Expand Down Expand Up @@ -33,3 +34,7 @@ class Settlement(BitPayModel):
total_amount: Union[float, None] = None
ledger_entries: Union[List[SettlementLedgerEntry], None] = None
token: Union[str, None] = None

@field_serializer("date_created", "date_executed", "date_completed", "closing_date")
def serialize_datetime_to_iso8601(self, dt: datetime) -> str:
return super().serialize_datetime_to_iso8601(dt)
5 changes: 5 additions & 0 deletions src/bitpay/models/settlement/settlement_ledger_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
SettlementLedgerEntry: ledger entries in the settlement,
"""
from datetime import datetime
from pydantic import field_serializer
from typing import Union
from .invoice_data import InvoiceData
from ..bitpay_model import BitPayModel
Expand All @@ -18,3 +19,7 @@ class SettlementLedgerEntry(BitPayModel):
timestamp: Union[datetime, None] = None
description: Union[str, None] = None
invoice_data: Union[InvoiceData, None] = None

@field_serializer("timestamp")
def serialize_datetime_to_iso8601(self, dt: datetime) -> str:
return super().serialize_datetime_to_iso8601(dt)
2 changes: 1 addition & 1 deletion tests/unit/json/create_bill_by_pos_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"city": "Alexandria",
"country": "US",
"currency": "USD",
"dueDate": "2021-5-31",
"dueDate": "2021-05-31T00:00:00.00Z",
"email": "[email protected]",
"items": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/json/create_bill_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"city": "Alexandria",
"country": "US",
"currency": "USD",
"dueDate": "2021-5-31",
"dueDate": "2021-05-31T00:00:00.00Z",
"email": "[email protected]",
"items": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/json/update_bill_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"city": "Alexandria",
"country": "US",
"currency": "USD",
"dueDate": "2021-5-31",
"dueDate": "2021-05-31T00:00:00.00Z",
"email": "[email protected]",
"items": [
{
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
from datetime import datetime
from typing import List

import pytest
Expand Down Expand Up @@ -115,7 +116,7 @@ def get_example_bill():
bill.country = "US"
bill.cc = cc
bill.phone = "555-123-456"
bill.due_date = "2021-5-31"
bill.due_date = datetime.strptime("2021-5-31", "%Y-%m-%d")
bill.pass_processing_fee = True
bill.items = [item1, item2]
return bill
Expand Down Expand Up @@ -1041,6 +1042,7 @@ def test_update_bill(mocker):
assert result.number == "bill1234-EFGH"
assert result.cc[0] == "[email protected]"
assert result.id == "X6KJbe9RxAGWNReCwd1xRw"
assert result.due_date.strftime('%Y-%m-%dT%H:%M:%S') == "2021-05-31T00:00:00"
assert result.items[1].description == "Test Item 2"
assert (
result.token
Expand Down