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

Commit

Permalink
Adiciona Address.update e Addres.get_by_document (#13)
Browse files Browse the repository at this point in the history
* adiciona método update e get_by_document

* corrige exemplos

* adiciona testes

* adiciona exemplos
  • Loading branch information
rodrigondec authored Sep 2, 2020
1 parent 0592f7a commit 8c5dbe9
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/address/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
a = {
"owner": "algum id",
"city": "Natal",
"state": "RN",
"uf": "RN",
"zip_code": "99999999",
"street": "Peterson Mills",
"number": "9626",
Expand Down
9 changes: 9 additions & 0 deletions examples/address/get_by_document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from imopay_wrapper import ImopayWrapper

client = ImopayWrapper()

document = "cpf/cnpj qualquer"

response = client.address.get_by_document(document)

print(response)
2 changes: 2 additions & 0 deletions examples/address/retrieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
id = "foo"

response = client.address.retrieve(id)

print(response)
15 changes: 7 additions & 8 deletions examples/address/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
id = "foo"

a = {
"owner": "algum id",
"owner": "bar",
"city": "Natal",
"state": "RN",
"zip_code": "99999999",
"street": "Peterson Mills",
"number": "9626",
"neighborhood": "Crescent",
"complement": "Senior condition research. City strategy such start",
"uf": "RN",
"zip_code": "59100000",
"street": "Rua Qualquer",
"number": 11111,
"neighborhood": "Tirol",
"complement": None,
}


response = client.address.update(id, a)
12 changes: 12 additions & 0 deletions imopay_wrapper/wrapper/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ def create(self, data: dict):
instance = self.model(**data)
url = self._construct_url(action=self.action, subaction="create_by_name_and_uf")
return self._post(url, instance.to_dict())

def update(self, identifier, data: dict):
instance = self.model(**data)
url = self._construct_url(
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)
45 changes: 45 additions & 0 deletions tests/wrapper/test_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,48 @@ def test_create(self):
),
mocked_model.return_value.return_value.to_dict.return_value,
)

def test_update(self):
with patch(
"imopay_wrapper.wrapper.address.AddressWrapper.model",
new_callable=PropertyMock,
) as mocked_model, patch(
"imopay_wrapper.wrapper.address.AddressWrapper.action",
new_callable=PropertyMock,
) as mocked_action, patch(
"imopay_wrapper.wrapper.address.AddressWrapper._patch"
) as mocked_post:
self.client.update("foo", {})

mocked_model.assert_called_once()

mocked_action.assert_called_once()

mocked_post.assert_called_once_with(
self.client._construct_url(
action=mocked_action.return_value,
subaction="update_by_name_and_uf",
identifier="foo",
),
mocked_model.return_value.return_value.to_dict.return_value,
)

def test_get_by_document(self):
with patch(
"imopay_wrapper.wrapper.address.AddressWrapper.action",
new_callable=PropertyMock,
) as mocked_action, patch(
"imopay_wrapper.wrapper.address.AddressWrapper._post"
) as mocked_post:
self.client.get_by_document("foo")

mocked_action.assert_called_once()

expected_data = {"cpf_cnpj": "foo"}

mocked_post.assert_called_once_with(
self.client._construct_url(
action=mocked_action.return_value, subaction="get_by_document"
),
expected_data,
)

0 comments on commit 8c5dbe9

Please sign in to comment.