diff --git a/setup.cfg b/setup.cfg index 036db29..aaa1d7f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,7 +2,7 @@ test=pytest [tool:pytest] -addopts = -p no:warnings -v --cov=mati +addopts = -p no:warnings -v --cov=dhlmex [flake8] inline-quotes = ' @@ -14,8 +14,8 @@ include_trailing_comma=True force_grid_wrap=0 combine_as_imports=True -[mypy-iso8601] +[mypy-pytest] ignore_missing_imports = true -[mypy-pytest] -ignore_missing_imports = true \ No newline at end of file +[mypy-vcr] +ignore_missing_imports = true diff --git a/setup.py b/setup.py index 7f8bc3e..9468920 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,6 @@ install_requires=[ 'dataclasses>=0.6;python_version<"3.7"', 'requests>=2.22.0,<3.0.0', - 'iso8601>=0.1.12,<0.2.0', ], setup_requires=['pytest-runner'], tests_require=test_requires, diff --git a/tests/cassettes/test_successful_login.yaml b/tests/cassettes/test_successful_login.yaml new file mode 100644 index 0000000..1916c36 --- /dev/null +++ b/tests/cassettes/test_successful_login.yaml @@ -0,0 +1,252 @@ +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
\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: + - Sun, 17 Nov 2019 23:30:50 GMT + Server: + - Apache-Coyote/1.1 + Set-Cookie: + - JSESSIONID=B5470032B5F652B29B9BA82DD96D17E1; 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_id4%27%5D&j_id6%3Aj_id29=%5B%27j_id6%3Aj_id29%27%5D + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '161' + Content-Type: + - application/x-www-form-urlencoded + Cookie: + - JSESSIONID=B5470032B5F652B29B9BA82DD96D17E1; 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-Expired: + - View state could't be restored - reload page ? + Ajax-Response: + - 'true' + Cache-Control: + - no-cache, must-revalidate, max_age=0, no-store + Content-Type: + - text/xml;charset=UTF-8 + Date: + - Sun, 17 Nov 2019 23:30:50 GMT + Expires: + - '0' + Pragma: + - no-cache + Server: + - Apache-Coyote/1.1 + Transfer-Encoding: + - chunked + X-Powered-By: + - JSF/1.2 + status: + code: 200 + message: OK +version: 1 diff --git a/tests/conftest.py b/tests/conftest.py index c08cb26..70bb05e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,14 +1,21 @@ +from urllib import parse + import pytest -from requests import Request +from vcr import request -def remove_creds(request: Request) -> Request: - # remove username and password +def remove_creds(request: request.Request) -> request.Request: + if request.path.endswith('/jsp/app/login/login.xhtml'): + username_key = 'j_id6:j_id20' + password_key = 'j_id6:j_id22' + body = parse.parse_qs(request.body.decode('utf-8')) + body[username_key] = ['USERNAME'] + body[password_key] = ['PASSWORD'] + request.body = parse.urlencode(body) return request @pytest.fixture(scope='module') def vcr_config() -> dict: - config = dict() - config['before_record_request'] = remove_creds - return config \ No newline at end of file + config = dict(before_record_request=remove_creds) + return config diff --git a/tests/test_client_login.py b/tests/test_client_login.py index 7098df3..edb818d 100644 --- a/tests/test_client_login.py +++ b/tests/test_client_login.py @@ -10,5 +10,5 @@ @pytest.mark.vcr def test_successful_login(): + # Just need to make sure it doesn't throw an exception assert Client(DHLMEX_USERNAME, DHLMEX_PASSWORD) -