Files
authentik/tests/_process.py
Jens L. a6775bc61e tests: refactor test harness to split apart a single file (#21391)
* re-instate previously flaky test

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* break up big file

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* move geoip data to subdir

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* i am but a weak man

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix ldap disconnect in testing

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* account for mismatched uid due to test server process

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
2026-04-05 22:12:52 +02:00

47 lines
1.8 KiB
Python

"""authentik e2e testing utilities"""
from datetime import timedelta
from time import mktime
from unittest.mock import MagicMock, patch
from daphne.testing import DaphneProcess
from django import setup as django_setup
from django.conf import settings
from django.utils.timezone import now
from authentik.lib.config import CONFIG
from authentik.lib.generators import generate_id
class TestDatabaseProcess(DaphneProcess):
"""Channels does not correctly switch to the test database by default.
https://github.com/django/channels/issues/2048"""
def run(self):
if not settings.configured: # Fix For raise AppRegistryNotReady("Apps aren't loaded yet.")
django_setup() # Ensure Django is fully set up before using settings
if not settings.DATABASES[list(settings.DATABASES.keys())[0]]["NAME"].startswith("test_"):
for _, db_settings in settings.DATABASES.items():
db_settings["NAME"] = f"test_{db_settings['NAME']}"
settings.TEST = True
from authentik.enterprise.license import LicenseKey
from authentik.root.test_runner import patched__get_ct_cached
with (
patch(
"authentik.enterprise.license.LicenseKey.validate",
MagicMock(
return_value=LicenseKey(
aud="",
exp=int(mktime((now() + timedelta(days=3000)).timetuple())),
name=generate_id(),
internal_users=100,
external_users=100,
)
),
),
CONFIG.patch("email.port", 1025),
patch("guardian.shortcuts._get_ct_cached", patched__get_ct_cached),
):
return super().run()