Skip to content

Commit

Permalink
Revert "Speididunique (#424)" (#427)
Browse files Browse the repository at this point in the history
This reverts commit e3b885c.
  • Loading branch information
felipao-mx authored Nov 14, 2023
1 parent e3b885c commit 114de0f
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 94 deletions.
6 changes: 0 additions & 6 deletions speid/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,3 @@ class TransactionNeedManualReviewError(Exception):

speid_id: str
error: str


class DuplicatedTransactionError(Exception):
"""
Duplicated transactions are not allowed
"""
7 changes: 1 addition & 6 deletions speid/models/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class Transaction(Document, BaseModel):
'index_background': True,
'indexes': [
'+stp_id',
'+speid_id',
'+clave_rastreo',
# The Unique-Sparse index skips over any document that is missing
# the indexed field (null values)
Expand All @@ -143,12 +144,6 @@ class Transaction(Document, BaseModel):
'partialFilterExpression': {'tipo': TipoTransaccion.retiro},
},
{'fields': ['+fecha_operacion', '+tipo']},
{
'fields': ['+speid_id'],
'unique': True,
'sparse': True,
'name': 'speid_id_1_unique',
},
],
}

Expand Down
10 changes: 3 additions & 7 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, NotUniqueError
from mongoengine import DoesNotExist
from pydantic import ValidationError
from sentry_sdk import capture_exception
from stpmex.exc import (
Expand All @@ -17,7 +17,6 @@
)

from speid.exc import (
DuplicatedTransactionError,
MalformedOrderException,
ResendSuccessOrderException,
ScheduleError,
Expand Down Expand Up @@ -58,7 +57,6 @@ def send_order(self, order_val: dict):
MalformedOrderException,
ResendSuccessOrderException,
TransactionNeedManualReviewError,
DuplicatedTransactionError,
) as exc:
capture_exception(exc)
except ScheduleError:
Expand Down Expand Up @@ -97,10 +95,8 @@ def execute(order_val: dict):
transaction.events.append(Event(type=EventType.retry))
except DoesNotExist:
transaction.events.append(Event(type=EventType.created))
try:
transaction.save()
except NotUniqueError:
raise DuplicatedTransactionError
transaction.save()
pass
except AssertionError:
# Se hace un reenvío del estado de la transferencia
# transaction.set_state(Estado.succeeded)
Expand Down

This file was deleted.

32 changes: 0 additions & 32 deletions tests/tasks/test_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

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

from speid.exc import (
DuplicatedTransactionError,
MalformedOrderException,
ResendSuccessOrderException,
ScheduleError,
Expand Down Expand Up @@ -84,36 +82,6 @@ def test_malformed_order_worker(order, mock_callback_queue):
assert transaction.estado is Estado.error


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

transaction0 = Transaction.objects.get(
clave_rastreo=order['clave_rastreo']
)

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
'mongoengine.queryset.base.BaseQuerySet.get',
side_effect=DoesNotExist,
):
execute(order)

transaction1 = Transaction.objects.get(
clave_rastreo=order['clave_rastreo']
)
assert transaction0.id == transaction1.id
assert transaction0.estado == transaction1.estado
assert transaction0.speid_id == transaction1.speid_id
mock_create_order.assert_not_called()


@pytest.mark.vcr
def test_create_order_debit_card(order, physical_account):
order['concepto_pago'] = 'DebitCardTest'
Expand Down

0 comments on commit 114de0f

Please sign in to comment.