import django
import pytest

from tests.factories import make_user
from vq_django_auth.choices import AuthMethod

USERNAME = "person1@world.com"
PWD = "person"
EMAIL = "person1@world.com"


def pytest_configure(config):
    from django.conf import settings

    settings.configure(
        INSTALLED_APPS=(
            "django.contrib.auth",
            "django.contrib.contenttypes",
            "vq_django_auth",
            "rest_framework",
            "rest_framework.authtoken",
            "django.contrib.sessions",
        ),
        ROOT_URLCONF="vq_django_auth.urls",
        DATABASES={
            "default": {
                "ENGINE": "django.db.backends.sqlite3",
                "NAME": ":memory:",
            },
        },
        SECRET_KEY="insecure",
        MIDDLEWARE=(
            "django.middleware.common.CommonMiddleware",
            "django.contrib.sessions.middleware.SessionMiddleware",
            "django.middleware.csrf.CsrfViewMiddleware",
            "django.contrib.auth.middleware.AuthenticationMiddleware",
            "django.contrib.messages.middleware.MessageMiddleware",
        ),
        REST_FRAMEWORK={
            "DEFAULT_AUTHENTICATION_CLASSES": [
                "rest_framework.authentication.BasicAuthentication",
                "rest_framework.authentication.SessionAuthentication",
                "rest_framework.authentication.TokenAuthentication",
            ]
        },
        TEMPLATES=[
            {
                "BACKEND": "django.template.backends.django.DjangoTemplates",
                "APP_DIRS": True,
                "OPTIONS": {
                    "context_processors": [
                        "django.contrib.auth.context_processors.auth",
                        "django.contrib.messages.context_processors.messages",
                    ]
                },
            },
        ],
        VQ_REST_AUTH={
            "AUTH_METHOD": AuthMethod.SESSION,
            "VQ_AUTH_THROTTLE": "30/sec",
        },
    )
    django.setup()


@pytest.fixture
def user():
    return make_user(
        username=USERNAME,
        email=EMAIL,
        pwd=PWD,
    )
