From 71564613e1f0a8bd7040b96fc79cc41750b413a8 Mon Sep 17 00:00:00 2001 From: Rodrigo Castro Date: Wed, 28 Oct 2020 12:42:30 -0300 Subject: [PATCH] Adiciona `get_by_document` em `BankAccountWrapper` (#20) * adiciona o GetByDocument Mixin * adiciona testes * fmt --- imopay_wrapper/wrapper/address.py | 17 ++++++++++------- imopay_wrapper/wrapper/bank_account.py | 12 ++++++++++-- imopay_wrapper/wrapper/base.py | 7 +++++++ tests/wrapper/test_address.py | 19 +++++++++++++++++++ tests/wrapper/test_bank_account.py | 14 +++++++++++--- 5 files changed, 57 insertions(+), 12 deletions(-) diff --git a/imopay_wrapper/wrapper/address.py b/imopay_wrapper/wrapper/address.py index 24fe8c2..973fa83 100644 --- a/imopay_wrapper/wrapper/address.py +++ b/imopay_wrapper/wrapper/address.py @@ -1,8 +1,16 @@ -from .base import BaseImopayWrapper, CreateMixin, UpdateMixin, RetrieveMixin +from .base import ( + BaseImopayWrapper, + CreateMixin, + UpdateMixin, + RetrieveMixin, + GetByDocumentMixin, +) from ..models.address import Address -class AddressWrapper(BaseImopayWrapper, CreateMixin, UpdateMixin, RetrieveMixin): +class AddressWrapper( + BaseImopayWrapper, CreateMixin, UpdateMixin, RetrieveMixin, GetByDocumentMixin +): """ Wrapper para os métodos de address """ @@ -26,8 +34,3 @@ def update(self, identifier, data: dict): action=self.action, subaction="update_by_name_and_uf", identifier=identifier ) return self._patch(url, instance.to_dict()) - - def get_by_document(self, document): - data = {"cpf_cnpj": document} - url = self._construct_url(action=self.action, subaction="get_by_document") - return self._post(url, data) diff --git a/imopay_wrapper/wrapper/bank_account.py b/imopay_wrapper/wrapper/bank_account.py index df603cb..9c9c5fe 100644 --- a/imopay_wrapper/wrapper/bank_account.py +++ b/imopay_wrapper/wrapper/bank_account.py @@ -1,8 +1,16 @@ -from .base import BaseImopayWrapper, CreateMixin, RetrieveMixin, DestroyMixin +from .base import ( + BaseImopayWrapper, + CreateMixin, + RetrieveMixin, + DestroyMixin, + GetByDocumentMixin, +) from ..models.bank_account import BankAccount -class BankAccountWrapper(BaseImopayWrapper, CreateMixin, RetrieveMixin, DestroyMixin): +class BankAccountWrapper( + BaseImopayWrapper, CreateMixin, RetrieveMixin, DestroyMixin, GetByDocumentMixin +): """ Wrapper para os métodos de contas bancárias """ diff --git a/imopay_wrapper/wrapper/base.py b/imopay_wrapper/wrapper/base.py index e214cd6..02b9197 100644 --- a/imopay_wrapper/wrapper/base.py +++ b/imopay_wrapper/wrapper/base.py @@ -258,3 +258,10 @@ class DestroyMixin: def destroy(self, identifier: str): url = self._construct_url(action=self.action, identifier=identifier) return self._delete(url) + + +class GetByDocumentMixin: + def get_by_document(self, document: str): + data = {"cpf_cnpj": document} + url = self._construct_url(action=self.action, subaction="get_by_document") + return self._post(url, data) diff --git a/tests/wrapper/test_address.py b/tests/wrapper/test_address.py index ae996dc..7aa394a 100644 --- a/tests/wrapper/test_address.py +++ b/tests/wrapper/test_address.py @@ -2,6 +2,11 @@ from ..utils import LocalImopayTestCase from imopay_wrapper import ImopayWrapper +from imopay_wrapper.wrapper.base import ( + CreateMixin, + RetrieveMixin, + GetByDocumentMixin, +) from imopay_wrapper.models.address import Address @@ -9,6 +14,20 @@ class AddressWrapperTestCase(LocalImopayTestCase): def setUp(self): self.client = ImopayWrapper().address + def test_mixins(self): + """ + Dado: + - um client ImopayWrapper().address + Quando: + - N/A + Então: + - client deve ser uma instância de + CreateMixin, RetrieveMixin, DestroyMixin, GetByDocumentMixin + """ + mixins = (CreateMixin, RetrieveMixin, GetByDocumentMixin) + for mixin in mixins: + self.assertIsInstance(self.client, mixin) + def test_model(self): self.assertEqual(self.client.model, Address) diff --git a/tests/wrapper/test_bank_account.py b/tests/wrapper/test_bank_account.py index fbd65a7..dda1bce 100644 --- a/tests/wrapper/test_bank_account.py +++ b/tests/wrapper/test_bank_account.py @@ -1,6 +1,11 @@ from ..utils import LocalImopayTestCase from imopay_wrapper import ImopayWrapper -from imopay_wrapper.wrapper.base import CreateMixin, RetrieveMixin, DestroyMixin +from imopay_wrapper.wrapper.base import ( + CreateMixin, + RetrieveMixin, + DestroyMixin, + GetByDocumentMixin, +) from imopay_wrapper.models.bank_account import BankAccount @@ -15,9 +20,12 @@ def test_mixins(self): Quando: - N/A Então: - - client deve ser uma instância de (CreateMixin, RetrieveMixin, DestroyMixin) # noqa + - client deve ser uma instância de + CreateMixin, RetrieveMixin, DestroyMixin, GetByDocumentMixin """ - self.assertIsInstance(self.client, (CreateMixin, RetrieveMixin, DestroyMixin)) + mixins = (CreateMixin, RetrieveMixin, DestroyMixin, GetByDocumentMixin) + for mixin in mixins: + self.assertIsInstance(self.client, mixin) def test_model(self): """