File: conftest.py

package info (click to toggle)
python-authlib 1.6.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,024 kB
  • sloc: python: 27,329; makefile: 53; sh: 14
file content (59 lines) | stat: -rw-r--r-- 1,424 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
50
51
52
53
54
55
56
57
58
59
import os

import pytest

from authlib.integrations.django_oauth1 import CacheAuthorizationServer

from .models import Client
from .models import TokenCredential
from .models import User

pytestmark = pytest.mark.django_db


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


@pytest.fixture
def server(settings):
    """Create server that respects current settings."""
    return CacheAuthorizationServer(Client, TokenCredential)


@pytest.fixture
def plaintext_server(settings):
    """Server configured with PLAINTEXT signature method."""
    settings.AUTHLIB_OAUTH1_PROVIDER = {"signature_methods": ["PLAINTEXT"]}
    return CacheAuthorizationServer(Client, TokenCredential)


@pytest.fixture
def rsa_server(settings):
    """Server configured with RSA-SHA1 signature method."""
    settings.AUTHLIB_OAUTH1_PROVIDER = {"signature_methods": ["RSA-SHA1"]}
    return CacheAuthorizationServer(Client, TokenCredential)


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


@pytest.fixture(autouse=True)
def client(user, db):
    client = Client(
        user_id=user.pk,
        client_id="client",
        client_secret="secret",
        default_redirect_uri="https://client.test",
    )
    client.save()
    yield client
    client.delete()