Skip to content

Commit

Permalink
fix: coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
JadeyOlivier committed Jul 15, 2024
1 parent 310d528 commit 66b0ab2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commerce_coordinator/apps/commercetools/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def run_filter(
f"[order_id: {order_id}, order_line_item_id: {order_line_item_id}")
log.exception(f"[{type(self).__name__}] Commercetools Error: {err}, {err.errors}")
raise OpenEdxFilterException(str(err)) from err
except HTTPError as err:
except HTTPError as err: # pragma no cover
log.info(f"[{tag}] Unsuccessful attempt to create order return with details: "
f"[order_id: {order_id}, order_line_item_id: {order_line_item_id}")
log.exception(f"[{type(self).__name__}] HTTP Error: {err}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,30 @@ def test_correct_arguments_passed_valid_stripe_refund(
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)
_stripe_api_mock.return_value.refund_payment_intent.assert_called_once()


@patch('commerce_coordinator.apps.commercetools.sub_messages.tasks.send_refund_notification')
@patch('commerce_coordinator.apps.commercetools.sub_messages.tasks.get_edx_payment_intent_id')
@patch('commerce_coordinator.apps.commercetools.sub_messages.tasks.logger.debug')
@patch('commerce_coordinator.apps.commercetools.sub_messages.tasks.OrderRefundRequested.run_filter')
def test_correct_arguments_passed_valid_stripe_refund(
self,
_return_filter_mock: MagicMock,
_mock_logger,
_mock_payment_intent: MagicMock,
_mock_zendesk: MagicMock
):
"""
Check calling uut with mock_parameters yields call to client with
expected_data.
"""
mock_values = self.mock
mock_values.order_mock.return_value.return_info = []
_return_filter_mock.return_value = {'refund_response': 'charge_already_refunded'}
_mock_payment_intent.return_value = 'mock_payment_intent_id'


self.get_uut()(*self.unpack_for_uut(self.mock.example_payload))
_mock_logger.assert_called_with(f'[CT-fulfill_order_returned_signal_task] payment intent mock_payment_intent_id already '
f'has refund transaction, sending Zendesk email')
_mock_zendesk.assert_called_once()
15 changes: 15 additions & 0 deletions commerce_coordinator/apps/commercetools/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ def test_commercetools_transaction_create_no_payment_data(self, mock_returned_pa
self.assertEqual(mock_payment_result, self.returned_payment)
self.assertEqual(mock_payment_result.transactions[0].type, TransactionType.REFUND)

@patch('commerce_coordinator.apps.commercetools.utils.has_refund_transaction')
@patch('commerce_coordinator.apps.commercetools.pipeline.log.info')
def test_commercetools_transaction_create_has_refund(self, mock_logger, mock_has_refund):
mock_has_refund.return_value = True

refund_pipe = CreateReturnPaymentTransaction("test_pipe", None)
refund_pipe.run_filter(
payment_data=self.mock_response_payment,
refund_response="charge_already_refunded",
active_order_management_system=COMMERCETOOLS_ORDER_MANAGEMENT_SYSTEM,
has_been_refunded=True
)
mock_logger.assert_called_once_with('[CreateReturnPaymentTransaction] refund has already been processed, '
'skipping refund payment transaction creation')


class OrderReturnPipelineTests(TestCase):
"""Commercetools pipeline testcase for order updates on returns"""
Expand Down

0 comments on commit 66b0ab2

Please sign in to comment.