authentik.blueprints.tests

Blueprint helpers

 1"""Blueprint helpers"""
 2
 3from collections.abc import Callable
 4from functools import wraps
 5
 6from django.apps import apps
 7
 8from authentik.blueprints.apps import ManagedAppConfig
 9from authentik.blueprints.models import BlueprintInstance
10
11
12def apply_blueprint(*files: str):
13    """Apply blueprint before test"""
14
15    from authentik.blueprints.v1.importer import Importer
16
17    def wrapper_outer(func: Callable):
18        """Apply blueprint before test"""
19
20        @wraps(func)
21        def wrapper(*args, **kwargs):
22            for file in files:
23                content = BlueprintInstance(path=file).retrieve()
24                Importer.from_string(content).apply()
25            return func(*args, **kwargs)
26
27        return wrapper
28
29    return wrapper_outer
30
31
32def reconcile_app(app_name: str):
33    """Re-reconcile AppConfig methods"""
34
35    def wrapper_outer(func: Callable):
36        """Re-reconcile AppConfig methods"""
37
38        @wraps(func)
39        def wrapper(*args, **kwargs):
40            config = apps.get_app_config(app_name)
41            if isinstance(config, ManagedAppConfig):
42                config._on_startup_callback(None)
43            return func(*args, **kwargs)
44
45        return wrapper
46
47    return wrapper_outer
def apply_blueprint(*files: str):
13def apply_blueprint(*files: str):
14    """Apply blueprint before test"""
15
16    from authentik.blueprints.v1.importer import Importer
17
18    def wrapper_outer(func: Callable):
19        """Apply blueprint before test"""
20
21        @wraps(func)
22        def wrapper(*args, **kwargs):
23            for file in files:
24                content = BlueprintInstance(path=file).retrieve()
25                Importer.from_string(content).apply()
26            return func(*args, **kwargs)
27
28        return wrapper
29
30    return wrapper_outer

Apply blueprint before test

def reconcile_app(app_name: str):
33def reconcile_app(app_name: str):
34    """Re-reconcile AppConfig methods"""
35
36    def wrapper_outer(func: Callable):
37        """Re-reconcile AppConfig methods"""
38
39        @wraps(func)
40        def wrapper(*args, **kwargs):
41            config = apps.get_app_config(app_name)
42            if isinstance(config, ManagedAppConfig):
43                config._on_startup_callback(None)
44            return func(*args, **kwargs)
45
46        return wrapper
47
48    return wrapper_outer

Re-reconcile AppConfig methods