Skip to content

Commit

Permalink
🚚 [#99] Move fixture to confest.py for generic usage
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed May 16, 2024
1 parent f2956a6 commit 1a033f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from typing import TYPE_CHECKING, Iterator

from django.contrib.sessions.backends.db import SessionStore
from django.test import RequestFactory

import pytest

if TYPE_CHECKING:
Expand Down Expand Up @@ -57,3 +60,12 @@ def keycloak_config(db) -> Iterator[OpenIDConnectConfig]:
yield config

OpenIDConnectConfig.clear_cache()


@pytest.fixture
def auth_request(rf: RequestFactory):
request = rf.get("/some-auth", {"next": "/ignored"})
session = SessionStore()
session.save()
request.session = session
return request
15 changes: 1 addition & 14 deletions tests/test_init_flow_custom_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

from urllib.parse import parse_qs, urlsplit

from django.contrib.sessions.backends.db import SessionStore
from django.core.exceptions import DisallowedRedirect
from django.test import RequestFactory

import pytest

Expand All @@ -17,18 +15,6 @@
pytestmark = [pytest.mark.django_db]


@pytest.fixture
def auth_request(rf: RequestFactory):
request = rf.get("/some-auth", {"next": "/ignored"})
session = SessionStore()
session.save()
request.session = session
return request


# Use a proxy model to modify behaviour without needing migrations/models machinery.


class static_setting:
def __init__(self, val):
self.val = val
Expand All @@ -41,6 +27,7 @@ def __set__(self, obj, val):


class CustomConfig(OpenIDConnectConfig):
# Use a proxy model to modify behaviour without needing migrations/models machinery.
class Meta:
proxy = True
app_label = "mozilla_django_oidc_db"
Expand Down

0 comments on commit 1a033f8

Please sign in to comment.