Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Given a version number MAJOR.MINOR.PATCH, increment:


## [Unreleased]
### Changed
- The create method from the Transaction resource is now deprecated
### Fixed
- workspace name and username patch

Expand Down
6 changes: 5 additions & 1 deletion starkbank/transaction/__transaction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ..utils import rest
from starkcore.utils.resource import Resource
from starkcore.utils.checks import check_datetime, check_date
from starkbank.error import StarkError


class Transaction(Resource):
Expand Down Expand Up @@ -47,6 +48,9 @@ def __init__(self, amount, description, external_id, receiver_id, sender_id=None


def create(transactions, user=None):
"""
Deprecated: Function deprecated since v2.31.0
"""
"""# Create Transactions
Send a list of Transaction objects for creation in the Stark Bank API
## Parameters (required):
Expand All @@ -56,7 +60,7 @@ def create(transactions, user=None):
## Return:
- list of Transaction objects with updated attributes
"""
return rest.post_multi(resource=_resource, entities=transactions, user=user)
raise StarkError([{"code": "deprecated", "message": "Function deprecated since v2.31.0"}])


def get(id, user=None):
Expand Down
17 changes: 9 additions & 8 deletions tests/sdk/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,35 @@
from tests.utils.date import randomPastDate
from tests.utils.transaction import generateExampleTransactionsJson
from tests.utils.user import exampleProject
from starkbank.error import StarkError


starkbank.user = exampleProject


class TestTransactionPost(TestCase):

def test_success(self):
transactions = starkbank.transaction.create(generateExampleTransactionsJson(n=5))
self.assertEqual(len(transactions), 5)
for transaction in transactions:
print(transaction)
def test_deprecated_error(self):
with self.assertRaises(StarkError) as cm:
starkbank.transaction.create(generateExampleTransactionsJson(n=1))

exception = cm.exception
self.assertIn("Function deprecated since v2.31.0", str(exception))


class TestTransactionQuery(TestCase):

def test_success(self):
transactions = list(starkbank.transaction.query(limit=10))
self.assertEqual(len(transactions), 10)
print("Number of transactions:", len(transactions))

def test_success_after_before(self):
after = randomPastDate(days=10)
before = datetime.today()
transactions = list(starkbank.transaction.query(after=after.date(), before=before.date(), limit=10))
self.assertLessEqual(len(transactions), 10)
for transaction in transactions:
print(transaction)
self.assertIsNotNone(transaction.id)


class TestTransactionPage(TestCase):
Expand All @@ -42,7 +43,7 @@ def test_success(self):
for _ in range(2):
transactions, cursor = starkbank.transaction.page(limit=2, cursor=cursor)
for transaction in transactions:
print(transaction)
self.assertIsNotNone(transaction.id)
self.assertFalse(transaction.id in transactionIds)
transactionIds.append(transaction.id)
if cursor is None:
Expand Down
Loading