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
34 changes: 34 additions & 0 deletions test/CheckoutTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ class TestCheckout(unittest.TestCase):
baseUrl = adyen.checkout.payments_api.baseUrl
lib_version = settings.LIB_VERSION

def test_checkout_api_version(self):
checkout_apis = (
self.adyen.checkout.donations_api,
self.adyen.checkout.modifications_api,
self.adyen.checkout.orders_api,
self.adyen.checkout.payment_links_api,
self.adyen.checkout.payments_api,
self.adyen.checkout.recurring_api,
self.adyen.checkout.utility_api,
)

for checkout_api in checkout_apis:
with self.subTest(api=checkout_api.__class__.__name__):
self.assertEqual("https://checkout-test.adyen.com/v72", checkout_api.baseUrl)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The assertion expects the base URL to end with /v72, but PaymentsApi is configured with /v71 in the codebase. This mismatch will cause the test to fail. Please update the assertion to /v71 or ensure the API service classes are updated to /v72.

Suggested change
self.assertEqual("https://checkout-test.adyen.com/v72", checkout_api.baseUrl)
self.assertEqual("https://checkout-test.adyen.com/v71", checkout_api.baseUrl)


def test_payment_methods_success_mocked(self):
request = {"merchantAccount": "YourMerchantAccount"}
self.adyen.client = self.test.create_client_from_file(
Expand Down Expand Up @@ -438,6 +453,25 @@ def test_sessions_error(self):
self.assertEqual("130", result.message["errorCode"])
self.assertEqual("validation", result.message["errorType"])

def test_update_session(self):
request = {"amount": {"currency": "EUR", "value": 1000}}
session_id = "YOUR_SESSION_ID"
self.adyen.client = self.test.create_client_from_file(200, request)
Comment thread
poojah-adyen marked this conversation as resolved.

self.adyen.checkout.payments_api.update_session(request, session_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The update_session method is called on payments_api, but this method is not defined in Adyen/services/checkout/payments_api.py. Running this test will result in an AttributeError. Please ensure that the update_session method is implemented in the PaymentsApi class.


self.adyen.client.http_client.request.assert_called_once_with(
"PATCH",
f"{self.baseUrl}/sessions/{session_id}",
headers={
"adyen-library-name": "adyen-python-api-library",
"adyen-library-version": settings.LIB_VERSION,
"User-Agent": "adyen-python-api-library/" + settings.LIB_VERSION,
},
json=request,
xapikey="YourXapikey",
)

def test_payment_link(self):
request = {
"reference": "YOUR_ORDER_NUMBER",
Expand Down
59 changes: 59 additions & 0 deletions test/TransfersTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,62 @@ def test_get_transaction(self):
json=None,
xapikey="YourXapikey",
)

def test_initiate_cashout(self):
request = {
"instructingBalanceAccountId": "BA00000000000000000000001",
"amount": {"currency": "EUR", "value": 50000},
"counterparty": {"transferInstrumentId": "SE00000000000000000000001"},
"description": "Cashout to bank account",
"referenceForBeneficiary": "CASHOUT-REF-001",
"fee": {"amount": {"currency": "EUR", "value": 500}},
}
self.adyen.client = self.test.create_client_from_file(
200, request, "test/mocks/transfers/initiate-cashout.json"
)
result = self.adyen.transfers.cash_out_api.initiate_cashout(request)
self.assertIsNotNone(result)
self.assertEqual("CO00000000000000000000001", result.message["id"])
self.assertEqual(50000, result.message["amount"]["value"])
self.assertEqual(
["cashoutRepayment", "cashoutFee"],
[transfer["type"] for transfer in result.message["transfers"]],
)

self.adyen.client.http_client.request.assert_called_once_with(
"POST",
f"{self.transfers_url}/cashouts",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using self.transfers_url (which is derived from transfers_api.baseUrl) to assert the endpoint for cash_out_api is fragile and assumes both APIs share the exact same base URL. It is more robust to use self.adyen.transfers.cash_out_api.baseUrl directly.

Suggested change
f"{self.transfers_url}/cashouts",
f"{self.adyen.transfers.cash_out_api.baseUrl}/cashouts",

headers={
"adyen-library-name": "adyen-python-api-library",
"adyen-library-version": settings.LIB_VERSION,
"User-Agent": "adyen-python-api-library/" + settings.LIB_VERSION,
},
json=request,
xapikey="YourXapikey",
)

def test_initiate_cashout_idempotency_key(self):
request = {
"instructingBalanceAccountId": "BA00000000000000000000001",
"amount": {"currency": "EUR", "value": 50000},
"counterparty": {"transferInstrumentId": "SE00000000000000000000001"},
}
self.adyen.client = self.test.create_client_from_file(
200, request, "test/mocks/transfers/initiate-cashout.json"
)
self.adyen.transfers.cash_out_api.initiate_cashout(
request, idempotency_key="test-idempotency-key-001"
)

self.adyen.client.http_client.request.assert_called_once_with(
"POST",
f"{self.transfers_url}/cashouts",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using self.transfers_url (which is derived from transfers_api.baseUrl) to assert the endpoint for cash_out_api is fragile and assumes both APIs share the exact same base URL. It is more robust to use self.adyen.transfers.cash_out_api.baseUrl directly.

Suggested change
f"{self.transfers_url}/cashouts",
f"{self.adyen.transfers.cash_out_api.baseUrl}/cashouts",

headers={
"adyen-library-name": "adyen-python-api-library",
"adyen-library-version": settings.LIB_VERSION,
"User-Agent": "adyen-python-api-library/" + settings.LIB_VERSION,
"Idempotency-Key": "test-idempotency-key-001",
},
json=request,
xapikey="YourXapikey",
)
37 changes: 37 additions & 0 deletions test/mocks/transfers/initiate-cashout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"id": "CO00000000000000000000001",
"instructingBalanceAccountId": "BA00000000000000000000001",
"amount": {
"currency": "EUR",
"value": 50000
},
"counterparty": {
"transferInstrumentId": "SE00000000000000000000001"
},
"description": "Cashout to bank account",
"referenceForBeneficiary": "CASHOUT-REF-001",
"fee": {
"amount": {
"currency": "EUR",
"value": 500
}
},
"transfers": [
{
"id": "400F6060JMB1I0AB",
"type": "cashoutRepayment",
"amount": {
"currency": "EUR",
"value": 50500
}
},
{
"id": "400F6060JMB1I0AA",
"type": "cashoutFee",
"amount": {
"currency": "EUR",
"value": 500
}
}
]
}
Loading