Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Corrige serialização de Configurations (#11)
Browse files Browse the repository at this point in the history
* corrige serialização do configurations

* adiciona teste

* fmt
  • Loading branch information
rodrigondec authored Sep 1, 2020
1 parent 4f2e5e1 commit f85338d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 9 additions & 5 deletions imopay_wrapper/models/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ def to_dict(self):
Ao invés de solucionar isso, mais fácil sobreescrever o método
no momento.
"""
data = {
"fine": self.fine.to_dict(),
"interest": self.interest.to_dict(),
"discounts": [discount.to_dict() for discount in self.discounts],
}
data = {}
if self.fine:
data["fine"] = self.fine.to_dict()

if self.interest:
data["interest"] = self.interest.to_dict()

if self.discounts:
data["discounts"] = [discount.to_dict() for discount in self.discounts]
return data


Expand Down
10 changes: 10 additions & 0 deletions tests/models/transaction/test_invoice_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ def test_2(self):
{"fine": {"value": 1, "type": "foo", "charge_type": "foo", "days": 0}}
)
self.assertEqual(t.fine.value, 1)

def test_3(self):
t = InvoiceConfigurations.from_dict(
{
"fine": Configuration.from_dict(
{"value": 1, "type": "foo", "charge_type": "foo", "days": 0}
)
}
)
t.to_dict()

0 comments on commit f85338d

Please sign in to comment.