From c3116347a832d8d5e7ff7fbbdcb53f703488a86d Mon Sep 17 00:00:00 2001 From: alan Date: Wed, 5 Feb 2020 08:38:32 -0600 Subject: [PATCH] Add missing data tests --- dhlmex/client.py | 1 - dhlmex/resources/base.py | 29 +- dhlmex/resources/guides.py | 8 +- tests/cassettes/test_invalid_creds.yaml | 318 +++ tests/conftest.py | 15 + .../cassettes/test_missing_city.yaml | 2520 +++++++++++++++++ tests/resources/test_invalid_data.py | 9 +- tests/test_client_login.py | 9 + 8 files changed, 2883 insertions(+), 26 deletions(-) create mode 100644 tests/cassettes/test_invalid_creds.yaml create mode 100644 tests/resources/cassettes/test_missing_city.yaml diff --git a/dhlmex/client.py b/dhlmex/client.py index d2ec865..67e5fbd 100644 --- a/dhlmex/client.py +++ b/dhlmex/client.py @@ -55,7 +55,6 @@ def _login(self, username: str, password: str) -> Response: 'javax.faces.ViewState': 'j_id1', 'j_id6:j_id29': 'j_id6:j_id29', } - print(f'DEBUG: {data}') resp = self.post(endpoint, data) except HTTPError as httpe: if 'Su sesiĆ³n ha caducado' in resp.text: diff --git a/dhlmex/resources/base.py b/dhlmex/resources/base.py index 15fdf13..a03a497 100644 --- a/dhlmex/resources/base.py +++ b/dhlmex/resources/base.py @@ -4,8 +4,6 @@ from bs4 import BeautifulSoup from requests import Response -from dhlmex.exceptions import DhlmexException - class Resource: _client: ClassVar["dhlmex.Client"] # type: ignore @@ -41,20 +39,15 @@ def get_data(resp: Response, action: Dict) -> Dict: view_state = soup.find('input', id='javax.faces.ViewState').attrs[ 'value' ] - a = soup.find('a', text=action['text']) - if a is None: - print(f'DEBUG: {resp.text}') - raise DhlmexException('Debug') - else: - js = soup.find('a', text=action['text']).attrs['onclick'] - matches = re.findall(r"\'(.+?)\'", js) - form_ids = [match for match in matches if match.startswith('j_id')] - j_pair_id = form_ids[1].split(',')[0] - j_id = form_ids[0] + js = soup.find('a', text=action['text']).attrs['onclick'] + matches = re.findall(r"\'(.+?)\'", js) + form_ids = [match for match in matches if match.startswith('j_id')] + j_pair_id = form_ids[1].split(',')[0] + j_id = form_ids[0] - return { - j_id: j_id, - j_pair_id: action['code'], - 'javax.faces.ViewState': view_state, - action['end']: action['end'], - } + return { + j_id: j_id, + j_pair_id: action['code'], + 'javax.faces.ViewState': view_state, + action['end']: action['end'], + } diff --git a/dhlmex/resources/guides.py b/dhlmex/resources/guides.py index 3cae045..24156ed 100644 --- a/dhlmex/resources/guides.py +++ b/dhlmex/resources/guides.py @@ -16,8 +16,7 @@ class Guide(Resource): @classmethod def create_guide( - cls, origin: Origin, destination: Destination, - details: OrderDetails, + cls, origin: Origin, destination: Destination, details: OrderDetails, ) -> Tuple[str, Optional[bytes]]: guide = cls() try: @@ -96,8 +95,7 @@ def _select_guide(self, guides_data: Dict) -> Dict: return select_data def _fill_guide_table( - self, origin: Origin, destination: Destination, - details: OrderDetails + self, origin: Origin, destination: Destination, details: OrderDetails ) -> str: resp = self._client.get(self._urls['capture']) soup = BeautifulSoup(resp.text, features='html.parser') @@ -130,7 +128,7 @@ def _fill_guide_table( fill_data['javax.faces.ViewState'] = view_state fill_data['datos:j_id105'] = 'datos:j_id105' - msg = self._validate_data() + msg = self._validate_data(fill_data) if msg: raise DhlmexException(f'Invalid data: {msg}') else: 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 226acba..45d3700 100644 --- a/tests/test_client_login.py +++ b/tests/test_client_login.py @@ -21,6 +21,14 @@ 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: @@ -30,6 +38,7 @@ def test_debug_login(): ) assert client.session.cert client._logout() + os.environ['DEBUG'] = '' @pytest.mark.vcr