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

Commit

Permalink
Adiciona get_by_document em BankAccountWrapper (#20)
Browse files Browse the repository at this point in the history
* adiciona o GetByDocument Mixin

* adiciona testes

* fmt
  • Loading branch information
rodrigondec authored Oct 28, 2020
1 parent f46e4fb commit 7156461
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
17 changes: 10 additions & 7 deletions imopay_wrapper/wrapper/address.py
Original file line number Diff line number Diff line change
@@ -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
"""
Expand All @@ -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)
12 changes: 10 additions & 2 deletions imopay_wrapper/wrapper/bank_account.py
Original file line number Diff line number Diff line change
@@ -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
"""
Expand Down
7 changes: 7 additions & 0 deletions imopay_wrapper/wrapper/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
19 changes: 19 additions & 0 deletions tests/wrapper/test_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,32 @@

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


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)

Expand Down
14 changes: 11 additions & 3 deletions tests/wrapper/test_bank_account.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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):
"""
Expand Down

0 comments on commit 7156461

Please sign in to comment.