From 781d53e83a7879a99beddb23f233a9d4fd5fa4de Mon Sep 17 00:00:00 2001 From: Paulo Souza Date: Mon, 29 Sep 2025 18:36:34 -0300 Subject: [PATCH] Deprecated create method from transaction resource --- CHANGELOG.md | 2 ++ starkbank/transaction/__transaction.py | 6 +++++- tests/sdk/test_transaction.py | 17 +++++++++-------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b6bfa4f..84d0b823 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/starkbank/transaction/__transaction.py b/starkbank/transaction/__transaction.py index f6568031..2cd91af5 100644 --- a/starkbank/transaction/__transaction.py +++ b/starkbank/transaction/__transaction.py @@ -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): @@ -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): @@ -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): diff --git a/tests/sdk/test_transaction.py b/tests/sdk/test_transaction.py index 4b25aaa2..1b28e66b 100644 --- a/tests/sdk/test_transaction.py +++ b/tests/sdk/test_transaction.py @@ -4,6 +4,7 @@ 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 @@ -11,11 +12,12 @@ 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): @@ -23,7 +25,6 @@ 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) @@ -31,7 +32,7 @@ def test_success_after_before(self): 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): @@ -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: