fix-tests

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt 2023-11-16 13:22:25 +01:00
parent 6676a81733
commit d13631914a
No known key found for this signature in database
GPG Key ID: 9C3FA22FABF1AA8D
3 changed files with 16 additions and 10 deletions

View File

@ -1,13 +1,20 @@
"""Run bootstrap tasks"""
from django.core.management.base import BaseCommand
from django_tenants.utils import get_public_schema_name
from authentik.root.celery import _get_startup_tasks
from authentik.root.celery import _get_startup_tasks_all_tenants, _get_startup_tasks_default_tenant
from authentik.tenants.models import Tenant
class Command(BaseCommand):
"""Run bootstrap tasks to ensure certain objects are created"""
def handle(self, **options):
tasks = _get_startup_tasks()
for task in tasks:
task()
for task in _get_startup_tasks_default_tenant():
with Tenant.objects.get(schema_name=get_public_schema_name()):
task()
for task in _get_startup_tasks_all_tenants():
for tenant in Tenant.objects.filter(ready=True):
with tenant:
task()

View File

@ -31,7 +31,6 @@ class PytestTestRunner(DiscoverRunner): # pragma: no cover
settings.TEST = True
settings.CELERY["task_always_eager"] = True
CONFIG.set("avatars", "none")
CONFIG.set("geoip", "tests/GeoLite2-City-Test.mmdb")
CONFIG.set("blueprints_dir", "./blueprints")
CONFIG.set(

View File

@ -2,10 +2,9 @@
from typing import Callable
from django.http import HttpRequest, HttpResponse
from django_tenants.utils import get_tenant
from sentry_sdk.api import set_tag
from authentik.tenants.utils import get_tenant_for_request
class CurrentTenantMiddleware:
"""Add current tenant to http request"""
@ -17,8 +16,9 @@ class CurrentTenantMiddleware:
def __call__(self, request: HttpRequest) -> HttpResponse:
if not hasattr(request, "tenant"):
tenant = get_tenant_for_request(request)
tenant = get_tenant(request)
setattr(request, "tenant", tenant)
set_tag("authentik.tenant_uuid", tenant.tenant_uuid.hex)
set_tag("authentik.tenant_domain_regex", tenant.domain_regex)
if tenant is not None:
set_tag("authentik.tenant_uuid", tenant.tenant_uuid.hex)
set_tag("authentik.tenant_domain_regex", tenant.domain_regex)
return self.get_response(request)