Skip to content

Commit 439b06a

Browse files
committed
tests
1 parent 0493dab commit 439b06a

12 files changed

+265
-75
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ coverage.xml
1515
/.python-version
1616

1717
prueba-cert.pem
18+
19+
htmlcov/

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ newrelic==6.2.0.156
1010
pandas==1.2.4
1111
python-hosts==1.0.1
1212
sentry-sdk==1.14.0
13-
stpmex==3.12.0
13+
stpmex==3.13.0
1414
importlib-metadata==4.13.0

speid/exc.py

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ class TransactionNeedManualReviewError(Exception):
2828
"""
2929

3030
speid_id: str
31+
error: str

speid/models/transaction.py

+9-20
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,9 @@ def is_valid_account(self) -> bool:
190190
return is_valid
191191

192192
def fetch_stp_status(self) -> STPEstado:
193-
# fecha_operacion = None
194-
# if (
195-
# self.created_at_fecha_operacion
196-
# < Transaction.current_fecha_operacion()
197-
# ):
198-
# fecha_operacion = self.created_at_fecha_operacion
199-
200193
stp_order = stpmex_client.ordenes_v2.consulta_clave_rastreo_enviada(
201194
clave_rastreo=self.clave_rastreo,
202-
fecha_operacion=self.created_at_fecha_operacion
203-
if self.created_at_fecha_operacion
204-
< Transaction.current_fecha_operacion()
205-
else None,
195+
fecha_operacion=self.created_at_fecha_operacion,
206196
)
207197
return stp_order.estado
208198

@@ -216,7 +206,10 @@ def update_stp_status(self) -> None:
216206
return
217207

218208
if self.stp_id and not status:
219-
raise TransactionNeedManualReviewError(self.speid_id)
209+
raise TransactionNeedManualReviewError(
210+
self.speid_id,
211+
f'Can not retrieve transaction stp_id: {self.stp_id}',
212+
)
220213
elif not self.stp_id and not status:
221214
self.set_state(Estado.failed)
222215
self.save()
@@ -227,11 +220,13 @@ def update_stp_status(self) -> None:
227220
self.set_state(Estado.succeeded)
228221
self.save()
229222
elif status is STPEstado.autorizada:
230-
pass
223+
return
231224
else:
232225
# Cualquier otro caso se debe revisar manualmente y aplicar
233226
# el fix correspondiente
234-
raise TransactionNeedManualReviewError(self.speid_id)
227+
raise TransactionNeedManualReviewError(
228+
self.speid_id, f'Unhandled stp status: {status}'
229+
)
235230

236231
def create_order(self) -> Orden:
237232
# Validate account has already been created
@@ -312,9 +307,3 @@ def create_order(self) -> Orden:
312307
self.estado = Estado.submitted
313308
self.save()
314309
return order
315-
316-
@staticmethod
317-
def current_fecha_operacion() -> dt.date:
318-
utcnow = dt.datetime.utcnow().replace(tzinfo=pytz.utc)
319-
cdmx_time = utcnow.astimezone(pytz.timezone('America/Mexico_City'))
320-
return get_next_business_day(cdmx_time)

speid/tasks/accounts.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from mongoengine import DoesNotExist
22
from pydantic import ValidationError
33
from sentry_sdk import capture_exception
4-
from stpmex.exc import DuplicatedAccount, InvalidRfcOrCurp, StpmexException
4+
from stpmex.exc import InvalidRfcOrCurp, StpmexException
55
from stpmex.resources.cuentas import Cuenta
66

77
from speid.models import Event, PhysicalAccount
@@ -45,10 +45,7 @@ def execute_create_account(account_dict: dict):
4545
if account.estado is Estado.succeeded:
4646
return
4747

48-
try:
49-
account.create_account()
50-
except DuplicatedAccount:
51-
...
48+
account.create_account()
5249

5350

5451
@celery.task(bind=True, max_retries=0)

speid/tasks/transactions.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
from celery.exceptions import MaxRetriesExceededError
77
from cep.exc import CepError, MaxRequestError
88
from mongoengine import DoesNotExist
9-
from pydantic import ValidationError
109
from stpmex.business_days import (
1110
current_cdmx_time_zone,
1211
get_next_business_day,
1312
get_prior_business_day,
1413
)
15-
from stpmex.exc import EmptyResultsError
14+
from stpmex.exc import EmptyResultsError, InvalidFutureDateError
1615

1716
from speid.helpers import callback_helper
1817
from speid.helpers.transaction_helper import (
@@ -146,11 +145,7 @@ def send_transaction_status(self, transaction_id: str, state: str) -> None:
146145

147146
@celery.task
148147
def check_deposits_status(deposit: Dict) -> None:
149-
try:
150-
req = DepositStatusQuery(**deposit)
151-
except ValidationError:
152-
return
153-
148+
req = DepositStatusQuery(**deposit)
154149
try:
155150
transaction = Transaction.objects.get(
156151
clave_rastreo=req.clave_rastreo,
@@ -175,13 +170,11 @@ def check_deposits_status(deposit: Dict) -> None:
175170
recibida = (
176171
stpmex_client.ordenes_v2.consulta_clave_rastreo_recibida(
177172
clave_rastreo=req.clave_rastreo,
178-
fecha_operacion=fecha_operacion
179-
if Transaction.current_fecha_operacion() > fecha_operacion
180-
else None,
173+
fecha_operacion=fecha_operacion,
181174
)
182175
)
183-
except EmptyResultsError:
184-
...
176+
except (InvalidFutureDateError, EmptyResultsError):
177+
continue
185178
else:
186179
if (
187180
recibida.tipoPago in REFUNDS_PAYMENTS_TYPES

tests/conftest.py

+30
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
SEND_STATUS_TRANSACTION_TASK = os.environ['SEND_STATUS_TRANSACTION_TASK']
1616

1717

18+
@pytest.fixture
19+
def client():
20+
app.testing = True
21+
client = app.test_client()
22+
return client
23+
24+
1825
@pytest.fixture
1926
def runner():
2027
runner = FlaskCliRunner(app)
@@ -57,6 +64,29 @@ def outcome_transaction() -> Generator[Transaction, None, None]:
5764
transaction.delete()
5865

5966

67+
@pytest.fixture
68+
def default_income_transaction():
69+
return dict(
70+
Clave=2456303,
71+
FechaOperacion=20210618,
72+
InstitucionOrdenante=40012,
73+
InstitucionBeneficiaria=90646,
74+
ClaveRastreo="PRUEBATAMIZI1",
75+
Monto=100.0,
76+
NombreOrdenante="BANCO",
77+
TipoCuentaOrdenante=40,
78+
CuentaOrdenante="846180000500000008",
79+
RFCCurpOrdenante="ND",
80+
NombreBeneficiario="TAMIZI",
81+
TipoCuentaBeneficiario=40,
82+
CuentaBeneficiario="646180157000000004",
83+
RFCCurpBeneficiario="ND",
84+
ConceptoPago="PRUEBA",
85+
ReferenciaNumerica=2423,
86+
Empresa="TAMIZI",
87+
)
88+
89+
6090
@pytest.fixture
6191
def physical_account():
6292
# Pongo los import aquí porque de otra forma no puedo hacer tests del
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
interactions:
2+
- request:
3+
body: '{"monto": 10.0, "conceptoPago": "PRUEBA 8060", "cuentaBeneficiario": "072691004495711499",
4+
"nombreBeneficiario": "Pablo Sanchez", "institucionContraparte": "40072", "cuentaOrdenante":
5+
"646180157018613700", "nombreOrdenante": "BANCO", "institucionOperante": "90646",
6+
"tipoCuentaBeneficiario": 40, "tipoCuentaOrdenante": 40, "claveRastreo": "CR1698363753",
7+
"referenciaNumerica": 8409977, "rfcCurpBeneficiario": "ND", "rfcCurpOrdenante":
8+
"ND", "prioridad": 1, "medioEntrega": 3, "tipoPago": 1, "topologia": "T", "firma":
9+
"WQ10pllVAc1vE7SK/yKJx9CFfOOPVzlcPfepVO998T69wDI+qNo4uWjd8CuxbF74zFd2F3oH5G6MgDKbdVNGgUifVZSSUNS8IeSQ5edymahP6b+NmBX0idmdJpVzrhWpxf1+9FqUgrBK8gYYEqjeIf+sYntj+4q5TspjuUnebgk=",
10+
"empresa": "TAMIZI"}'
11+
headers:
12+
Accept:
13+
- '*/*'
14+
Accept-Encoding:
15+
- gzip, deflate
16+
Connection:
17+
- keep-alive
18+
Content-Length:
19+
- '714'
20+
Content-Type:
21+
- application/json
22+
User-Agent:
23+
- stpmex-python/3.13.0
24+
method: PUT
25+
uri: https://demo.stpmex.com:7024/speiws/rest/ordenPago/registra
26+
response:
27+
body:
28+
string: '{"resultado":{"id":21787172}}'
29+
headers:
30+
Content-Length:
31+
- '29'
32+
Content-Type:
33+
- application/json
34+
Date:
35+
- Thu, 26 Oct 2023 23:42:34 GMT
36+
X-ORACLE-DMS-ECID:
37+
- bc722c26-d789-4f18-88dc-059072b5d031-00016096
38+
X-ORACLE-DMS-RID:
39+
- '0'
40+
status:
41+
code: 200
42+
message: OK
43+
version: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
interactions:
2+
- request:
3+
body: '{"monto": 10.0, "conceptoPago": "PRUEBA 7243", "cuentaBeneficiario": "072691004495711499",
4+
"nombreBeneficiario": "Pablo Sanchez", "institucionContraparte": "40072", "cuentaOrdenante":
5+
"646180157018613700", "nombreOrdenante": "BANCO", "institucionOperante": "90646",
6+
"tipoCuentaBeneficiario": 40, "tipoCuentaOrdenante": 40, "claveRastreo": "CR1698365494",
7+
"referenciaNumerica": 6224447, "rfcCurpBeneficiario": "ND", "rfcCurpOrdenante":
8+
"ND", "prioridad": 1, "medioEntrega": 3, "tipoPago": 1, "topologia": "T", "firma":
9+
"uWRUIURdRE75pP1XXTdFRNchxN+w537JYmqZvL/2+GjujhkL3z9tqxb5I48ZUbAnsT8F9Waur9gOR25ARbCCkYO6JbsObUVgNwDW5WQhl3I1O8G6W3PMX77m6k+ZXnbdx0ynBYrQfHquIKETl5RPiWx52w9xfZWhaVG9rQg8vNE=",
10+
"empresa": "TAMIZI"}'
11+
headers:
12+
Accept:
13+
- '*/*'
14+
Accept-Encoding:
15+
- gzip, deflate
16+
Connection:
17+
- keep-alive
18+
Content-Length:
19+
- '714'
20+
Content-Type:
21+
- application/json
22+
User-Agent:
23+
- stpmex-python/3.13.0
24+
method: PUT
25+
uri: https://demo.stpmex.com:7024/speiws/rest/ordenPago/registra
26+
response:
27+
body:
28+
string: '{"resultado":{"id":21787203}}'
29+
headers:
30+
Content-Length:
31+
- '29'
32+
Content-Type:
33+
- application/json
34+
Date:
35+
- Fri, 27 Oct 2023 00:11:36 GMT
36+
X-ORACLE-DMS-ECID:
37+
- bc722c26-d789-4f18-88dc-059072b5d031-00016134
38+
X-ORACLE-DMS-RID:
39+
- '0'
40+
status:
41+
code: 200
42+
message: OK
43+
- request:
44+
body: '{"empresa": "TAMIZI", "claveRastreo": "CR1698365494", "tipoOrden": "E",
45+
"fechaOperacion": "20231027", "firma": "wzk7xxPDg9sHF04wXGMGALdr+7RSb6TQWm7ALO49Wx/kBGIXLfWzqzriifIhyrfNeJk5AyDYcm2uTCU2a4gKicjpXHuyyiEzQzx3tVkI7Vk5gTvY66Zn4uOE7OwaqbElc4an6uIosYNkoqtX+QPBs3y8MGFqIQjr42mbQBPSkDk="}'
46+
headers:
47+
Accept:
48+
- '*/*'
49+
Accept-Encoding:
50+
- gzip, deflate
51+
Connection:
52+
- keep-alive
53+
Content-Length:
54+
- '286'
55+
Content-Type:
56+
- application/json
57+
User-Agent:
58+
- stpmex-python/3.13.0
59+
method: POST
60+
uri: https://efws-dev.stpmex.com/efws/API/consultaOrden
61+
response:
62+
body:
63+
string: '{"estado":0,"mensaje":"Datos consultados correctamente","respuesta":{"idEF":21787203,"claveRastreo":"CR1698365494","conceptoPago":"PRUEBA
64+
7243","cuentaBeneficiario":"072691004495711499","cuentaOrdenante":"646180157018613700","empresa":"TAMIZI","estado":"L","fechaOperacion":20231027,"institucionContraparte":40072,"institucionOperante":90646,"medioEntrega":3,"monto":10.00,"nombreBeneficiario":"Pablo
65+
Sanchez","nombreOrdenante":"JUAN PEREZ PEREZ","nombreCep":null,"rfcCep":null,"sello":"ezdNCEax5YmpqHVNYFny4Ddd0PAXvyUqItMsUy8S7BMoQgoP4+AHGmaLqPsoLDjFadZF/fqTaJqI8kKCeQCPJg==","rfcCurpBeneficiario":"ND","referenciaNumerica":6224447,"rfcCurpOrdenante":"PEPJ800101HCSPRL02","tipoCuentaBeneficiario":40,"tipoCuentaOrdenante":40,"tipoPago":1,"tsCaptura":1698365496834,"tsLiquidacion":null,"causaDevolucion":null,"urlCEP":null}}'
66+
headers:
67+
Connection:
68+
- keep-alive
69+
Content-Type:
70+
- application/json
71+
Date:
72+
- Fri, 27 Oct 2023 00:11:44 GMT
73+
Server:
74+
- nginx
75+
Transfer-Encoding:
76+
- chunked
77+
Vary:
78+
- Origin
79+
- Access-Control-Request-Method
80+
- Access-Control-Request-Headers
81+
status:
82+
code: 200
83+
message: OK
84+
version: 1

0 commit comments

Comments
 (0)