Skip to content

Commit d60dbc4

Browse files
author
gabino
committed
Add CepNotAvailableError
1 parent 4bb1e4b commit d60dbc4

7 files changed

+506
-14
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,10 @@ Use the `descargar` method to download a transfer in one of the following format
7676
```python
7777
tr.descargar(formato='XML')
7878
```
79+
80+
## Exceptions
81+
82+
- `NotFoundError`: The transfer was not found.
83+
- `MaxRequestError`: The maximum number of requests has been reached.
84+
- `CepNotAvailableError`: The transfer was found, but the CEP is not available.
85+

cep/exc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ class MaxRequestError(CepError):
1616
Máximo número de peticiones alcanzadas para
1717
obtener el CEP de una transferencia
1818
"""
19+
20+
21+
class CepNotAvailableError(CepError):
22+
"""
23+
La transferencia fue encontrada, pero el CEP no
24+
está disponible.
25+
"""

cep/transferencia.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,26 @@
99

1010
from .client import Client
1111
from .cuenta import Cuenta
12-
from .exc import CepError, MaxRequestError, NotFoundError
12+
from .exc import CepError, CepNotAvailableError, MaxRequestError, NotFoundError
1313

1414
MAX_REQUEST_ERROR_MESSAGE = (
1515
b'Lo sentimos, pero ha excedido el número máximo '
1616
b'de consultas en este portal'
1717
)
1818

19-
NOT_FOUND_ERROR_MESSAGE = (
19+
NO_PAYMENT_ERROR_MESSAGE = (
2020
'No se encontró ningún pago con la información proporcionada'
2121
)
2222

23+
NO_OPERATION_ERROR_MESSAGE = (
24+
'El SPEI no ha recibido una orden de pago que cumpla con el '
25+
'criterio de búsqueda especificado'
26+
)
27+
28+
NO_CEP_ERROR_MESSAGE = (
29+
'Con la información proporcionada se identificó el siguiente pago'
30+
)
31+
2332

2433
@dataclass
2534
class Transferencia:
@@ -149,10 +158,11 @@ def _validar(
149158
receptorParticipante=1 if pago_a_banco else 0,
150159
)
151160
resp = client.post('/valida.do', request_body)
152-
if (
153-
NOT_FOUND_ERROR_MESSAGE in resp.decode('utf-8')
154-
or b'no encontrada' in resp
155-
):
161+
if NO_CEP_ERROR_MESSAGE in resp.decode('utf-8'):
162+
raise CepNotAvailableError
163+
if NO_PAYMENT_ERROR_MESSAGE in resp.decode(
164+
'utf-8'
165+
) or NO_OPERATION_ERROR_MESSAGE in resp.decode('utf-8'):
156166
raise NotFoundError
157167
return client
158168

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
interactions:
2+
- request:
3+
body: tipoCriterio=T&captcha=c&tipoConsulta=1&fecha=08-11-2024&criterio=BiB202411081016248XXX&emisor=37166&receptor=90723&cuenta=723969000011000077&monto=3414.95&receptorParticipante=0
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Connection:
10+
- keep-alive
11+
Content-Length:
12+
- '178'
13+
Content-Type:
14+
- application/x-www-form-urlencoded
15+
User-Agent:
16+
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML,
17+
like Gecko) Chrome/75.0.3770.142 Safari/537.36
18+
method: POST
19+
uri: http://www.banxico.org.mx/cep-beta/valida.do
20+
response:
21+
body:
22+
string: ''
23+
headers:
24+
Connection:
25+
- Keep-Alive
26+
Content-Length:
27+
- '0'
28+
Location:
29+
- https://www.banxico.org.mx/cep-beta/valida.do
30+
Server:
31+
- mxbanxico
32+
status:
33+
code: 307
34+
message: Temporary Redirect
35+
- request:
36+
body: tipoCriterio=T&captcha=c&tipoConsulta=1&fecha=08-11-2024&criterio=BiB202411081016248XXX&emisor=37166&receptor=90723&cuenta=723969000011000077&monto=3414.95&receptorParticipante=0
37+
headers:
38+
Accept:
39+
- '*/*'
40+
Accept-Encoding:
41+
- gzip, deflate
42+
Connection:
43+
- keep-alive
44+
Content-Length:
45+
- '178'
46+
Content-Type:
47+
- application/x-www-form-urlencoded
48+
User-Agent:
49+
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML,
50+
like Gecko) Chrome/75.0.3770.142 Safari/537.36
51+
method: POST
52+
uri: https://www.banxico.org.mx/cep-beta/valida.do
53+
response:
54+
body:
55+
string: "\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1.0,user-scalable=no\"
56+
/>\n<meta charset=\"utf-8\" /> \n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=9;
57+
IE=8; IE=7; IE=edge\" />\n<link rel=\"apple-touch-icon\" href=\"images/icon.png\"/>\n<link
58+
rel=\"shortcut icon\" href=\"images/icon.png\">\n<!--Bootstrap-->\n<!--<link
59+
href=\"//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css\"
60+
rel=\"stylesheet\">\n<link rel=stylesheet href=\"css/bootstrap/bootstrap.min.css\"
61+
type=\"text/css\">\n<link rel=\"stylesheet\" href=\"css/bootstrap/dataTables.bootstrap.min.css\"
62+
type=\"text/css\" >-->\n<link rel=stylesheet href=\"css/fuentes.css\" type=\"text/css\">\n\n
63+
\ <link rel=stylesheet href=\"css/cep-min.css\" type=\"text/css\">\n\n<!--
64+
JQuery -->\n<script type=\"text/javascript\" src=\"js/jquery-3.6.1.min.js\"></script>\n<script
65+
type=\"text/javascript\" src=\"js/jquery-ui.min.js\"></script>\n<script type=\"text/javascript\"
66+
src=\"js/jquery/jquery.dataTables.min.js\"></script>\n<script type=\"text/javascript\"
67+
src=\"js/datepicker-es.js\"></script>\n\n<!-- Validations -->\n<script type=\"text/javascript\"
68+
src=\"js/validations/validateInput.js\"></script>\n<script type=\"text/javascript\"
69+
src=\"js/validations/validateEvents.js\"></script>\n<script type=\"text/javascript\"
70+
src=\"js/validations/validateWriting.js\"></script>\n<script type=\"text/javascript\"
71+
src=\"js/validations/validationBussines.js\"></script>\n\n<!--Bootstrap-->\n<!--<script
72+
src=\"js/bootstrap/bootstrap.min.js\"></script>-->\n<!--Bootbox Alert-->\n<!--<script
73+
type=\"text/javascript\" src=\"js/bootstrap/bootbox.min.js\"></script>-->\n<!--Bootstrap
74+
Tables-->\n<!--<script type=\"text/javascript\" src=\"js/bootstrap/dataTables.bootstrap.min.js\"></script>-->\n\r\n<meta
75+
http-equiv=\"Content-type\" content=\"text/html; charset=UTF-8\" /> \r\n<style
76+
type=\"text/css\">\r\n /* 20230216_AJRG_GSC_Se cambia versi\xF3n de la
77+
dependencia cep-generador-comprobante (remover dependencia itext) */\r\n @media
78+
screen and (min-width: 481px) and (min-height: 551px) { /* no es movil */\r\n
79+
\ .contenido-wide {\r\n width: 1100px !important;\r\n max-width:
80+
1100px !important;\r\n /*\r\n width: 1050px !important;\r\n
81+
\ max-width: 1050px !important;\r\n */\r\n }\r\n
82+
\ .contenido-wide table {\r\n width: fit-content !important;\r\n
83+
\ }\r\n }\r\n \r\n #consultaMISPEI {\r\n padding: 0
84+
!important;\r\n margin: 15px !important;\r\n }\r\n \r\n #htmlCEP
85+
tr {\r\n padding-top: 2px;\r\n padding-bottom: 2px;\r\n }\r\n</style>\r\n<div
86+
class=\"bg-banxico title-bar\">\r\n <i class=\"icono-header icon-list\"></i>\r\n
87+
\ Informaci&oacute;n del estado del pago\r\n</div>\r\n<div class=\"cuerpo-msg\">\r\n
88+
\ <div id=\"consultaMISPEI\" style=\"padding: 15px;box-sizing: border-box;overflow-x:
89+
auto;\">\r\n <!-- <div class=\"info\" style=\"margin-bottom: 10px;\"><center><strong>Lo
90+
sentimos, por el momento no es posible generar el CEP. Operaci\xF3n no encontrada.
91+
El SPEI no ha recibido una orden de pago que cumpla con el criterio de b\xFAsqueda
92+
especificado. Se recomienda verificar la informaci\xF3n o consulte con su
93+
instituci\xF3n financiera.</strong></center></div> -->\r\n <div
94+
class=\"info\" style=\"margin-bottom: 10px;\"><center><strong>Lo sentimos,
95+
por el momento no es posible generar el CEP. Operaci\xF3n no encontrada. El
96+
SPEI no ha recibido una orden de pago que cumpla con el criterio de b\xFAsqueda
97+
especificado. Se recomienda verificar la informaci\xF3n o consulte con su
98+
instituci\xF3n financiera.</strong></center></div>\r\n \r\n
99+
\ <br><br>\r\n \r\n </div> \r\n \r\n</div>\r\n\r\n<script>\r\n
100+
\ $(document).ready(function () {\r\n if ($(\".operacionesLiquidados\").length
101+
|| $(\".operacionesDevueltas\").length) {\r\n $(\".cuerpo-msg\").addClass('contenido-wide');\r\n
102+
\ }\r\n });\r\n \r\n// $(function () {\r\n// $(\"#htmlCEP\").val($(\"#consultaMISPEI\").html());\r\n//
103+
\ });\r\n\r\n function start_download() {\r\n// if ($(\".operacionesLiquidados\").length
104+
|| $(\".operacionesDevueltas\").length) {\r\n// $(\".cuerpo-msg\").removeClass('contenido-wide');\r\n//
105+
\ $(\"#htmlCEP\").val($(\"#desc_Liquidado\").html());\r\n// }\r\n
106+
\ // evt.preventDefault();\r\n var $htmlToSend = $('#consultaMISPEI').clone();\r\n
107+
\ $(\"#htmlCEP\").val($htmlToSend.html());\r\n return true;\r\n
108+
\ }\r\n\r\n</script>"
109+
headers:
110+
Content-Language:
111+
- es-MX
112+
Content-Length:
113+
- '4353'
114+
Content-Type:
115+
- text/html; charset=UTF-8
116+
Date:
117+
- Fri, 14 Feb 2025 18:25:00 GMT
118+
Set-Cookie:
119+
- JSESSIONID=IqkFtPWscAfquVAu7B3iqmwSXS3jX_8YkJuMjv6-i8rvv4GXfXwB!-2094109768;
120+
path=/; secure; HttpOnly
121+
- Hex39764011=!V/M13Dw+vDYMB7VFNVyFw/oTv40kxNntM9Cc6wJni3k2NRMa0yVJOoPIZGPZ2yztNhLv43+jmR6nNQ==;
122+
expires=Sat, 15-Feb-2025 02:25:00 GMT; path=/; Httponly
123+
- 'TS012f422b=01ab44a5a8be8c98dfb666a6f6f8ac94c01d11b86c3651ff0ecbb7343ae81fabb06ab50ece65a041d2c42843ec30791e5846f4307852112d127b1109f72e1adbeed6e77195de2e64a2ee899ab39b3f1723e25db831;
124+
Path=/; '
125+
- TS604574e3027=083fd6a492ab2000d7d560a374810648a3ca846f27b698b39c5d5afa98be331ec435cd0bce871651080d38975e113000fb177e6916cb13c6cbec0e53e11f475bd3705e75f10b4be26a04b395977daca653a3e6e7d4a51bfa3f0ccfe876dba4de;
126+
Path=/
127+
status:
128+
code: 200
129+
message: OK
130+
version: 1

tests/cassettes/test_fail_validar_transferencia.yaml renamed to tests/cassettes/test_fail_validar_transferencia_pago.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ interactions:
6666
Content-Type:
6767
- text/html; charset=UTF-8
6868
Date:
69-
- Thu, 13 Feb 2025 16:25:34 GMT
69+
- Fri, 14 Feb 2025 18:24:59 GMT
7070
Set-Cookie:
71-
- JSESSIONID=L1QAIUBvfVoiIyEPtI_zYKtEVdTdxUKW6DURwUlxUrUf5j0buoTS!-2094109768;
71+
- JSESSIONID=i2UFtPQJ_qSQA4LOoo5U8qT4BaGkDWrx98jdKjqqx0jFe-LWqrIm!384618570;
7272
path=/; secure; HttpOnly
73-
- Hex39764011=!gAvSQWDwuCTFl1JFNVyFw/oTv40kxLg1HD4ls3vODi3yAy5Wm3BhzgxxulALXcz3KoRgQlInngLvSA==;
74-
expires=Fri, 14-Feb-2025 00:25:34 GMT; path=/; Httponly
75-
- 'TS012f422b=01ab44a5a81497a889d111c7c6b7a3089924f249dd3e785c8e18d629bf521efe70d62e81d052987707a4c517bd392afa6c339df4f68ee482fea560a8b88c923a2c40cad78199bbf43b8453c9e11dd62064f4a1e0dc;
73+
- Hex39764011=!XCF7PmHmzc2GmLpFNVyFw/oTv40kxIBv9ZJrUZn6/gd08ilD6Cp9OeDi7rdTe4T4vOjBkoi+d6KV0A==;
74+
expires=Sat, 15-Feb-2025 02:25:00 GMT; path=/; Httponly
75+
- 'TS012f422b=01ab44a5a861a3409779d131ae7adc973ed697f37166d6ea395011d0d355d063db0b567fa99bfbcb3f99ce7d76c8eeed8989d95d444624d9064ac79d07386af62c3b3fe6738f8c605526f2ae874ab733a34e6a01de;
7676
Path=/; '
77-
- TS604574e3027=083fd6a492ab2000610ffb96df3cc891ddf40e7adf2c7f4f53681407b649677c5f37ccd84082e3ea088ae78a5511300008172d082ec1c9a6ba5daced4ae245998f994aa81feace10acfa2583bbbccd3af9a668c3034f8883362e7467a2f0b9d7;
77+
- TS604574e3027=083fd6a492ab20000a9f766d9f752ee0ee19d7263690d52f4f7108add91b9501da46d3315b57e4f908f7953b9c113000b83fb6dfc65e99efcbec0e53e11f475b2b5e72011020258f921584a6eb7633dc7071f17a4db8d0b7121424dfdccfb23d;
7878
Path=/
7979
status:
8080
code: 200

0 commit comments

Comments
 (0)