Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
felipao-mx committed Oct 27, 2023
1 parent 439b06a commit 623caa7
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 5 deletions.
8 changes: 5 additions & 3 deletions speid/tasks/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ def retry_timeout(attempts: int) -> int:
def send_order(self, order_val: dict):
try:
execute(order_val)
except (MalformedOrderException, ResendSuccessOrderException) as exc:
except (
MalformedOrderException,
ResendSuccessOrderException,
TransactionNeedManualReviewError,
) as exc:
capture_exception(exc)
except ScheduleError:
self.retry(countdown=STP_COUNTDOWN)
except TransactionNeedManualReviewError as exc:
capture_exception(exc)
except Exception as exc:
capture_exception(exc)
self.retry(countdown=retry_timeout(self.request.retries))
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def runner():

@pytest.fixture
def mock_callback_queue():
with patch.object(Celery, 'send_task', return_value=None):
yield
with patch.object(Celery, 'send_task', return_value=None) as mock:
yield mock


@pytest.fixture(scope='module')
Expand Down
43 changes: 43 additions & 0 deletions tests/tasks/cassettes/test_retry_transfer_already_failed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
interactions:
- request:
body: '{"monto": 10.0, "conceptoPago": "PRUEBA 8070", "cuentaBeneficiario": "072691004495711499",
"nombreBeneficiario": "Pablo Sanchez", "institucionContraparte": "40072", "cuentaOrdenante":
"646180157018613700", "nombreOrdenante": "BANCO", "institucionOperante": "90646",
"tipoCuentaBeneficiario": 40, "tipoCuentaOrdenante": 40, "claveRastreo": "CR1698366540",
"referenciaNumerica": 9486455, "rfcCurpBeneficiario": "ND", "rfcCurpOrdenante":
"ND", "prioridad": 1, "medioEntrega": 3, "tipoPago": 1, "topologia": "T", "firma":
"dEzSpoMpp+WvzgoYtXcruMMdK0Q/qqsUkwnh8vwOFXaph5e8BitET8Y/HWDa9xfODsNA4u7ChxA19fYhEZVF2FNtDlMb7hv7HgOKda/vHWwWcYtKo9/oUIndnCZecb0+BGgLOqCgOOdp4y9qndDj2bMs/jK27kLYtPrt7nmCt4U=",
"empresa": "TAMIZI"}'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '714'
Content-Type:
- application/json
User-Agent:
- stpmex-python/3.13.0
method: PUT
uri: https://demo.stpmex.com:7024/speiws/rest/ordenPago/registra
response:
body:
string: '{"resultado":{"id":21787417}}'
headers:
Content-Length:
- '29'
Content-Type:
- application/json
Date:
- Fri, 27 Oct 2023 00:29:01 GMT
X-ORACLE-DMS-ECID:
- bc722c26-d789-4f18-88dc-059072b5d031-0001617e
X-ORACLE-DMS-RID:
- '0'
status:
code: 200
message: OK
version: 1
31 changes: 31 additions & 0 deletions tests/tasks/test_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ def test_retry_on_unexpected_exception(
mock_capture_exception.assert_called_once()


@patch(
'speid.tasks.orders.execute',
side_effect=TransactionNeedManualReviewError('sp1', 'error'),
)
@patch('speid.tasks.orders.capture_exception')
def test_doesnt_retry_on_manual_review_exception(
mock_capture_exception: MagicMock, _, order
):
send_order(order)
mock_capture_exception.assert_called_once()


def test_hold_max_amount(order):
order['monto'] = 102000000
with pytest.raises(MalformedOrderException):
Expand Down Expand Up @@ -399,3 +411,22 @@ def test_retry_transfers_with_stp_id_but_unhandled_status(
transaction.reload()
assert transaction.estado is Estado.submitted
mock_registra.assert_not_called()


@pytest.mark.vcr
def test_retry_transfer_already_failed(
order, second_physical_account, mock_callback_queue
):
order['cuenta_ordenante'] = second_physical_account.cuenta
execute(order)

transaction = Transaction.objects.order_by('-created_at').first()
# Changing to error state so we can simulate a failed trx
transaction.estado = Estado.error
transaction.save()
with patch(
'speid.models.transaction.stpmex_client.ordenes.registra'
) as mock_registra:
execute(order)

mock_registra.assert_not_called()

0 comments on commit 623caa7

Please sign in to comment.