Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/conftest.py
Show First 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | |||||
@pytest.fixture | @pytest.fixture | ||||
def client(): | def client(): | ||||
"""Override pytest-django one which does not work for djangorestframework. | """Override pytest-django one which does not work for djangorestframework. | ||||
""" | """ | ||||
return APIClient() # <- drf's client | return APIClient() # <- drf's client | ||||
@pytest.yield_fixture | @pytest.fixture | ||||
def authenticated_client(client, deposit_user): | def authenticated_client(client, deposit_user): | ||||
"""Returned a logged client | """Returned a logged client | ||||
This also patched the client instance to keep a reference on the associated | |||||
deposit_user. | |||||
""" | """ | ||||
_token = "%s:%s" % (deposit_user.username, TEST_USER["password"]) | _token = "%s:%s" % (deposit_user.username, TEST_USER["password"]) | ||||
token = base64.b64encode(_token.encode("utf-8")) | token = base64.b64encode(_token.encode("utf-8")) | ||||
authorization = "Basic %s" % token.decode("utf-8") | authorization = "Basic %s" % token.decode("utf-8") | ||||
client.credentials(HTTP_AUTHORIZATION=authorization) | client.credentials(HTTP_AUTHORIZATION=authorization) | ||||
client.deposit_client = deposit_user | |||||
yield client | yield client | ||||
client.logout() | client.logout() | ||||
@pytest.fixture | @pytest.fixture | ||||
def sample_archive(tmp_path): | def sample_archive(tmp_path): | ||||
"""Returns a sample archive | """Returns a sample archive | ||||
▲ Show 20 Lines • Show All 218 Lines • Show Last 20 Lines |