Skip to content

Commit

Permalink
fix: update payment object mock
Browse files Browse the repository at this point in the history
  • Loading branch information
mubbsharanwar committed Dec 19, 2024
1 parent 5871d37 commit efb1f81
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def get_edx_successful_payment_info(order: CTOrder):
for pr in order.payment_info.payments:
pmt = pr.obj
if pmt.payment_status.interface_code == PAYMENT_STATUS_INTERFACE_CODE_SUCCEEDED and pmt.interface_id:
return pmt, pmt.payment_method_info.payment_interface
ct_payment_provider_id = pmt.payment_method_info.payment_interface
return pmt, ct_payment_provider_id
return None, None


Expand Down
3 changes: 2 additions & 1 deletion commerce_coordinator/apps/commercetools/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ def run_filter(self, active_order_management_system, order_number, **kwargs): #
log.info(f"[Performance Check] get_order_by_number call took {duration} seconds")

payment, psp = get_edx_successful_payment_info(ct_order)
ct_payment_provider_id = payment.interface_id if payment else None

ret_val = {
"order_data": ct_order,
"psp": psp,
"payment_intent_id": payment.interface_id if payment else None
"payment_intent_id": ct_payment_provider_id
}

return ret_val
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Commercetools Task Tests"""
import logging
from unittest import TestCase, skip
from unittest import TestCase
from unittest.mock import MagicMock, call, patch

from commercetools.platform.models import MoneyType as CTMoneyType
from commercetools.platform.models import Order as CTOrder
from commercetools.platform.models import ReturnInfo as CTReturnInfo
from commercetools.platform.models import ReturnPaymentState as CTReturnPaymentState
from commercetools.platform.models import TypedMoney as CTTypedMoney
from edx_django_utils.cache import TieredCache

from commerce_coordinator.apps.commercetools.clients import CommercetoolsAPIClient
Expand Down Expand Up @@ -252,6 +254,18 @@ def setUp(self):
self.mock.update_return_payment_state_after_successful_refund
}
)
# TODO: Properly mock the Payment object.
payment = self.mock.get_payment_by_key.return_value
amount = CTTypedMoney(
currency_code='USD',
cent_amount=1000,
type=CTMoneyType.CENT_PRECISION,
fraction_digits=2,
)
for transaction in payment.transactions:
transaction.amount = amount

self.payment_mock = payment

def tearDown(self):
MonkeyPatch.unmonkey(CommercetoolsAPIClient)
Expand All @@ -270,35 +284,23 @@ def unpack_for_uut(values):
def get_uut():
return fulfill_order_returned_uut

# TODO: Fix this test. It is failing because of the way the mock is set up.
@patch('commerce_coordinator.apps.commercetools.sub_messages.tasks.is_edx_lms_order')
@patch('commerce_coordinator.apps.stripe.pipeline.StripeAPIClient')
@patch.object(CommercetoolsAPIClientMock, 'payment_mock', new_callable=MagicMock)
@skip(reason="It is failing because of the way the mock is set up.")
def test_correct_arguments_passed_already_refunded_doest_break(
self,
_stripe_api_mock,
_lms_signal,
custom_payment_mock
):
def test_correct_arguments_passed_already_refunded_doest_break(self, _stripe_api_mock, _lms_signal):
"""
Check calling uut with mock_parameters yields call to client with
expected_data.
"""
mock_values = self.mock
custom_payment_mock.return_value = CTPaymentByKey()

ret_val = self.get_uut()(*self.unpack_for_uut(self.mock.example_payload))

self.assertTrue(ret_val)
mock_values.order_mock.assert_has_calls([call(mock_values.order_id), call(order_id=mock_values.order_id)])
mock_values.customer_mock.assert_called_once_with(mock_values.customer_id)

# TODO: Fix this test. It is failing because of the way the mock is set up.
@patch('commerce_coordinator.apps.commercetools.sub_messages.tasks.is_edx_lms_order')
@patch('commerce_coordinator.apps.stripe.pipeline.StripeAPIClient')
@patch('commerce_coordinator.apps.commercetools.clients.CommercetoolsAPIClient.create_return_for_order')
@skip(reason="It is failing because of the way the mock is set up.")
def test_correct_arguments_passed_valid_stripe_refund(
self,
_return_order_mock: MagicMock,
Expand Down

0 comments on commit efb1f81

Please sign in to comment.