fix-tests
Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
parent
6676a81733
commit
d13631914a
|
@ -1,13 +1,20 @@
|
||||||
"""Run bootstrap tasks"""
|
"""Run bootstrap tasks"""
|
||||||
from django.core.management.base import BaseCommand
|
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):
|
class Command(BaseCommand):
|
||||||
"""Run bootstrap tasks to ensure certain objects are created"""
|
"""Run bootstrap tasks to ensure certain objects are created"""
|
||||||
|
|
||||||
def handle(self, **options):
|
def handle(self, **options):
|
||||||
tasks = _get_startup_tasks()
|
for task in _get_startup_tasks_default_tenant():
|
||||||
for task in tasks:
|
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()
|
task()
|
||||||
|
|
|
@ -31,7 +31,6 @@ class PytestTestRunner(DiscoverRunner): # pragma: no cover
|
||||||
|
|
||||||
settings.TEST = True
|
settings.TEST = True
|
||||||
settings.CELERY["task_always_eager"] = True
|
settings.CELERY["task_always_eager"] = True
|
||||||
CONFIG.set("avatars", "none")
|
|
||||||
CONFIG.set("geoip", "tests/GeoLite2-City-Test.mmdb")
|
CONFIG.set("geoip", "tests/GeoLite2-City-Test.mmdb")
|
||||||
CONFIG.set("blueprints_dir", "./blueprints")
|
CONFIG.set("blueprints_dir", "./blueprints")
|
||||||
CONFIG.set(
|
CONFIG.set(
|
||||||
|
|
|
@ -2,10 +2,9 @@
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
|
from django_tenants.utils import get_tenant
|
||||||
from sentry_sdk.api import set_tag
|
from sentry_sdk.api import set_tag
|
||||||
|
|
||||||
from authentik.tenants.utils import get_tenant_for_request
|
|
||||||
|
|
||||||
|
|
||||||
class CurrentTenantMiddleware:
|
class CurrentTenantMiddleware:
|
||||||
"""Add current tenant to http request"""
|
"""Add current tenant to http request"""
|
||||||
|
@ -17,8 +16,9 @@ class CurrentTenantMiddleware:
|
||||||
|
|
||||||
def __call__(self, request: HttpRequest) -> HttpResponse:
|
def __call__(self, request: HttpRequest) -> HttpResponse:
|
||||||
if not hasattr(request, "tenant"):
|
if not hasattr(request, "tenant"):
|
||||||
tenant = get_tenant_for_request(request)
|
tenant = get_tenant(request)
|
||||||
setattr(request, "tenant", tenant)
|
setattr(request, "tenant", tenant)
|
||||||
|
if tenant is not None:
|
||||||
set_tag("authentik.tenant_uuid", tenant.tenant_uuid.hex)
|
set_tag("authentik.tenant_uuid", tenant.tenant_uuid.hex)
|
||||||
set_tag("authentik.tenant_domain_regex", tenant.domain_regex)
|
set_tag("authentik.tenant_domain_regex", tenant.domain_regex)
|
||||||
return self.get_response(request)
|
return self.get_response(request)
|
||||||
|
|
Reference in New Issue