From f85338dcbcc93806ef6a8d7e43c690205c72e331 Mon Sep 17 00:00:00 2001 From: Rodrigo Castro Date: Tue, 1 Sep 2020 14:34:43 -0300 Subject: [PATCH] =?UTF-8?q?Corrige=20serializa=C3=A7=C3=A3o=20de=20Configu?= =?UTF-8?q?rations=20(#11)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * corrige serialização do configurations * adiciona teste * fmt --- imopay_wrapper/models/transaction.py | 14 +++++++++----- .../transaction/test_invoice_configurations.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/imopay_wrapper/models/transaction.py b/imopay_wrapper/models/transaction.py index adf5b92..78413ea 100644 --- a/imopay_wrapper/models/transaction.py +++ b/imopay_wrapper/models/transaction.py @@ -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 diff --git a/tests/models/transaction/test_invoice_configurations.py b/tests/models/transaction/test_invoice_configurations.py index 50da07b..83c0a50 100644 --- a/tests/models/transaction/test_invoice_configurations.py +++ b/tests/models/transaction/test_invoice_configurations.py @@ -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()