diff --git a/dhlmex/client.py b/dhlmex/client.py index c2d6cb1..67e5fbd 100644 --- a/dhlmex/client.py +++ b/dhlmex/client.py @@ -1,3 +1,4 @@ +import logging import os from typing import Any, ClassVar, Dict, Optional @@ -14,6 +15,8 @@ ) DHL_CERT = 'prepaid-dhl-com-mx.pem' +logging.basicConfig(level=logging.DEBUG) + class Client: @@ -34,7 +37,7 @@ def __init__( self.session = Session() self.session.headers['User-Agent'] = USER_AGENT if os.getenv('DEBUG'): - print(f'Client using Charles certificate') + logging.debug(f'Client using Charles certificate') self.session.verify = DHL_CERT self._login(username, password) @@ -59,12 +62,14 @@ def _login(self, username: str, password: str) -> Response: else: raise httpe except SSLError: - raise DhlmexException('Cient on debug, but Charles not running') + raise DhlmexException('Client on debug, but Charles not running') # DHL always return 200 although there is an existing session if 'Ya existe una sesiĆ³n' in resp.text: raise DhlmexException( f'There is an exisiting session on DHL for {username}' ) + if 'Verifique su usuario' in resp.text: + raise DhlmexException('Invalid credentials') return resp def _logout(self) -> Response: diff --git a/dhlmex/resources/guides.py b/dhlmex/resources/guides.py index 0953a6b..96fa1b2 100644 --- a/dhlmex/resources/guides.py +++ b/dhlmex/resources/guides.py @@ -128,9 +128,19 @@ def _fill_guide_table( fill_data['javax.faces.ViewState'] = view_state fill_data['datos:j_id105'] = 'datos:j_id105' - self._client.post(self._urls['capture'], fill_data) + msg = self._validate_data(fill_data) + if msg: + raise DhlmexException(f'Invalid data: {msg}') + else: + return fill_data['javax.faces.ViewState'] - return fill_data['javax.faces.ViewState'] + def _validate_data(self, fill_data: Dict) -> str: + resp = self._client.post(self._urls['capture'], fill_data) + msg = '' + if 'messageError' in resp.text: + soup = BeautifulSoup(resp.text, features='html.parser') + msg = soup.find('span', {'class': 'rich-messages-label'}).text + return msg def _confirm_capture(self, view_state: str) -> Response: confirm_data = { diff --git a/dhlmex/version.py b/dhlmex/version.py index 971fbc4..4a197ec 100644 --- a/dhlmex/version.py +++ b/dhlmex/version.py @@ -1 +1 @@ -__version__ = '0.0.4' # pragma: no cover +__version__ = '0.0.5' # pragma: no cover diff --git a/tests/cassettes/test_invalid_creds.yaml b/tests/cassettes/test_invalid_creds.yaml new file mode 100644 index 0000000..584a117 --- /dev/null +++ b/tests/cassettes/test_invalid_creds.yaml @@ -0,0 +1,318 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + 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: GET + uri: https://prepaid.dhl.com.mx/Prepago/ + response: + body: + string: "\n\n\n \n \n Login\ + \ / Admin\n \n \n \n \n \n \n \n \n \n\ + \
\n \n
\n\n \n
\n
\n \ + \ \n
\n
\n \"DHL\n
\n
\n\ + \ \n\n \n\n \n
\n
\n
\n\n\n \ + \
\n\n\n\n\n\n
\n\n\n\n\n\n\n\n\n\n\n\n\ +
Prepago\ + \ DHL
Debe autenticarse en el sistema para acceder
\n\n\n\n\n\n\ + \n\ + \n\n\n\n\n\ + \n\n\n
\n\n\n\n\n\ + \n\n\n\n\n\n
Usuario:
Contraseña:
\n
Recuperar Contraseña
\n\n\n\n\n\n\ + \n
\n
\n
\n
\n\n
\n
Recuperar Contraseña
\n
\n\n\n\n\n\n\n\n\n\n\n\n
Recuperación\ + \ de Contraseña
Usuario:
\n\"\
\"\"\n\n\n\n\n\n\n\ +
\n\n
new ModalPanel('pnlUsuario',\n\t\t\t\t{\n\t\t\t\ + \t\twidth: 400,\n\t\t\t\t\theight: 200,\n\n\t\t\t\t\tminWidth: -1,\n\t\t\t\ + \t\tminHeight: -1,\n\n\t\t\t\t\tresizeable: true,\n\t\t\t\t\tmoveable: true,\n\ + \n\t\t\t\t\tleft: \"auto\",\n\t\t\t\t\ttop: \"auto\",\n\n\t\t\t\t\tzindex:\ + \ 100,onresize: '',onmove: '',onshow: '',onhide: '',onbeforeshow: '',onbeforehide:\ + \ '',\n\t\t\t\t\tdomElementAttachment: \"\",\t\t\t\t\n\t\t\t\t\tkeepVisualState:\ + \ false,\n\t\t\t\t\tshowWhenRendered: false,\n\t\t\t\t\tselectBehavior: \"\ + disable\",\n\n\t\t\t\t\tautosized: false,\n\t\t\t\t\toverlapEmbedObjects:\ + \ false});
\n\ + \ \n \n \n\n \n \ + \ \n \n \n\n \n
\n \n \"Deutsche\n \n
\n\n \ + \ \n \n" + headers: + Content-Type: + - text/html;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:15:46 GMT + Server: + - Apache-Coyote/1.1 + Set-Cookie: + - JSESSIONID=E190FC94FE243B7B23387AD81E554633; Path=/Prepago/; HttpOnly + - BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000; path=/; Httponly; Secure + Transfer-Encoding: + - chunked + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +- request: + body: AJAXREQUEST=%5B%27_viewRoot%27%5D&j_id6=%5B%27j_id6%27%5D&j_id6%3Aj_id20=%5B%27USERNAME%27%5D&j_id6%3Aj_id22=%5B%27PASSWORD%27%5D&javax.faces.ViewState=%5B%27j_id1%27%5D&j_id6%3Aj_id29=%5B%27j_id6%3Aj_id29%27%5D + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '153' + Content-Type: + - application/x-www-form-urlencoded + Cookie: + - JSESSIONID=E190FC94FE243B7B23387AD81E554633; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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://prepaid.dhl.com.mx/Prepago/jsp/app/login/login.xhtml + response: + body: + string: "\r\n\r\n
Verifique\ + \ su usuario/contrase\xF1a
Usuario:Contrase\xF1a:
Recuperar Contrase\xF1a
Verifique su usuario/contrase\xF1a
" + headers: + Ajax-Response: + - 'true' + Cache-Control: + - no-cache, must-revalidate, max_age=0, no-store + Content-Length: + - '4503' + Content-Type: + - text/xml;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:15:46 GMT + Expires: + - '0' + Pragma: + - no-cache + Server: + - Apache-Coyote/1.1 + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +version: 1 diff --git a/tests/conftest.py b/tests/conftest.py index 4674a08..50e2a0d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -85,6 +85,21 @@ def invalid_destination() -> Destination: ) +@pytest.fixture +def missing_data() -> Destination: + return Destination( + company='GREGORIO CASTRO', + contact='GREGORIO CASTRO', + email='greg@gmail.com', + phone='550909090', + address1='REFORMA 222', + postal_code='06600', + neighborhood='JUAREZ', + city='', + state='CDMX', + ) + + @pytest.fixture def invalid_postal_code() -> Destination: return Destination( diff --git a/tests/resources/cassettes/test_missing_city.yaml b/tests/resources/cassettes/test_missing_city.yaml new file mode 100644 index 0000000..a26342e --- /dev/null +++ b/tests/resources/cassettes/test_missing_city.yaml @@ -0,0 +1,2520 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + 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: GET + uri: https://prepaid.dhl.com.mx/Prepago/ + response: + body: + string: "\n\n\n \n \n Login\ + \ / Admin\n \n \n \n \n \n \n \n \n \n\ + \
\n \n
\n\n \n
\n
\n \ + \ \n
\n
\n \"DHL\n
\n
\n\ + \ \n\n \n\n \n
\n
\n
\n\n\n \ + \
\n\n\n\n\n\n
\n\n\n\n\n\n\n\n\n\n\n\n\ +
Prepago\ + \ DHL
Debe autenticarse en el sistema para acceder
\n\n\n\n\n\n\ + \n\ + \n\n\n\n\n\ + \n\n\n
\n\n\n\n\n\ + \n\n\n\n\n\n
Usuario:
Contraseña:
\n
Recuperar Contraseña
\n\n\n\n\n\n\ + \n
\n
\n
\n
\n\n
\n
Recuperar Contraseña
\n
\n\n\n\n\n\n\n\n\n\n\n\n
Recuperación\ + \ de Contraseña
Usuario:
\n\"\
\"\"\n\n\n\n\n\n\n\ +
\n\n
new ModalPanel('pnlUsuario',\n\t\t\t\t{\n\t\t\t\ + \t\twidth: 400,\n\t\t\t\t\theight: 200,\n\n\t\t\t\t\tminWidth: -1,\n\t\t\t\ + \t\tminHeight: -1,\n\n\t\t\t\t\tresizeable: true,\n\t\t\t\t\tmoveable: true,\n\ + \n\t\t\t\t\tleft: \"auto\",\n\t\t\t\t\ttop: \"auto\",\n\n\t\t\t\t\tzindex:\ + \ 100,onresize: '',onmove: '',onshow: '',onhide: '',onbeforeshow: '',onbeforehide:\ + \ '',\n\t\t\t\t\tdomElementAttachment: \"\",\t\t\t\t\n\t\t\t\t\tkeepVisualState:\ + \ false,\n\t\t\t\t\tshowWhenRendered: false,\n\t\t\t\t\tselectBehavior: \"\ + disable\",\n\n\t\t\t\t\tautosized: false,\n\t\t\t\t\toverlapEmbedObjects:\ + \ false});
\n\ + \ \n \n \n\n \n \ + \ \n \n \n\n \n
\n \n \"Deutsche\n \n
\n\n \ + \ \n \n" + headers: + Content-Type: + - text/html;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:22:20 GMT + Server: + - Apache-Coyote/1.1 + Set-Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; Path=/Prepago/; HttpOnly + - BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000; path=/; Httponly; Secure + Transfer-Encoding: + - chunked + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +- request: + body: AJAXREQUEST=%5B%27_viewRoot%27%5D&j_id6=%5B%27j_id6%27%5D&j_id6%3Aj_id20=%5B%27USERNAME%27%5D&j_id6%3Aj_id22=%5B%27PASSWORD%27%5D&javax.faces.ViewState=%5B%27j_id1%27%5D&j_id6%3Aj_id29=%5B%27j_id6%3Aj_id29%27%5D + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '148' + Content-Type: + - application/x-www-form-urlencoded + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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://prepaid.dhl.com.mx/Prepago/jsp/app/login/login.xhtml + response: + body: + string: ' + + ' + headers: + Ajax-Response: + - redirect + Cache-Control: + - no-cache, must-revalidate, max_age=0, no-store + Content-Type: + - text/xml;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:22:20 GMT + Expires: + - '0' + Location: + - /Prepago/jsp/app/inicio/inicio.xhtml + Pragma: + - no-cache + Server: + - Apache-Coyote/1.1 + Transfer-Encoding: + - chunked + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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://prepaid.dhl.com.mx/Prepago/jsp/app/inicio/inicio.xhtml + response: + body: + string: "\n\n\n \n \n Administrar\n\ + \ \n \n \n \n \n \n \n \n \n\ + \
\n \n
\n\n \n
\n
\n \ + \ \n
\n
\n \"DHL\n
\n
\n\ + \ \n\n \n\n \n
\n
\n
\n \n
\n
\n\ + \
\n \n\n
\n
\n\ +
\n\n
Cliente
Cliente
\n\n\n\n\n\n\ + \n\n\n\n\n\ + \n\n\ + \n\n\n\n\n\n\ +
\n\nImpresión Sub Usuario
Guías Impresas
Asignar Recolección (SubUsuario)
Manual de Usuario
\n
Reportes
Reportes
\n\n\n\n\n\ + \n\n
Guías Generadas (SubUsuario)
\n
Salir
Salir
\n\n\n\n\n\n\n\n\n\n\n\ +
Cambiar Password
Cerrar Sesión
\n
\n
\n
\n\ + \
\n
\n \n\n \n
\n \n \"Deutsche\n \n
\n\n \ + \ \n \n" + headers: + Content-Type: + - text/html;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:22:20 GMT + Server: + - Apache-Coyote/1.1 + Transfer-Encoding: + - chunked + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +- request: + body: j_id9=j_id9&j_id9%3Aj_id16=j_id9%3Aj_id16&javax.faces.ViewState=j_id2&j_id9%3Aj_id10=j_id9%3Aj_id14 + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '99' + Content-Type: + - application/x-www-form-urlencoded + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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://prepaid.dhl.com.mx/Prepago/jsp/app/inicio/inicio.xhtml + response: + body: + string: '' + headers: + Content-Length: + - '0' + Date: + - Wed, 05 Feb 2020 14:22:20 GMT + Location: + - http://prepaid.dhl.com.mx/Prepago/jsp/app/cliente/impresionClienteSubUsuario.xhtml + Server: + - Apache-Coyote/1.1 + X-Powered-By: + - JSF/1.2 + status: + code: 302 + message: Found +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746 + 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: GET + uri: http://prepaid.dhl.com.mx/Prepago/jsp/app/cliente/impresionClienteSubUsuario.xhtml + response: + body: + string: '' + headers: + Connection: + - Keep-Alive + Content-Length: + - '0' + Location: + - https://prepaid.dhl.com.mx/Prepago/jsp/app/cliente/impresionClienteSubUsuario.xhtml + Server: + - BigIP + status: + code: 302 + message: Found +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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: GET + uri: https://prepaid.dhl.com.mx/Prepago/jsp/app/cliente/impresionClienteSubUsuario.xhtml + response: + body: + string: "\n\n\n \n \n Impresión\n\ + \ \n \n \n \n \n \n \n \n \n\ + \
\n \n
\n\n \n
\n
\n \ + \ \n
\n
\n \"DHL\n
\n
\n\ + \ \n\n \n\n \n
\n
\n
\n\n\n
\n\n\n\n\n\n
\n\n\ + \n\n\n\ + \n\n\n\n\n\n\n\n\n\n
\n\n\ + \n\n\n\n
Impresión Sub Usuario - Ordenes\ + \ de Compra
\n
\n\n\ + \n\n\ + \n\n
\n\n\n\n\n\ + \n\n\ + \n\n\n\n\n
619434seleccionar
Ordenes de Compra
FolioFecha de CaducidadTotal de GuíasGuías UsadasGuías DisponiblesSeleccionar
1002913430/12/20203053050
1002913830/12/20204344340
1002967224/01/20211,053
\"\"
\n
\n
\"\
\n\n\n\n\ + \n\n\n\n\n
\"\"
\n\ +
\n
\n\n \ + \
\n
\n \ + \
\n
\n \n\n
\n
\n\ +
\n\n
Cliente
Cliente
\n\n\n\n\n\n\ + \n\n\n\n\n\ + \n\n\ + \n\n\n\n\n\n\ +
\n\nImpresión Sub Usuario
Guías Impresas
Asignar Recolección (SubUsuario)
Manual de Usuario
\n
Reportes
Reportes
\n\n\n\n\n\ + \n\n
Guías Generadas (SubUsuario)
\n
Salir
Salir
\n\n\n\n\n\n\n\n\n\n\n\ +
Cambiar Password
Cerrar Sesión
\n
\n
\n
\n\ + \
\n
\n \n\n \n
\n \n \"Deutsche\n \n
\n\n \ + \ \n \n" + headers: + Content-Type: + - text/html;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:22:22 GMT + Server: + - Apache-Coyote/1.1 + Transfer-Encoding: + - chunked + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +- request: + body: AJAXREQUEST=_viewRoot&j_id6=j_id6&javax.faces.ViewState=j_id3&j_id6%3AtblElementos%3A2%3AlinkEditar=j_id6%3AtblElementos%3A2%3AlinkEditar + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '137' + Content-Type: + - application/x-www-form-urlencoded + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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://prepaid.dhl.com.mx/Prepago/jsp/app/cliente/impresionClienteSubUsuario.xhtml + response: + body: + string: "\r\n\r\n
Capturar Gu\xEDas a Imprimir
Productos Disponibles
Descripci\xF3nGu\xEDas TotalesGu\xEDas ImpresasGu\xEDas DisponiblesGu\xEDas a Imprimir
Totales10536194340
Documento\ + \ 1 KG1,053619434
" + headers: + Ajax-Response: + - 'true' + Cache-Control: + - no-cache, must-revalidate, max_age=0, no-store + Content-Length: + - '6686' + Content-Type: + - text/xml;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:22:22 GMT + Expires: + - '0' + Pragma: + - no-cache + Server: + - Apache-Coyote/1.1 + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +- request: + body: AJAXREQUEST=_viewRoot&j_id6=j_id6&j_id6%3Aj_id48%3A0%3Aj_id71=1&javax.faces.ViewState=j_id3&j_id6%3Aj_id48%3A0%3Aj_id72=j_id6%3Aj_id48%3A0%3Aj_id72&AJAX%3AEVENTS_COUNT=1 + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '169' + Content-Type: + - application/x-www-form-urlencoded + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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://prepaid.dhl.com.mx/Prepago/jsp/app/cliente/impresionClienteSubUsuario.xhtml + response: + body: + string: "\r\n\r\n1
" + headers: + Ajax-Response: + - 'true' + Cache-Control: + - no-cache, must-revalidate, max_age=0, no-store + Content-Length: + - '4128' + Content-Type: + - text/xml;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:22:22 GMT + Expires: + - '0' + Pragma: + - no-cache + Server: + - Apache-Coyote/1.1 + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +- request: + body: AJAXREQUEST=_viewRoot&j_id6=j_id6&j_id6%3Aj_id48%3A0%3Aj_id71=1&javax.faces.ViewState=j_id3&j_id6%3AbtnGuardarCotizacion=j_id6%3AbtnGuardarCotizacion + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '149' + Content-Type: + - application/x-www-form-urlencoded + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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://prepaid.dhl.com.mx/Prepago/jsp/app/cliente/impresionClienteSubUsuario.xhtml + response: + body: + string: ' + + ' + headers: + Ajax-Response: + - redirect + Cache-Control: + - no-cache, must-revalidate, max_age=0, no-store + Content-Type: + - text/xml;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:22:22 GMT + Expires: + - '0' + Location: + - /Prepago/jsp/app/cliente/capturaDatosImpresionClienteSU.xhtml + Pragma: + - no-cache + Server: + - Apache-Coyote/1.1 + Transfer-Encoding: + - chunked + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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: GET + uri: https://prepaid.dhl.com.mx/Prepago/jsp/app/cliente/capturaDatosImpresionClienteSU.xhtml + response: + body: + string: "\n\n\n \n \n Datos\ + \ de Impresión\n \n \n \n \n \n \n \n \n \n\ + \
\n \n
\n\n \n
\n
\n \ + \ \n
\n
\n \"DHL\n
\n
\n\ + \ \n\n \n\n \n
\n
\n
\n\n\n
\n\n\ + \n
\n\n\n\ + \n\n\n
Impresión Sub Usuario- Capturar información
\n\n\n\n\n\n\n\n\n
\"\"
\"\"
\"\"\"\"
Remitente
\"\"
\"\"\
\"\"
Destinatario
\"\"
\"\"\
\"\"
Detalles
\"\"
\"\"\
\n\n\n\ + \n\ + \n\n\n\n\n\n\n\ + \n\n\n\n\n\n\n\n\n\n\ + \n\n\n\n\ + \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\ + \n\ + \n\n\n
* Compañia:
* Contacto:
Correo:
* Teléfono:
* Dirección 1:
Línea 2:
Referencia:
* Código Postal:
* Colonia
* Ciudad:
* Estado:
\n\ +
\n\n\n\ + \n\ + \n\n\n\n\n\n\n\ + \n\n\n\n\ + \n\ + \n\n\n\n\n\ + \n\n\n\n\ + \n\n\n\n\ + \n\n\n\n\n\n\n\n\n\n\n\n\n\n\ + \n\ + \n\n\n
* Compañia:
* Contacto:
Correo:
* Teléfono:
* Dirección 1:
Linea 2:
Referencia:
* Código\ + \ Postal:
* Colonia
* Ciudad:
* Estado:
\n\ +
\n\n\n\ + \n\ + \n\n\n\n\n\n\n\ +
*Descripción:
Contenido de\ + \ la Pieza:
\n
\n\n\n\ + La información marcada con (*) debe ser capturada.\n\n\n\n\ + \n\n\n\n\n\n
\n\ + \n\n\n\n\n\n\n\n\n\ + \n
\n\n\n\n\n\n\n\n\ + \n\n
\n \n
Confirmación\ + \ antes de imprimir
\n
\n\n\n\n\n\n\ + \n\n\n\n\n
Todas las guías seleccionadas para imprimir\ + \ aparecerán con los datos ingresados en esa sección.
\n\n\ + \n\n\n\n\n\ +
\n
\n\n\ +
Generando Guías...
\n\n\n\n\n\n\n\n\n\n\n\n
\n\n\n\n\ + \n\n
\n
\n \ + \
\n\n\n\n\n\n\ +
\n
\n\n \n function limitArea(valor,maximo){\n\ + \ if(valor.length > maximo){\n \ + \ valor = valor.substring(0,maximo);\n \ + \ }\n return valor;\n \ + \ }\n \n \n
Confirmación Cerrar
\n
\n\n\n\n\n\n\n\n\n\n\n\n\ + \n\n\n\n\n
Estimado Usuario:
\n \ + \
Podrá encontrar la(s)\ + \ guía(s) generada(s) en esta sección. Le recordamos que sólo\ + \ estarán disponibles 24 horas, le invitamos a guardar sus archivos.
\n\n\ + \n\n\n\n\ +
\n
\n\n\ +
\n \n \ + \ \n \n\n
\n
\n\ +
\n\n
Cliente
Cliente
\n\n\n\n\n\n\ + \n\n\n\n\n\ + \n\n\ + \n\n\n\n\n\n\ +
\n\nImpresión Sub Usuario
Guías Impresas
Asignar Recolección (SubUsuario)
Manual de Usuario
\n
Reportes
Reportes
\n\n\n\n\n\ + \n\n
Guías Generadas (SubUsuario)
\n
Salir
Salir
\n\n\n\n\n\n\n\n\n\n\n\ +
Cambiar Password
Cerrar Sesión
\n
\n
\n
\n\ + \
\n \n \n\n \n
\n \n \"Deutsche\n \n
\n\n \ + \ \n \n" + headers: + Content-Type: + - text/html;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:22:23 GMT + Server: + - Apache-Coyote/1.1 + Transfer-Encoding: + - chunked + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +- request: + body: AJAXREQUEST=_viewRoot&datos=datos&datos%3Aj_id10=j_id11&datos%3Aj_id15=&datos%3Aj_id19=&datos%3AemailOrigen=&datos%3Aj_id24=&datos%3Aj_id28=&datos%3Aj_id30=&datos%3Aj_id32=&datos%3Aj_id36=06600&datos%3Aj_id41=&datos%3Aj_id45=&datos%3Aj_id49=&datos%3Aj_id54=&datos%3Aj_id58=&datos%3AemailDestino=&datos%3Aj_id63=&datos%3Aj_id67=&datos%3Aj_id69=&datos%3Aj_id71=&datos%3Aj_id75=&datos%3Aj_id80=&datos%3Aj_id84=&datos%3Aj_id88=&datos%3Aj_id93=&datos%3Aj_id95=&javax.faces.ViewState=j_id4&datos%3Aj_id37=datos%3Aj_id37 + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '513' + Content-Type: + - application/x-www-form-urlencoded + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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://prepaid.dhl.com.mx/Prepago/jsp/app/cliente/capturaDatosImpresionClienteSU.xhtml + response: + body: + string: "\r\n\r\nCorreo:* Tel\xE9fono:L\xEDnea 2:Referencia:* C\xF3digo Postal:* Estado:
* Compa\xF1\ + ia:
* Contacto:
* Direcci\xF3n 1:
* Colonia
* Ciudad:
C\xF3digo Postal\ + \ v\xE1lido
" + headers: + Ajax-Response: + - 'true' + Cache-Control: + - no-cache, must-revalidate, max_age=0, no-store + Content-Length: + - '6077' + Content-Type: + - text/xml;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:22:24 GMT + Expires: + - '0' + Pragma: + - no-cache + Server: + - Apache-Coyote/1.1 + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +- request: + body: AJAXREQUEST=_viewRoot&datos=datos&datos%3Aj_id10=j_id11&datos%3Aj_id15=&datos%3Aj_id19=&datos%3AemailOrigen=&datos%3Aj_id24=&datos%3Aj_id28=&datos%3Aj_id30=&datos%3Aj_id32=&datos%3Aj_id36=06600&datos%3Aj_id41=&datos%3Aj_id45=&datos%3Aj_id49=&datos%3Aj_id54=&datos%3Aj_id58=&datos%3AemailDestino=&datos%3Aj_id63=&datos%3Aj_id67=&datos%3Aj_id69=&datos%3Aj_id71=&datos%3Aj_id75=06600&datos%3Aj_id80=&datos%3Aj_id84=&datos%3Aj_id88=&datos%3Aj_id93=&datos%3Aj_id95=&javax.faces.ViewState=j_id4&datos%3Aj_id76=datos%3Aj_id76 + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '518' + Content-Type: + - application/x-www-form-urlencoded + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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://prepaid.dhl.com.mx/Prepago/jsp/app/cliente/capturaDatosImpresionClienteSU.xhtml + response: + body: + string: "\r\n\r\nCorreo:* Tel\xE9fono:Linea 2:Referencia:* C\xF3digo Postal:* Estado:
* Compa\xF1\ + ia:
* Contacto:
* Direcci\xF3n 1:
* Colonia
* Ciudad:
C\xF3digo Postal\ + \ v\xE1lido
" + headers: + Ajax-Response: + - 'true' + Cache-Control: + - no-cache, must-revalidate, max_age=0, no-store + Content-Length: + - '6167' + Content-Type: + - text/xml;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:22:24 GMT + Expires: + - '0' + Pragma: + - no-cache + Server: + - Apache-Coyote/1.1 + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +- request: + body: AJAXREQUEST=_viewRoot&datos=datos&datos%3Aj_id10=j_id11&datos%3Aj_id15=CUENCA+LABS&datos%3Aj_id19=GINO+LAPI&datos%3AemailOrigen=gino%40cuenca.com&datos%3Aj_id24=5544364200&datos%3Aj_id28=VARSOVIA+36&datos%3Aj_id30=&datos%3Aj_id32=&datos%3Aj_id36=06600&datos%3Aj_id41=JUAREZ&datos%3Aj_id45=CUAUHTEMOC&datos%3Aj_id49=CMX&datos%3Aj_id54=GREGORIO+CASTRO&datos%3Aj_id58=GREGORIO+CASTRO&datos%3AemailDestino=greg%40gmail.com&datos%3Aj_id63=550909090&datos%3Aj_id67=REFORMA+222&datos%3Aj_id69=&datos%3Aj_id71=CASA+COLOR+VERDE&datos%3Aj_id75=06600&datos%3Aj_id80=JUAREZ&datos%3Aj_id84=&datos%3Aj_id88=CDMX&datos%3Aj_id93=Tarjetas+de+presentacion&datos%3Aj_id95=&javax.faces.ViewState=j_id4&datos%3Aj_id105=datos%3Aj_id105 + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '713' + Content-Type: + - application/x-www-form-urlencoded + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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://prepaid.dhl.com.mx/Prepago/jsp/app/cliente/capturaDatosImpresionClienteSU.xhtml + response: + body: + string: "\r\n\r\n
Ciudad Destinatario es requerido
if(data){validaEmails();}if(data){validaEmails();}" + headers: + Ajax-Response: + - 'true' + Cache-Control: + - no-cache, must-revalidate, max_age=0, no-store + Content-Length: + - '4195' + Content-Type: + - text/xml;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:22:26 GMT + Expires: + - '0' + Pragma: + - no-cache + Server: + - Apache-Coyote/1.1 + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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://prepaid.dhl.com.mx/Prepago/jsp/app/inicio/inicio.xhtml + response: + body: + string: "\n\n\n \n \n Administrar\n\ + \ \n \n \n \n \n \n \n \n \n\ + \
\n \n
\n\n \n
\n
\n \ + \ \n
\n
\n \"DHL\n
\n
\n\ + \ \n\n \n\n \n
\n
\n
\n \n
\n
\n\ + \
\n \n\n
\n
\n\ +
\n\n
Cliente
Cliente
\n\n\n\n\n\n\ + \n\n\n\n\n\ + \n\n\ + \n\n\n\n\n\n\ +
\n\nImpresión Sub Usuario
Guías Impresas
Asignar Recolección (SubUsuario)
Manual de Usuario
\n
Reportes
Reportes
\n\n\n\n\n\ + \n\n
Guías Generadas (SubUsuario)
\n
Salir
Salir
\n\n\n\n\n\n\n\n\n\n\n\ +
Cambiar Password
Cerrar Sesión
\n
\n
\n
\n\ + \
\n
\n \n\n \n
\n \n \"Deutsche\n \n
\n\n \ + \ \n \n" + headers: + Content-Type: + - text/html;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:22:26 GMT + Server: + - Apache-Coyote/1.1 + Transfer-Encoding: + - chunked + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +- request: + body: j_id9=j_id9&j_id9%3Aj_id30=j_id9%3Aj_id30&javax.faces.ViewState=j_id5 + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '69' + Content-Type: + - application/x-www-form-urlencoded + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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://prepaid.dhl.com.mx/Prepago/jsp/app/inicio/inicio.xhtml + response: + body: + string: '' + headers: + Content-Length: + - '0' + Date: + - Wed, 05 Feb 2020 14:22:26 GMT + Location: + - http://prepaid.dhl.com.mx/Prepago/jsp/app/login/login.xhtml + Server: + - Apache-Coyote/1.1 + X-Powered-By: + - JSF/1.2 + status: + code: 302 + message: Found +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746 + 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: GET + uri: http://prepaid.dhl.com.mx/Prepago/jsp/app/login/login.xhtml + response: + body: + string: '' + headers: + Connection: + - Keep-Alive + Content-Length: + - '0' + Location: + - https://prepaid.dhl.com.mx/Prepago/jsp/app/login/login.xhtml + Server: + - BigIP + status: + code: 302 + message: Found +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Cookie: + - JSESSIONID=8A8EC9BCEEB5E9A146867958CC475746; BIGipServerpl_prepaid.com.mx_80=1029802396.20480.0000 + 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: GET + uri: https://prepaid.dhl.com.mx/Prepago/jsp/app/login/login.xhtml + response: + body: + string: "\n\n\n \n \n Login\ + \ / Admin\n \n \n \n \n \n \n \n \n \n\ + \
\n \n
\n\n \n
\n
\n \ + \ \n
\n
\n \"DHL\n
\n
\n\ + \ \n\n \n\n \n
\n
\n
\n\n\n \ + \
\n\n\n\n\n\n
\n\n\n\n\n\n\n\n\n\n\n\n\ +
Prepago\ + \ DHL
Debe autenticarse en el sistema para acceder
\n\n\n\n\n\n\ + \n\ + \n\n\n\n\n\ + \n\n\n
\n\n\n\n\n\ + \n\n\n\n\n\n
Usuario:
Contraseña:
\n
Recuperar Contraseña
\n\n\n\n\n\n\ + \n
\n
\n
\n
\n\n
\n
Recuperar Contraseña
\n
\n\n\n\n\n\n\n\n\n\n\n\n
Recuperación\ + \ de Contraseña
Usuario:
\n\"\
\"\"\n\n\n\n\n\n\n\ +
\n\n
new ModalPanel('pnlUsuario',\n\t\t\t\t{\n\t\t\t\ + \t\twidth: 400,\n\t\t\t\t\theight: 200,\n\n\t\t\t\t\tminWidth: -1,\n\t\t\t\ + \t\tminHeight: -1,\n\n\t\t\t\t\tresizeable: true,\n\t\t\t\t\tmoveable: true,\n\ + \n\t\t\t\t\tleft: \"auto\",\n\t\t\t\t\ttop: \"auto\",\n\n\t\t\t\t\tzindex:\ + \ 100,onresize: '',onmove: '',onshow: '',onhide: '',onbeforeshow: '',onbeforehide:\ + \ '',\n\t\t\t\t\tdomElementAttachment: \"\",\t\t\t\t\n\t\t\t\t\tkeepVisualState:\ + \ false,\n\t\t\t\t\tshowWhenRendered: false,\n\t\t\t\t\tselectBehavior: \"\ + disable\",\n\n\t\t\t\t\tautosized: false,\n\t\t\t\t\toverlapEmbedObjects:\ + \ false});
\n\ + \ \n \n \n\n \n \ + \ \n \n \n\n \n
\n \n \"Deutsche\n \n
\n\n \ + \ \n \n" + headers: + Content-Type: + - text/html;charset=UTF-8 + Date: + - Wed, 05 Feb 2020 14:22:26 GMT + Server: + - Apache-Coyote/1.1 + Set-Cookie: + - JSESSIONID=DED9B0B472206CC966610596EB9EB72F; Path=/Prepago/; HttpOnly + Transfer-Encoding: + - chunked + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +version: 1 diff --git a/tests/resources/test_invalid_data.py b/tests/resources/test_invalid_data.py index 09625a7..c6e8ae5 100644 --- a/tests/resources/test_invalid_data.py +++ b/tests/resources/test_invalid_data.py @@ -5,7 +5,6 @@ @pytest.mark.vcr def test_invalid_destination(client, origin, invalid_destination, details): - with pytest.raises(DhlmexException) as execinfo: client.guides.create_guide(origin, invalid_destination, details) assert str(execinfo) == 'Error while creating guide' @@ -13,7 +12,13 @@ def test_invalid_destination(client, origin, invalid_destination, details): @pytest.mark.vcr def test_invalid_postal_code(client, origin, invalid_postal_code, details): - with pytest.raises(DhlmexException) as execinfo: client.guides.create_guide(origin, invalid_postal_code, details) assert str(execinfo.value) == 'Invalid destiny postal code' + + +@pytest.mark.vcr +def test_missing_city(client, origin, missing_data, details): + with pytest.raises(DhlmexException) as execinfo: + client.guides.create_guide(origin, missing_data, details) + assert str(execinfo.value) == 'Invalid value' diff --git a/tests/test_client_login.py b/tests/test_client_login.py index eb80510..45d3700 100644 --- a/tests/test_client_login.py +++ b/tests/test_client_login.py @@ -21,6 +21,26 @@ def test_successful_login(site_urls): assert 'Administrar' in soup.find('title').text +@pytest.mark.vcr +def test_invalid_creds(): + with pytest.raises(DhlmexException) as execinfo: + client = Client('invalidUsername', 'invalidPassword') + assert str(execinfo.value) == f'Invalid credentials' + assert client + + +def test_debug_login(): + os.environ['DEBUG'] = 'True' + with pytest.raises(DhlmexException) as execinfo: + client = Client(DHLMEX_USERNAME, DHLMEX_PASSWORD) + assert ( + str(execinfo.value) == f'Client on debug, but Charles not running' + ) + assert client.session.cert + client._logout() + os.environ['DEBUG'] = '' + + @pytest.mark.vcr def test_client_log_out(): client = Client(DHLMEX_USERNAME, DHLMEX_PASSWORD)