Skip to content

Commit bd2f210

Browse files
author
gabino
committed
Update Transferencia class to remove unnecessary validation checks
1 parent dbd3ae0 commit bd2f210

27 files changed

+3830
-2288
lines changed
28.1 KB
Binary file not shown.

cep/transferencia.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22
from dataclasses import asdict, dataclass
33
from decimal import Decimal
4-
from typing import Optional, cast
4+
from typing import cast
55

66
import clabe
77
from lxml import etree
@@ -51,8 +51,6 @@ def validar(
5151
client = cls._validar(
5252
fecha, clave_rastreo, emisor, receptor, cuenta, monto, pago_a_banco
5353
)
54-
if not client:
55-
return None
5654

5755
try:
5856
xml = cls._descargar(client, 'XML')
@@ -123,8 +121,6 @@ def descargar(self, formato: str = 'PDF') -> bytes:
123121
self.monto,
124122
self.pago_a_banco,
125123
)
126-
if not client:
127-
raise CepError
128124
return self._descargar(client, formato)
129125

130126
def to_dict(self) -> dict:
@@ -139,7 +135,7 @@ def _validar(
139135
cuenta: str,
140136
monto: Decimal,
141137
pago_a_banco: bool = False,
142-
) -> Optional[Client]:
138+
) -> Client:
143139
assert emisor in clabe.BANKS.values()
144140
assert receptor in clabe.BANKS.values()
145141
client = Client() # Use new client to ensure thread-safeness
-34.8 KB
Binary file not shown.
28.1 KB
Binary file not shown.

tests/cassettes/test_descagar_transferencia_con_fecha_distinta.yaml

Lines changed: 0 additions & 830 deletions
This file was deleted.

tests/cassettes/test_descarga_pdf.yaml

Lines changed: 598 additions & 642 deletions
Large diffs are not rendered by default.
Lines changed: 41 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
interactions:
22
- request:
3-
body: tipoCriterio=T&receptorParticipante=0&captcha=c&tipoConsulta=1&fecha=01-01-2019&criterio=guey&emisor=90646&receptor=40012&cuenta=012180004643051249&monto=1111111.0
3+
body: tipoCriterio=T&captcha=c&tipoConsulta=1&fecha=01-01-2019&criterio=invalid-clave&emisor=37166&receptor=90723&cuenta=012180004643051249&monto=1111111.0&receptorParticipante=0
44
headers:
55
Accept:
66
- '*/*'
@@ -9,138 +9,74 @@ interactions:
99
Connection:
1010
- keep-alive
1111
Content-Length:
12-
- '163'
12+
- '172'
1313
Content-Type:
1414
- application/x-www-form-urlencoded
1515
User-Agent:
1616
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML,
1717
like Gecko) Chrome/75.0.3770.142 Safari/537.36
1818
method: POST
19-
uri: http://www.banxico.org.mx/cep/valida.do
19+
uri: http://www.banxico.org.mx/cep-beta/valida.do
2020
response:
2121
body:
22-
string: "\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1.0,user-scalable=no\"
23-
/>\n<meta charset=\"utf-8\" /> \n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=9;
24-
IE=8; IE=7; IE=edge\" />\n<link rel=\"apple-touch-icon\" href=\"images/icon.png\"/>\n<link
25-
rel=\"shortcut icon\" href=\"images/icon.png\">\n<!--Bootstrap-->\n<!--<link
26-
href=\"//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css\"
27-
rel=\"stylesheet\">\n<link rel=stylesheet href=\"css/bootstrap/bootstrap.min.css\"
28-
type=\"text/css\">\n<link rel=\"stylesheet\" href=\"css/bootstrap/dataTables.bootstrap.min.css\"
29-
type=\"text/css\" >-->\n<link rel=stylesheet href=\"css/fuentes.css\" type=\"text/css\">\n\n
30-
\ <link rel=stylesheet href=\"css/cep-min.css\" type=\"text/css\">\n\n<!--
31-
JQuery -->\n<script type=\"text/javascript\" src=\"js/jquery-3.0.0.min.js\"></script>\n<script
32-
type=\"text/javascript\" src=\"js/jquery-ui.min.js\"></script>\n<script type=\"text/javascript\"
33-
src=\"js/jquery/jquery.dataTables.min.js\"></script>\n<script type=\"text/javascript\"
34-
src=\"js/datepicker-es.js\"></script>\n\n<!-- Validations -->\n<script type=\"text/javascript\"
35-
src=\"js/validations/validateInput.js\"></script>\n<script type=\"text/javascript\"
36-
src=\"js/validations/validateEvents.js\"></script>\n<script type=\"text/javascript\"
37-
src=\"js/validations/validateWriting.js\"></script>\n<script type=\"text/javascript\"
38-
src=\"js/validations/validationBussines.js\"></script>\n\n<!--Bootstrap-->\n<!--<script
39-
src=\"js/bootstrap/bootstrap.min.js\"></script>-->\n<!--Bootbox Alert-->\n<!--<script
40-
type=\"text/javascript\" src=\"js/bootstrap/bootbox.min.js\"></script>-->\n<!--Bootstrap
41-
Tables-->\n<!--<script type=\"text/javascript\" src=\"js/bootstrap/dataTables.bootstrap.min.js\"></script>-->\n\r\n<meta
42-
http-equiv=\"Content-type\" content=\"text/html; charset=UTF-8\" /> \r\n<div
43-
class=\"bg-banxico title-bar\">\r\n <i class=\"icono-header icon-list\"></i>\r\n
44-
\ Informaci&oacute;n del estado del pago\r\n</div>\r\n<div class=\"cuerpo-msg\"
45-
style=\"width: 600px;\">\r\n <div id=\"consultaMISPEI\" style=\"padding:
46-
15px;box-sizing: border-box;overflow-x: auto;\">\r\n <div class=\"info\"
47-
style=\"margin-bottom: 10px;\"><center><strong>Lo sentimos, por el momento
48-
no es posible generar el CEP. Operaci\xF3n no encontrada. El SPEI no ha recibido
49-
una orden de pago que cumpla con el criterio de b\xFAsqueda especificado.
50-
Se recomienda verificar la informaci\xF3n o consulte a su banco.</strong></center></div>\r\n
51-
\ \r\n <br><br>\r\n \r\n </div> \r\n
52-
\ \r\n</div>\r\n\r\n<script>\r\n $(function () {\r\n $(\"#htmlCEP\").val($(\"#consultaMISPEI\").html());\r\n
53-
\ });\r\n</script>"
22+
string: ''
5423
headers:
55-
Content-Language:
56-
- es-MX
24+
Connection:
25+
- Keep-Alive
5726
Content-Length:
58-
- '2573'
59-
Content-Type:
60-
- text/html; charset=UTF-8
61-
Date:
62-
- Wed, 31 Jul 2019 22:19:42 GMT
63-
Set-Cookie:
64-
- JSESSIONID=83VKHhmHhOhCaGk5yk5nzvCfnvQE63t9iro03PxjtKvH3te3AblR!-436816968;
65-
path=/; HttpOnly
66-
- ser29307111=709772970.50971.0000; path=/; Httponly
67-
- TS014a759c=0189f484af94034651e412ada5540a7d6a8aeb988ef6a20b8b6d7cc6308e9f26cdfe4cec213451c440f3f58f598d41622ea859b099abe12ba4cb355c92fa26625cd3e33b347bef995315dc0964ffaaff7b38e2b816;
68-
Path=/
27+
- '0'
28+
Location:
29+
- https://www.banxico.org.mx/cep-beta/valida.do
30+
Server:
31+
- mxbanxico
6932
status:
70-
code: 200
71-
message: OK
33+
code: 307
34+
message: Temporary Redirect
7235
- request:
73-
body: null
36+
body: tipoCriterio=T&captcha=c&tipoConsulta=1&fecha=01-01-2019&criterio=invalid-clave&emisor=37166&receptor=90723&cuenta=012180004643051249&monto=1111111.0&receptorParticipante=0
7437
headers:
7538
Accept:
7639
- '*/*'
7740
Accept-Encoding:
7841
- gzip, deflate
7942
Connection:
8043
- keep-alive
81-
Cookie:
82-
- JSESSIONID=83VKHhmHhOhCaGk5yk5nzvCfnvQE63t9iro03PxjtKvH3te3AblR!-436816968;
83-
TS014a759c=0189f484af94034651e412ada5540a7d6a8aeb988ef6a20b8b6d7cc6308e9f26cdfe4cec213451c440f3f58f598d41622ea859b099abe12ba4cb355c92fa26625cd3e33b347bef995315dc0964ffaaff7b38e2b816;
84-
ser29307111=709772970.50971.0000
44+
Content-Length:
45+
- '172'
46+
Content-Type:
47+
- application/x-www-form-urlencoded
8548
User-Agent:
8649
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML,
8750
like Gecko) Chrome/75.0.3770.142 Safari/537.36
88-
method: GET
89-
uri: http://www.banxico.org.mx/cep/descarga.do?formato=XML
51+
method: POST
52+
uri: https://www.banxico.org.mx/cep-beta/valida.do
9053
response:
9154
body:
92-
string: '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Draft//EN">
93-
94-
<HTML>
95-
96-
<HEAD>
97-
98-
<TITLE>Error 500--Internal Server Error</TITLE>
99-
100-
</HEAD>
101-
102-
<BODY bgcolor="white">
103-
104-
<FONT FACE=Helvetica><BR CLEAR=all>
105-
106-
<TABLE border=0 cellspacing=5><TR><TD><BR CLEAR=all>
107-
108-
<FONT FACE="Helvetica" COLOR="black" SIZE="3"><H2>Error 500--Internal Server
109-
Error</H2>
110-
111-
</FONT></TD></TR>
112-
113-
</TABLE>
114-
115-
<TABLE border=0 width=100% cellpadding=10><TR><TD VALIGN=top WIDTH=100% BGCOLOR=white><FONT
116-
FACE="Courier New"><FONT FACE="Helvetica" SIZE="3"><H3>From RFC 2068 <i>Hypertext
117-
Transfer Protocol -- HTTP/1.1</i>:</H3>
118-
119-
</FONT><FONT FACE="Helvetica" SIZE="3"><H4>10.5.1 500 Internal Server Error</H4>
120-
121-
</FONT><P><FONT FACE="Courier New">The server encountered an unexpected condition
122-
which prevented it from fulfilling the request.</FONT></P>
123-
124-
</FONT></TD></TR>
125-
126-
</TABLE>
127-
128-
129-
</BODY>
130-
131-
</HTML>
132-
133-
'
55+
string: "\r\n<div class=\"bg-banxico title-bar\">\r\n <i class=\"icono-header
56+
icon-warning3\"></i>\r\n Error\r\n</div>\r\n<div id=\"#error_div\">\r\n
57+
\ <div class=\"info\">\r\n <p style=\"padding: 10px;max-width: 500px;
58+
text-align: center;\">\r\n [BE] No se encontr\xF3 ning\xFAn pago
59+
con la informaci\xF3n proporcionada. Verifique e intente nuevamente.\r\n </p>\r\n
60+
\ </div>\r\n</div>\r\n<input type=\"hidden\" name=\"varHideCaptcha\" value=\"true\"/>\r\n"
13461
headers:
135-
Connection:
136-
- close
62+
Content-Language:
63+
- es-MX
13764
Content-Length:
138-
- '833'
65+
- '432'
13966
Content-Type:
14067
- text/html; charset=UTF-8
14168
Date:
142-
- Wed, 31 Jul 2019 22:19:44 GMT
69+
- Thu, 13 Feb 2025 16:25:34 GMT
70+
Set-Cookie:
71+
- JSESSIONID=L1QAIUBvfVoiIyEPtI_zYKtEVdTdxUKW6DURwUlxUrUf5j0buoTS!-2094109768;
72+
path=/; secure; HttpOnly
73+
- Hex39764011=!gAvSQWDwuCTFl1JFNVyFw/oTv40kxLg1HD4ls3vODi3yAy5Wm3BhzgxxulALXcz3KoRgQlInngLvSA==;
74+
expires=Fri, 14-Feb-2025 00:25:34 GMT; path=/; Httponly
75+
- 'TS012f422b=01ab44a5a81497a889d111c7c6b7a3089924f249dd3e785c8e18d629bf521efe70d62e81d052987707a4c517bd392afa6c339df4f68ee482fea560a8b88c923a2c40cad78199bbf43b8453c9e11dd62064f4a1e0dc;
76+
Path=/; '
77+
- TS604574e3027=083fd6a492ab2000610ffb96df3cc891ddf40e7adf2c7f4f53681407b649677c5f37ccd84082e3ea088ae78a5511300008172d082ec1c9a6ba5daced4ae245998f994aa81feace10acfa2583bbbccd3af9a668c3034f8883362e7467a2f0b9d7;
78+
Path=/
14379
status:
144-
code: 500
145-
message: Internal Server Error
80+
code: 200
81+
message: OK
14682
version: 1

tests/cassettes/test_http_error.yaml

Lines changed: 44 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interactions:
1212
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML,
1313
like Gecko) Chrome/75.0.3770.142 Safari/537.36
1414
method: GET
15-
uri: http://www.banxico.org.mx/cep/no/existe
15+
uri: http://www.banxico.org.mx/cep-beta/no/existe
1616
response:
1717
body:
1818
string: ''
@@ -22,12 +22,41 @@ interactions:
2222
Content-Length:
2323
- '0'
2424
Location:
25-
- http://www.anterior.banxico.org.mx/cep/no/existe
25+
- https://www.banxico.org.mx/cep-beta/no/existe
2626
Server:
27-
- BigIP
27+
- mxbanxico
28+
status:
29+
code: 307
30+
message: Temporary Redirect
31+
- request:
32+
body: null
33+
headers:
34+
Accept:
35+
- '*/*'
36+
Accept-Encoding:
37+
- gzip, deflate
38+
Connection:
39+
- keep-alive
40+
User-Agent:
41+
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML,
42+
like Gecko) Chrome/75.0.3770.142 Safari/537.36
43+
method: GET
44+
uri: https://www.banxico.org.mx/cep-beta/no/existe
45+
response:
46+
body:
47+
string: ''
48+
headers:
49+
Connection:
50+
- Keep-Alive
51+
Content-Length:
52+
- '0'
53+
Location:
54+
- https://anterior.banxico.org.mx/cep-beta/no/existe
55+
Server:
56+
- mxbanxico
2857
status:
2958
code: 302
30-
message: Found
59+
message: Moved Temporarily
3160
- request:
3261
body: null
3362
headers:
@@ -41,66 +70,25 @@ interactions:
4170
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML,
4271
like Gecko) Chrome/75.0.3770.142 Safari/537.36
4372
method: GET
44-
uri: http://www.anterior.banxico.org.mx/cep/no/existe
73+
uri: https://anterior.banxico.org.mx/cep-beta/no/existe
4574
response:
4675
body:
47-
string: '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Draft//EN">
48-
49-
<HTML>
50-
51-
<HEAD>
52-
53-
<TITLE>Error 404--Not Found</TITLE>
54-
55-
</HEAD>
56-
57-
<BODY bgcolor="white">
58-
59-
<FONT FACE=Helvetica><BR CLEAR=all>
60-
61-
<TABLE border=0 cellspacing=5><TR><TD><BR CLEAR=all>
62-
63-
<FONT FACE="Helvetica" COLOR="black" SIZE="3"><H2>Error 404--Not Found</H2>
64-
65-
</FONT></TD></TR>
66-
67-
</TABLE>
68-
69-
<TABLE border=0 width=100% cellpadding=10><TR><TD VALIGN=top WIDTH=100% BGCOLOR=white><FONT
70-
FACE="Courier New"><FONT FACE="Helvetica" SIZE="3"><H3>From RFC 2068 <i>Hypertext
71-
Transfer Protocol -- HTTP/1.1</i>:</H3>
72-
73-
</FONT><FONT FACE="Helvetica" SIZE="3"><H4>10.4.5 404 Not Found</H4>
74-
75-
</FONT><P><FONT FACE="Courier New">The server has not found anything matching
76-
the Request-URI. No indication is given of whether the condition is temporary
77-
or permanent.</p><p>If the server does not wish to make this information available
78-
to the client, the status code 403 (Forbidden) can be used instead. The 410
79-
(Gone) status code SHOULD be used if the server knows, through some internally
80-
configurable mechanism, that an old resource is permanently unavailable and
81-
has no forwarding address.</FONT></P>
82-
83-
</FONT></TD></TR>
84-
85-
</TABLE>
86-
87-
88-
</BODY>
89-
90-
</HTML>
91-
92-
'
76+
string: The resource you are looking for has been removed, had its name changed,
77+
or is temporarily unavailable.
9378
headers:
9479
Content-Length:
95-
- '1164'
80+
- '103'
9681
Content-Type:
97-
- text/html; charset=UTF-8
82+
- text/html
9883
Date:
99-
- Wed, 31 Jul 2019 22:10:25 GMT
84+
- Thu, 13 Feb 2025 16:29:05 GMT
10085
Set-Cookie:
101-
- ser29307111=709772970.50971.0000; path=/; Httponly
102-
- TS014a759c=0189f484af0dfe57a482b0397c7dfa4de3ec8dccb82bf88c7c60badfd116214ac8e976e9160aa3f01c58847e5567305109721675e798547f39f5e434af9c6fddd649ea7867;
86+
- TS27080ada027=083fd6a492ab2000b680ccb1da004b5b4fdaa8484afdb7be4f778f6c1b99695c85df7ec0db406647089836ce1e1130000f24c8692fcbf30a82791dd1a64a58930c0ee5d9bd2646eb613c5a9e383a5019333abdba92c2cf7c77f10a2b5a0f0e8a;
10387
Path=/
88+
Strict-Transport-Security:
89+
- max-age=480; preload
90+
X-Robots-Tag:
91+
- noindex, nofollow
10492
status:
10593
code: 404
10694
message: Not Found

0 commit comments

Comments
 (0)