File: conftest.py

package info (click to toggle)
python-authlib 1.6.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,024 kB
  • sloc: python: 27,412; makefile: 53; sh: 14
file content (49 lines) | stat: -rw-r--r-- 987 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os

import pytest

from authlib.integrations.django_oauth2 import AuthorizationServer

from .models import Client
from .models import OAuth2Token
from .models import User

pytestmark = pytest.mark.django_db


@pytest.fixture(autouse=True)
def env():
    os.environ["AUTHLIB_INSECURE_TRANSPORT"] = "true"
    yield
    os.environ.pop("AUTHLIB_INSECURE_TRANSPORT", None)


@pytest.fixture(autouse=True)
def server(settings):
    settings.AUTHLIB_OAUTH2_PROVIDER = {}
    return AuthorizationServer(Client, OAuth2Token)


@pytest.fixture(autouse=True)
def user(db):
    user = User(username="foo")
    user.set_password("ok")
    user.save()
    yield user
    user.delete()


@pytest.fixture
def token(user):
    token = OAuth2Token(
        user_id=user.pk,
        client_id="client-id",
        token_type="bearer",
        access_token="a1",
        refresh_token="r1",
        scope="profile",
        expires_in=3600,
    )
    token.save()
    yield token
    token.delete()