Skip to content

Commit

Permalink
add exc
Browse files Browse the repository at this point in the history
  • Loading branch information
felipao-mx committed Nov 10, 2023
1 parent 88ce126 commit 84a5381
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion speid/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TransactionNeedManualReviewError(Exception):
error: str


class DuplicatedTransaction(Exception):
class DuplicatedTransactionError(Exception):
"""
Duplicated transactions are not allowed
"""
12 changes: 7 additions & 5 deletions speid/tasks/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import clabe
import luhnmod10
from mongoengine import DoesNotExist
from mongoengine import DoesNotExist, NotUniqueError
from pydantic import ValidationError
from sentry_sdk import capture_exception
from stpmex.exc import (
Expand All @@ -17,7 +17,7 @@
)

from speid.exc import (
DuplicatedTransaction,
DuplicatedTransactionError,
MalformedOrderException,
ResendSuccessOrderException,
ScheduleError,
Expand Down Expand Up @@ -58,7 +58,7 @@ def send_order(self, order_val: dict):
MalformedOrderException,
ResendSuccessOrderException,
TransactionNeedManualReviewError,
DuplicatedTransaction,
DuplicatedTransactionError,
) as exc:
capture_exception(exc)
except ScheduleError:
Expand Down Expand Up @@ -97,8 +97,10 @@ def execute(order_val: dict):
transaction.events.append(Event(type=EventType.retry))
except DoesNotExist:
transaction.events.append(Event(type=EventType.created))
transaction.save()

try:
transaction.save()
except NotUniqueError:
raise DuplicatedTransactionError
except AssertionError:
# Se hace un reenvío del estado de la transferencia
# transaction.set_state(Estado.succeeded)
Expand Down
5 changes: 3 additions & 2 deletions tests/tasks/test_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest
from freezegun import freeze_time
from mongoengine import DoesNotExist, NotUniqueError
from mongoengine import DoesNotExist
from stpmex.exc import (
AccountDoesNotExist,
BankCodeClabeMismatch,
Expand All @@ -18,6 +18,7 @@
)

from speid.exc import (
DuplicatedTransactionError,
MalformedOrderException,
ResendSuccessOrderException,
ScheduleError,
Expand Down Expand Up @@ -95,7 +96,7 @@ def test_not_unique_speid_id_are_not_allowed(
clave_rastreo=order['clave_rastreo']
)

with pytest.raises(NotUniqueError), patch(
with pytest.raises(DuplicatedTransactionError), patch(
'speid.tasks.orders.Transaction.create_order'
) as mock_create_order, patch(
# Simulate that in a parallel task execution the order doesn't exist
Expand Down

0 comments on commit 84a5381

Please sign in to comment.