Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
new test:
compare TransactionDTO's in mappings to TransactionDTO's in model.
  • Loading branch information
axshani committed May 9, 2022
commit d395624a39226dd52840e30515798f4c2b70f3c9
29 changes: 26 additions & 3 deletions e2e_tests/transaction_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest
from unit import Unit
from unit.models.transaction import *
from unit.models.codecs import mappings

token = os.environ.get('TOKEN')
client = Unit("https://api.s.unit.sh", token)
Expand Down Expand Up @@ -89,7 +90,6 @@ def test_sending_wire_transaction():
assert transaction.attributes["counterparty"].routing_number == "812345678"
assert transaction.attributes["referenceForBeneficiary"] == "Test"


def test_receiving_wire_transaction():
wire_transaction_api_response = {
"type": "wireTransaction",
Expand Down Expand Up @@ -151,7 +151,6 @@ def test_receiving_wire_transaction():
assert transaction.attributes["counterparty"].routing_number == "812345678"
assert transaction.attributes["senderReference"] == "Test"


def test_card_transaction():
card_transaction_api_response = {
"type": "cardTransaction",
Expand Down Expand Up @@ -335,7 +334,6 @@ def test_purchase_transaction():
assert transaction.attributes["digitalWallet"] == "Apple"
assert transaction.attributes["paymentMethod"] == "Contactless"


def test_list_and_get_transactions_with_type():
transaction_ids = []
response = client.transactions.list(ListTransactionParams(100, 0, type=["Fee", "ReceivedAch"]))
Expand All @@ -348,3 +346,28 @@ def test_list_and_get_transactions_with_type():
response = client.transactions.get(id)
assert response.data.type == "receivedAchTransaction" or response.data.type == "feeTransaction"


def test_codecs_transactions():
import inspect
import unit.models.transaction as foo

classes = []

p = 'unit.models.transaction.'
for name, obj in inspect.getmembers(foo):
if inspect.isclass(obj):
try:
s = str(obj)
if 'Transaction' in s and 'DTO' in s and 'Base' not in s:
i = s.index(p) + len(p)
j = s.index('DTO\'>')
classes.append(s[i:j])
except e:
print(e)
continue


transactions = [x.lower() for x in mappings if "Transaction" in x]
Copy link
Collaborator

@chita13 chita13 May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can just compare the length? and that also higher than zero

for c in classes:
if c.lower() not in transactions:
assert False
3 changes: 3 additions & 0 deletions unit/models/codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
"repaidPaymentAdvanceTransaction": lambda _id, _type, attributes, relationships:
RepaidPaymentAdvanceTransactionDTO.from_json_api(_id, _type, attributes, relationships),

"cardReversalTransaction": lambda _id, _type, attributes, relationships:
CardReversalTransactionDTO.from_json_api(_id, _type, attributes, relationships),

"achPayment": lambda _id, _type, attributes, relationships:
AchPaymentDTO.from_json_api(_id, _type, attributes, relationships),

Expand Down