Open PythonCoderAS opened 3 years ago
When I try to run a simple test to log in to this API, I get an AttributeError:
AttributeError
_____________________________________________________________________________________________________________ test_login ______________________________________________________________________________________________________________ username = '<censored>', password = '<censored>' @pytest.mark.asyncio @pytest.mark.vcr() async def test_login(username, password): async with MangadexClient(username=username, password=password) as client: > await client.login() tests/test_client.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ asyncdex/client.py:412: in login r = await self.request( asyncdex/client.py:273: in request resp = await self.session.request(method, url, headers=headers, json=json, **session_request_kwargs) ../../.local/share/virtualenvs/AsyncDex-nRbDnH62/lib/python3.8/site-packages/vcr/stubs/aiohttp_stubs.py:257: in new_request if cassette.can_play_response_for(vcr_request): ../../.local/share/virtualenvs/AsyncDex-nRbDnH62/lib/python3.8/site-packages/vcr/cassette.py:255: in can_play_response_for request = self._before_record_request(request) ../../.local/share/virtualenvs/AsyncDex-nRbDnH62/lib/python3.8/site-packages/vcr/config.py:223: in before_record_request request = function(request) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ request = <Request (POST) https://api.mangadex.org/auth/login>, replacements = {'password': 'PASSWORD', 'refresh_token': 'REFRESH_TOKEN', 'username': 'USERNAME'} def replace_post_data_parameters(request, replacements): """Replace post data in request--either form data or json--according to replacements. The replacements should be a list of (key, value) pairs where the value can be any of: 1. A simple replacement string value. 2. None to remove the given header. 3. A callable which accepts (key, value, request) and returns a string value or None. """ if not request.body: # Nothing to replace return request replacements = dict(replacements) if request.method == "POST" and not isinstance(request.body, BytesIO): if request.headers.get("Content-Type") == "application/json": json_data = json.loads(request.body.decode("utf-8")) for k, rv in replacements.items(): if k in json_data: ov = json_data.pop(k) if callable(rv): rv = rv(key=k, value=ov, request=request) if rv is not None: json_data[k] = rv request.body = json.dumps(json_data).encode("utf-8") else: if isinstance(request.body, str): request.body = request.body.encode("utf-8") > splits = [p.partition(b"=") for p in request.body.split(b"&")] E AttributeError: 'dict' object has no attribute 'split' ../../.local/share/virtualenvs/AsyncDex-nRbDnH62/lib/python3.8/site-packages/vcr/filters.py:100: AttributeError ======================================================================================================= short test summary info ======================================================================================================= FAILED tests/test_client.py::test_login - AttributeError: 'dict' object has no attribute 'split'
This is my conftest.py:
conftest.py
import os import pytest @pytest.fixture(scope="session") def vcr_config(): return { "filter_headers": [("authorization", "AUTHORIZATION")], "filter_post_data_parameters": [('username', "USERNAME"), ('password', "PASSWORD"), ('refresh_token', "REFRESH_TOKEN")] } @pytest.fixture def username(): return os.environ["asyncdex_username"] @pytest.fixture def password(): return os.environ["asyncdex_password"] @pytest.fixture def refresh_token(): return os.environ["asyncdex_refresh_token"]
I am using the pytest-asyncio and pytest-recording packages.
pytest-asyncio
pytest-recording
When I try to run a simple test to log in to this API, I get an
AttributeError
:This is my
conftest.py
:I am using the
pytest-asyncio
andpytest-recording
packages.