35 lines
918 B
Python
35 lines
918 B
Python
import base64
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def static_files(settings, tmp_path):
|
|
"""The manifest storage needs collectstatic, which tests don't run."""
|
|
settings.STATIC_ROOT = tmp_path / "static"
|
|
settings.STATIC_ROOT.mkdir()
|
|
settings.STORAGES = {
|
|
**settings.STORAGES,
|
|
"staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"},
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def admin(django_user_model):
|
|
return django_user_model.objects.create_superuser("admin", "admin@example.com", "secret")
|
|
|
|
|
|
@pytest.fixture
|
|
def api(client, admin):
|
|
"""A Django test client authenticated with HTTP Basic auth."""
|
|
token = base64.b64encode(b"admin:secret").decode()
|
|
client.defaults["HTTP_AUTHORIZATION"] = f"Basic {token}"
|
|
return client
|
|
|
|
|
|
@pytest.fixture
|
|
def domain(db):
|
|
from dpdapi.models import Domain
|
|
|
|
return Domain.objects.create(name="example.com")
|