Skip to content

Commit

Permalink
Add CepNotAvailableError
Browse files Browse the repository at this point in the history
  • Loading branch information
gabino committed Feb 14, 2025
1 parent 4bb1e4b commit d60dbc4
Show file tree
Hide file tree
Showing 7 changed files with 506 additions and 14 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ Use the `descargar` method to download a transfer in one of the following format
```python
tr.descargar(formato='XML')
```

## Exceptions

- `NotFoundError`: The transfer was not found.
- `MaxRequestError`: The maximum number of requests has been reached.
- `CepNotAvailableError`: The transfer was found, but the CEP is not available.

7 changes: 7 additions & 0 deletions cep/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ class MaxRequestError(CepError):
Máximo número de peticiones alcanzadas para
obtener el CEP de una transferencia
"""


class CepNotAvailableError(CepError):
"""
La transferencia fue encontrada, pero el CEP no
está disponible.
"""
22 changes: 16 additions & 6 deletions cep/transferencia.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,26 @@

from .client import Client
from .cuenta import Cuenta
from .exc import CepError, MaxRequestError, NotFoundError
from .exc import CepError, CepNotAvailableError, MaxRequestError, NotFoundError

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

NOT_FOUND_ERROR_MESSAGE = (
NO_PAYMENT_ERROR_MESSAGE = (
'No se encontró ningún pago con la información proporcionada'
)

NO_OPERATION_ERROR_MESSAGE = (
'El SPEI no ha recibido una orden de pago que cumpla con el '
'criterio de búsqueda especificado'
)

NO_CEP_ERROR_MESSAGE = (
'Con la información proporcionada se identificó el siguiente pago'
)


@dataclass
class Transferencia:
Expand Down Expand Up @@ -149,10 +158,11 @@ def _validar(
receptorParticipante=1 if pago_a_banco else 0,
)
resp = client.post('/valida.do', request_body)
if (
NOT_FOUND_ERROR_MESSAGE in resp.decode('utf-8')
or b'no encontrada' in resp
):
if NO_CEP_ERROR_MESSAGE in resp.decode('utf-8'):
raise CepNotAvailableError
if NO_PAYMENT_ERROR_MESSAGE in resp.decode(
'utf-8'
) or NO_OPERATION_ERROR_MESSAGE in resp.decode('utf-8'):
raise NotFoundError
return client

Expand Down
130 changes: 130 additions & 0 deletions tests/cassettes/test_fail_validar_transferencia_operacion.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
interactions:
- request:
body: tipoCriterio=T&captcha=c&tipoConsulta=1&fecha=08-11-2024&criterio=BiB202411081016248XXX&emisor=37166&receptor=90723&cuenta=723969000011000077&monto=3414.95&receptorParticipante=0
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '178'
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/75.0.3770.142 Safari/537.36
method: POST
uri: http://www.banxico.org.mx/cep-beta/valida.do
response:
body:
string: ''
headers:
Connection:
- Keep-Alive
Content-Length:
- '0'
Location:
- https://www.banxico.org.mx/cep-beta/valida.do
Server:
- mxbanxico
status:
code: 307
message: Temporary Redirect
- request:
body: tipoCriterio=T&captcha=c&tipoConsulta=1&fecha=08-11-2024&criterio=BiB202411081016248XXX&emisor=37166&receptor=90723&cuenta=723969000011000077&monto=3414.95&receptorParticipante=0
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '178'
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/75.0.3770.142 Safari/537.36
method: POST
uri: https://www.banxico.org.mx/cep-beta/valida.do
response:
body:
string: "\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1.0,user-scalable=no\"
/>\n<meta charset=\"utf-8\" /> \n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=9;
IE=8; IE=7; IE=edge\" />\n<link rel=\"apple-touch-icon\" href=\"images/icon.png\"/>\n<link
rel=\"shortcut icon\" href=\"images/icon.png\">\n<!--Bootstrap-->\n<!--<link
href=\"//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css\"
rel=\"stylesheet\">\n<link rel=stylesheet href=\"css/bootstrap/bootstrap.min.css\"
type=\"text/css\">\n<link rel=\"stylesheet\" href=\"css/bootstrap/dataTables.bootstrap.min.css\"
type=\"text/css\" >-->\n<link rel=stylesheet href=\"css/fuentes.css\" type=\"text/css\">\n\n
\ <link rel=stylesheet href=\"css/cep-min.css\" type=\"text/css\">\n\n<!--
JQuery -->\n<script type=\"text/javascript\" src=\"js/jquery-3.6.1.min.js\"></script>\n<script
type=\"text/javascript\" src=\"js/jquery-ui.min.js\"></script>\n<script type=\"text/javascript\"
src=\"js/jquery/jquery.dataTables.min.js\"></script>\n<script type=\"text/javascript\"
src=\"js/datepicker-es.js\"></script>\n\n<!-- Validations -->\n<script type=\"text/javascript\"
src=\"js/validations/validateInput.js\"></script>\n<script type=\"text/javascript\"
src=\"js/validations/validateEvents.js\"></script>\n<script type=\"text/javascript\"
src=\"js/validations/validateWriting.js\"></script>\n<script type=\"text/javascript\"
src=\"js/validations/validationBussines.js\"></script>\n\n<!--Bootstrap-->\n<!--<script
src=\"js/bootstrap/bootstrap.min.js\"></script>-->\n<!--Bootbox Alert-->\n<!--<script
type=\"text/javascript\" src=\"js/bootstrap/bootbox.min.js\"></script>-->\n<!--Bootstrap
Tables-->\n<!--<script type=\"text/javascript\" src=\"js/bootstrap/dataTables.bootstrap.min.js\"></script>-->\n\r\n<meta
http-equiv=\"Content-type\" content=\"text/html; charset=UTF-8\" /> \r\n<style
type=\"text/css\">\r\n /* 20230216_AJRG_GSC_Se cambia versi\xF3n de la
dependencia cep-generador-comprobante (remover dependencia itext) */\r\n @media
screen and (min-width: 481px) and (min-height: 551px) { /* no es movil */\r\n
\ .contenido-wide {\r\n width: 1100px !important;\r\n max-width:
1100px !important;\r\n /*\r\n width: 1050px !important;\r\n
\ max-width: 1050px !important;\r\n */\r\n }\r\n
\ .contenido-wide table {\r\n width: fit-content !important;\r\n
\ }\r\n }\r\n \r\n #consultaMISPEI {\r\n padding: 0
!important;\r\n margin: 15px !important;\r\n }\r\n \r\n #htmlCEP
tr {\r\n padding-top: 2px;\r\n padding-bottom: 2px;\r\n }\r\n</style>\r\n<div
class=\"bg-banxico title-bar\">\r\n <i class=\"icono-header icon-list\"></i>\r\n
\ Informaci&oacute;n del estado del pago\r\n</div>\r\n<div class=\"cuerpo-msg\">\r\n
\ <div id=\"consultaMISPEI\" style=\"padding: 15px;box-sizing: border-box;overflow-x:
auto;\">\r\n <!-- <div class=\"info\" style=\"margin-bottom: 10px;\"><center><strong>Lo
sentimos, por el momento no es posible generar el CEP. Operaci\xF3n no encontrada.
El SPEI no ha recibido una orden de pago que cumpla con el criterio de b\xFAsqueda
especificado. Se recomienda verificar la informaci\xF3n o consulte con su
instituci\xF3n financiera.</strong></center></div> -->\r\n <div
class=\"info\" style=\"margin-bottom: 10px;\"><center><strong>Lo sentimos,
por el momento no es posible generar el CEP. Operaci\xF3n no encontrada. El
SPEI no ha recibido una orden de pago que cumpla con el criterio de b\xFAsqueda
especificado. Se recomienda verificar la informaci\xF3n o consulte con su
instituci\xF3n financiera.</strong></center></div>\r\n \r\n
\ <br><br>\r\n \r\n </div> \r\n \r\n</div>\r\n\r\n<script>\r\n
\ $(document).ready(function () {\r\n if ($(\".operacionesLiquidados\").length
|| $(\".operacionesDevueltas\").length) {\r\n $(\".cuerpo-msg\").addClass('contenido-wide');\r\n
\ }\r\n });\r\n \r\n// $(function () {\r\n// $(\"#htmlCEP\").val($(\"#consultaMISPEI\").html());\r\n//
\ });\r\n\r\n function start_download() {\r\n// if ($(\".operacionesLiquidados\").length
|| $(\".operacionesDevueltas\").length) {\r\n// $(\".cuerpo-msg\").removeClass('contenido-wide');\r\n//
\ $(\"#htmlCEP\").val($(\"#desc_Liquidado\").html());\r\n// }\r\n
\ // evt.preventDefault();\r\n var $htmlToSend = $('#consultaMISPEI').clone();\r\n
\ $(\"#htmlCEP\").val($htmlToSend.html());\r\n return true;\r\n
\ }\r\n\r\n</script>"
headers:
Content-Language:
- es-MX
Content-Length:
- '4353'
Content-Type:
- text/html; charset=UTF-8
Date:
- Fri, 14 Feb 2025 18:25:00 GMT
Set-Cookie:
- JSESSIONID=IqkFtPWscAfquVAu7B3iqmwSXS3jX_8YkJuMjv6-i8rvv4GXfXwB!-2094109768;
path=/; secure; HttpOnly
- Hex39764011=!V/M13Dw+vDYMB7VFNVyFw/oTv40kxNntM9Cc6wJni3k2NRMa0yVJOoPIZGPZ2yztNhLv43+jmR6nNQ==;
expires=Sat, 15-Feb-2025 02:25:00 GMT; path=/; Httponly
- 'TS012f422b=01ab44a5a8be8c98dfb666a6f6f8ac94c01d11b86c3651ff0ecbb7343ae81fabb06ab50ece65a041d2c42843ec30791e5846f4307852112d127b1109f72e1adbeed6e77195de2e64a2ee899ab39b3f1723e25db831;
Path=/; '
- TS604574e3027=083fd6a492ab2000d7d560a374810648a3ca846f27b698b39c5d5afa98be331ec435cd0bce871651080d38975e113000fb177e6916cb13c6cbec0e53e11f475bd3705e75f10b4be26a04b395977daca653a3e6e7d4a51bfa3f0ccfe876dba4de;
Path=/
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ interactions:
Content-Type:
- text/html; charset=UTF-8
Date:
- Thu, 13 Feb 2025 16:25:34 GMT
- Fri, 14 Feb 2025 18:24:59 GMT
Set-Cookie:
- JSESSIONID=L1QAIUBvfVoiIyEPtI_zYKtEVdTdxUKW6DURwUlxUrUf5j0buoTS!-2094109768;
- JSESSIONID=i2UFtPQJ_qSQA4LOoo5U8qT4BaGkDWrx98jdKjqqx0jFe-LWqrIm!384618570;
path=/; secure; HttpOnly
- Hex39764011=!gAvSQWDwuCTFl1JFNVyFw/oTv40kxLg1HD4ls3vODi3yAy5Wm3BhzgxxulALXcz3KoRgQlInngLvSA==;
expires=Fri, 14-Feb-2025 00:25:34 GMT; path=/; Httponly
- 'TS012f422b=01ab44a5a81497a889d111c7c6b7a3089924f249dd3e785c8e18d629bf521efe70d62e81d052987707a4c517bd392afa6c339df4f68ee482fea560a8b88c923a2c40cad78199bbf43b8453c9e11dd62064f4a1e0dc;
- Hex39764011=!XCF7PmHmzc2GmLpFNVyFw/oTv40kxIBv9ZJrUZn6/gd08ilD6Cp9OeDi7rdTe4T4vOjBkoi+d6KV0A==;
expires=Sat, 15-Feb-2025 02:25:00 GMT; path=/; Httponly
- 'TS012f422b=01ab44a5a861a3409779d131ae7adc973ed697f37166d6ea395011d0d355d063db0b567fa99bfbcb3f99ce7d76c8eeed8989d95d444624d9064ac79d07386af62c3b3fe6738f8c605526f2ae874ab733a34e6a01de;
Path=/; '
- TS604574e3027=083fd6a492ab2000610ffb96df3cc891ddf40e7adf2c7f4f53681407b649677c5f37ccd84082e3ea088ae78a5511300008172d082ec1c9a6ba5daced4ae245998f994aa81feace10acfa2583bbbccd3af9a668c3034f8883362e7467a2f0b9d7;
- TS604574e3027=083fd6a492ab20000a9f766d9f752ee0ee19d7263690d52f4f7108add91b9501da46d3315b57e4f908f7953b9c113000b83fb6dfc65e99efcbec0e53e11f475b2b5e72011020258f921584a6eb7633dc7071f17a4db8d0b7121424dfdccfb23d;
Path=/
status:
code: 200
Expand Down
Loading

0 comments on commit d60dbc4

Please sign in to comment.