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

Commit

Permalink
remove a adiciona do instance no response! (#113)
Browse files Browse the repository at this point in the history
* remove o instance no response

* a zoop recebe ein para criar conta bancária mas retorna um taxpayer_id!!

* fmt
  • Loading branch information
rodrigondec authored Oct 30, 2020
1 parent b7f4513 commit e7427fd
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 114 deletions.
30 changes: 30 additions & 0 deletions examples/bank_account/bank_account_create_business.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os

from zoop_wrapper import ZoopWrapper, BankAccount
from examples.utils import dump_response


"""
Nesse momento as constantes podem ser criadas no arquivo .py.
Mas é recomendado utilizar como variável de ambiente em um '.env'
"""
from zoop_wrapper.constants import MARKETPLACE_ID, ZOOP_KEY


client = ZoopWrapper(marketplace_id=MARKETPLACE_ID, key=ZOOP_KEY)

business_seller_id = "ef90df686ab64e6cbcdc2c1d68156605"
response = client.retrieve_seller(business_seller_id)

ba = {
"account_number": "123123",
"bank_code": "001",
"holder_name": "Algum Nome",
"routing_number": "123123",
"ein": response.data["ein"],
"type": BankAccount.SAVING_TYPE,
}

response = client.add_bank_account(ba)

dump_response(response, os.path.basename(__file__).split(".")[0])
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
brian = client.retrieve_seller(seller_brian)

ba = {
"account_number": "123",
"bank_code": "237",
"account_number": "123123",
"bank_code": "001",
"holder_name": "Algum Nome",
"routing_number": "foo",
"taxpayer_id": brian.instance.taxpayer_id,
"routing_number": "123123",
"taxpayer_id": brian.data["taxpayer_id"],
"type": BankAccount.SAVING_TYPE,
}

Expand Down
8 changes: 4 additions & 4 deletions examples/data/add_business_seller.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "a482a4d33d3741b287071132bb3225af",
"id": "ef90df686ab64e6cbcdc2c1d68156605",
"status": "pending",
"resource": "seller",
"type": "business",
Expand All @@ -14,7 +14,7 @@
"business_opening_date": "0000-00-00",
"business_facebook": null,
"business_twitter": null,
"ein": "16535515052002",
"ein": "74201461611044",
"statement_descriptor": null,
"mcc": null,
"business_address": {
Expand Down Expand Up @@ -58,6 +58,6 @@
"uri": "/v1/marketplaces/foo/sellers/businesses/",
"marketplace_id": "foo",
"metadata": {},
"created_at": "2020-08-24T17:22:06+00:00",
"updated_at": "2020-08-24T17:22:07+00:00"
"created_at": "2020-10-30T22:32:22+00:00",
"updated_at": "2020-10-30T22:32:22+00:00"
}
30 changes: 30 additions & 0 deletions examples/data/bank_account_create_business.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"id": "4e03e7785405428a90f67f007721025c",
"resource": "bank_account",
"holder_name": "Algum Nome",
"taxpayer_id": "74201461611044",
"description": null,
"bank_name": "Banco do Brasil S.A.",
"bank_code": "001",
"type": "Savings",
"account_number": "123123",
"country_code": "BR",
"routing_number": "123123",
"routing_check_digit": null,
"phone_number": null,
"is_active": true,
"is_verified": false,
"debitable": false,
"customer": "ef90df686ab64e6cbcdc2c1d68156605",
"fingerprint": "05fdfcb94af1e73c223ac75ca69665c3afd6bd62aaad9bdc99af5590b2eb8438",
"address": null,
"verification_checklist": {
"postal_code_check": "unchecked",
"address_line1_check": "unchecked",
"deposit_check": "unchecked"
},
"metadata": {},
"uri": "/v1/marketplaces/foo/bank_accounts/4e03e7785405428a90f67f007721025c",
"created_at": "2020-10-30T22:34:01+00:00",
"updated_at": "2020-10-30T22:34:01+00:00"
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"id": "e85edf6d0add48339e3d8189f615c3b1",
"id": "b45141b144f34208b18c4b695e7a6b48",
"resource": "bank_account",
"holder_name": "Algum Nome",
"taxpayer_id": "94998862499",
"description": null,
"bank_name": "Banco Bradesco S.A.",
"bank_code": "237",
"bank_name": "Banco do Brasil S.A.",
"bank_code": "001",
"type": "Savings",
"account_number": "123",
"account_number": "123123",
"country_code": "BR",
"routing_number": "foo",
"routing_number": "123123",
"routing_check_digit": null,
"phone_number": null,
"is_active": true,
"is_verified": false,
"debitable": false,
"customer": "0b05a360f4b749498f74e13004c08024",
"fingerprint": "5415ba4927cb5cec4aa4dfd309a4f6813b5f2644423533ffb2d245713a285a61",
"fingerprint": "66fde16cbcd461a389ad0fa31c61c30c6c5a8a3f44d40cf783f808498a59b0ec",
"address": null,
"verification_checklist": {
"postal_code_check": "unchecked",
"address_line1_check": "unchecked",
"deposit_check": "unchecked"
},
"metadata": {},
"uri": "/v1/marketplaces/foo/bank_accounts/e85edf6d0add48339e3d8189f615c3b1",
"created_at": "2020-10-09T19:54:56+00:00",
"updated_at": "2020-10-09T19:54:57+00:00"
"uri": "/v1/marketplaces/foo/bank_accounts/b45141b144f34208b18c4b695e7a6b48",
"created_at": "2020-10-30T22:34:10+00:00",
"updated_at": "2020-10-30T22:34:11+00:00"
}
4 changes: 2 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def tearDown(self):
del self.client

@staticmethod
def build_response_mock(status_code=200, content=None, instance=None):
def build_response_mock(status_code=200, content=None, data=None):
response = MagicMock(
status_code=status_code,
json=MagicMock(return_value=content if content else {}),
instance=instance,
data=data if data else {},
)

def raise_for_status():
Expand Down
8 changes: 0 additions & 8 deletions tests/wrapper/test_bank_accounts_methods.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from unittest.mock import patch, MagicMock

from tests.utils import APITestCase
from zoop_wrapper.models.bank_account import BankAccount
from zoop_wrapper.models.token import Token
from tests.factories.bank_account import IndividualBankAccountFactory
from tests.factories.token import (
BankAccountTokenFactory,
Expand Down Expand Up @@ -33,8 +31,6 @@ def test_retrieve_bank_account(self):
self.assertEqual(response.status_code, 200, msg=response.data)
data = response.data
self.assertEqual(data.get("id"), "foo", msg=data)
self.assertIsInstance(response.instance, BankAccount)
self.assertEqual(response.instance.id, "foo")

def test_add_bank_account_token(self):
"""
Expand All @@ -46,8 +42,6 @@ def test_add_bank_account_token(self):

response = self.client._BankAccountWrapper__add_bank_account_token(token)
self.assertEqual(response.status_code, 201, msg=response.data)
self.assertIsInstance(response.instance, Token)
self.assertIsInstance(response.instance.bank_account, BankAccount)

@patch(
"zoop_wrapper.wrapper.ZoopWrapper._BankAccountWrapper__add_bank_account_token"
Expand All @@ -68,5 +62,3 @@ def test_add_bank_account(self, mocked_add_token):

response = self.client.add_bank_account(data)
self.assertEqual(response.status_code, 200, msg=response.data)
self.assertIsInstance(response.instance, BankAccount)
self.assertEqual(response.instance.id, "foo")
5 changes: 0 additions & 5 deletions tests/wrapper/test_buyer_methods.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pycpfcnpj import gen

from tests.utils import APITestCase
from zoop_wrapper.models.buyer import Buyer
from tests.factories.buyer import BuyerFactory


Expand Down Expand Up @@ -52,8 +51,6 @@ def test_retrieve_buyer(self):
response = self.client.retrieve_buyer("foo")
self.assertEqual(response.status_code, 200, msg=response.data)
self.assertEqual(response.data.get("id"), "foo")
self.assertIsInstance(response.instance, Buyer)
self.assertEqual(response.instance.id, "foo")

def test_remove_buyer(self):
"""
Expand All @@ -74,8 +71,6 @@ def test_search_buyer(self):
response = self.client.search_buyer("bar")
self.assertEqual(response.status_code, 200, msg=response.data)
self.assertEqual(response.data.get("id"), "foo")
self.assertIsInstance(response.instance, Buyer)
self.assertEqual(response.instance.id, "foo")

def test_update_buyer(self):
self.set_put_mock(201, BuyerFactory(id="1").to_dict())
Expand Down
5 changes: 0 additions & 5 deletions tests/wrapper/test_card_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from ..factories.card import CardFactory
from ..factories.seller import SellerFactory
from ..factories.token import CardTokenFactory, CreateCardTokenFactory
from zoop_wrapper.models.card import Card
from zoop_wrapper.exceptions import ValidationError


Expand All @@ -21,8 +20,6 @@ def test_retrieve_card(self):
response = self.client.list_bank_accounts_by_seller("foo")
self.assertEqual(response.status_code, 200, msg=response.data)
self.assertEqual(response.data.get("id"), "foo")
self.assertIsInstance(response.instance, Card)
self.assertEqual(response.instance.id, "foo")

def test_add_card_token(self):
"""
Expand Down Expand Up @@ -52,8 +49,6 @@ def test_add_card(self, mocked_add_token):

response = self.client.add_card(data, "bar")
self.assertEqual(response.status_code, 200, msg=response.data)
self.assertIsInstance(response.instance, Card)
self.assertEqual(response.instance.id, "foo")

@patch("zoop_wrapper.wrapper.ZoopWrapper._CardWrapper__add_card_token")
def test_add_card_buyer(self, mocked_add_token):
Expand Down
18 changes: 0 additions & 18 deletions tests/wrapper/test_requests_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,3 @@ def test_process_response_error_reasons(self):
{"error": {"message": "foo", "reasons": ["bla bla bla"]}},
)
self.assertEqual(processed_response.reason, "foo ['bla bla bla']")

def test_process_response_resource(self):
response = self.build_response_mock(content={"resource": "test"})

processed_response = self.client._RequestsWrapper__process_response(response)
self.assertIsNone(processed_response.instance)

def test_process_response_resource_list(self):
response = self.build_response_mock(
content={
"resource": "list",
"items": [{"resource": "test", "message": "foo"}],
}
)

processed_response = self.client._RequestsWrapper__process_response(response)
self.assertEqual(len(processed_response.instances), 1)
self.assertEqual(processed_response.instances, [None])
7 changes: 0 additions & 7 deletions tests/wrapper/test_seller_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from tests.utils import APITestCase
from tests.factories.seller import BusinessSellerFactory, IndividualSellerFactory
from tests.factories.bank_account import IndividualBankAccountFactory
from zoop_wrapper.models.seller import Seller


class ZoopWrapperSellerMethodsTestCase(APITestCase):
Expand All @@ -28,8 +27,6 @@ def test_retrieve_seller(self):
response = self.client.retrieve_seller("foo")
self.assertEqual(response.status_code, 200, msg=response.data)
self.assertEqual(response.data.get("id"), "foo")
self.assertIsInstance(response.instance, Seller)
self.assertEqual(response.instance.id, "foo")

def test_search_individual_seller(self):
"""
Expand All @@ -40,8 +37,6 @@ def test_search_individual_seller(self):
response = self.client.search_individual_seller("bar")
self.assertEqual(response.status_code, 200, msg=response.data)
self.assertEqual(response.data.get("id"), "foo")
self.assertIsInstance(response.instance, Seller)
self.assertEqual(response.instance.id, "foo")

def test_search_business_seller(self):
"""
Expand All @@ -52,8 +47,6 @@ def test_search_business_seller(self):
response = self.client.search_business_seller("bar")
self.assertEqual(response.status_code, 200, msg=response.data)
self.assertEqual(response.data.get("id"), "foo")
self.assertIsInstance(response.instance, Seller)
self.assertEqual(response.instance.id, "foo")

def test_add_individual_seller(self):
self.set_post_mock(201, {})
Expand Down
19 changes: 3 additions & 16 deletions tests/wrapper/test_transactions_methods.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from unittest.mock import patch

from tests.utils import APITestCase
from zoop_wrapper.models.transaction import Transaction, Source
from zoop_wrapper.models.base import PaymentMethod
from tests.factories.transaction import (
CancelTransactionCardFactory,
TransactionBoletoFactory,
TransactionCreditFactory,
)
from zoop_wrapper.models.token import Token
from zoop_wrapper.exceptions import ValidationError


Expand Down Expand Up @@ -46,8 +43,6 @@ def test_retrieve_transaction(self):
response = self.client.retrieve_transaction("foo")
self.assertEqual(response.status_code, 200, msg=response.data)
self.assertEqual(response.data.get("id"), "foo")
self.assertIsInstance(response.instance, Transaction)
self.assertEqual(response.instance.id, "foo")

def test_add_transaction_invoice(self):
self.set_post_mock(201, TransactionBoletoFactory().to_dict())
Expand All @@ -74,8 +69,6 @@ def test_add_transaction_invoice(self):

response = self.client.add_transaction(data)
self.assertEqual(response.status_code, 201, msg=response.data)
self.assertEqual(response.instance.payment_type, "boleto")
self.assertIsInstance(response.instance.payment_method, PaymentMethod)

def test_add_transaction_card_present(self):
self.set_post_mock(201, TransactionCreditFactory().to_dict())
Expand Down Expand Up @@ -107,9 +100,6 @@ def test_add_transaction_card_present(self):

response = self.client.add_transaction(data)
self.assertEqual(response.status_code, 201, msg=response.data)
self.assertEqual(response.instance.payment_type, "credit")
self.assertIsInstance(response.instance.source.card, Token)
self.assertIsInstance(response.instance.source, Source)

def test_add_transaction_card_not_present(self):
self.set_post_mock(201, TransactionCreditFactory().to_dict())
Expand Down Expand Up @@ -138,9 +128,6 @@ def test_add_transaction_card_not_present(self):

response = self.client.add_transaction(data)
self.assertEqual(response.status_code, 201, msg=response.data)
self.assertEqual(response.instance.payment_type, "credit")
self.assertIsInstance(response.instance.source.card, Token)
self.assertIsInstance(response.instance.source, Source)

def test__capture_or_void_transaction(self):
"""
Expand All @@ -159,7 +146,7 @@ def test__capture_or_void_transaction(self):
t1 = TransactionCreditFactory(id="1", allow_empty=True)

mocked_retrieve_transaction.return_value = self.build_response_mock(
200, instance=t1
200, data={"amount": t1.amount, "on_behalf_of": t1.on_behalf_of}
)

response = self.client._capture_or_void_transaction(t1.id, "void")
Expand Down Expand Up @@ -191,7 +178,7 @@ def test__capture_or_void_transaction_amount(self):
t1 = TransactionCreditFactory(id="1", amount=10000, allow_empty=True)

mocked_retrieve_transaction.return_value = self.build_response_mock(
200, instance=t1
200, data={"amount": t1.amount, "on_behalf_of": t1.on_behalf_of}
)

response = self.client._capture_or_void_transaction(t1.id, "void", 100.00)
Expand Down Expand Up @@ -224,7 +211,7 @@ def test__capture_or_void_transaction_amount_invalid(self):
t1 = TransactionCreditFactory(id="1", amount=10000, allow_empty=True)

mocked_retrieve_transaction.return_value = self.build_response_mock(
200, instance=t1
200, data={"amount": t1.amount, "on_behalf_of": t1.on_behalf_of}
)

with self.assertRaises(ValidationError) as error_context:
Expand Down
2 changes: 0 additions & 2 deletions tests/wrapper/test_webhook_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ def test_retrieve_webhook(self):
response = self.client.retrieve_webhook("foo")
self.assertEqual(response.status_code, 200, msg=response.data)
self.assertEqual(response.data.get("id"), "foo")
self.assertIsInstance(response.instance, Webhook)
self.assertEqual(response.instance.id, "foo")

self.mocked_get.assert_called_once_with(
f"{self.base_url}/webhooks/foo/", auth=self.auth
Expand Down
2 changes: 0 additions & 2 deletions zoop_wrapper/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ class ZoopResponse(Response):
Attributes:
data (dict): json da resposta
instance (:class:`.ResourceModel`): instância do recurso
instances (lista de :class:`.ResourceModel`): lista de instâncias do recurso
"""
Loading

0 comments on commit e7427fd

Please sign in to comment.