authentik.core.tests.test_migration_move_source_icons

Test moving stored built-in source icons to their themed folders

 1"""Test moving stored built-in source icons to their themed folders"""
 2
 3from importlib import import_module
 4
 5from django.apps import apps
 6from django.db import connection
 7from django.test import TestCase
 8
 9from authentik.core.models import Application
10from authentik.flows.models import Flow, FlowDesignation
11from authentik.lib.generators import generate_id
12from authentik.sources.oauth.models import OAuthSource
13
14move_source_icons = import_module(
15    "authentik.core.migrations.0068_move_source_icons"
16).move_source_icons
17
18
19class TestMoveSourceIcons(TestCase):
20    """Test moving stored built-in source icons to their themed folders"""
21
22    def test_move(self):
23        """Test built-in icons are moved, other values are kept"""
24        github = OAuthSource.objects.create(
25            name=generate_id(), slug=generate_id(), icon="/static/authentik/sources/github.svg"
26        )
27        custom = OAuthSource.objects.create(
28            name=generate_id(), slug=generate_id(), icon="sources/github.svg"
29        )
30        app = Application.objects.create(
31            name=generate_id(), slug=generate_id(), meta_icon="/static/authentik/sources/ldap.png"
32        )
33        flow = Flow.objects.create(
34            name=generate_id(),
35            slug=generate_id(),
36            designation=FlowDesignation.AUTHENTICATION,
37            background="/static/authentik/sources/kerberos.png",
38        )
39
40        with connection.schema_editor() as schema_editor:
41            move_source_icons(apps, schema_editor)
42
43        github.refresh_from_db()
44        custom.refresh_from_db()
45        app.refresh_from_db()
46        flow.refresh_from_db()
47        self.assertEqual(github.icon, "/static/authentik/sources/github/%(theme)s.svg")
48        self.assertEqual(custom.icon, "sources/github.svg")
49        self.assertEqual(app.meta_icon, "/static/authentik/sources/ldap/%(theme)s.svg")
50        self.assertEqual(flow.background, "/static/authentik/sources/kerberos/%(theme)s.png")
def move_source_icons( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
57def move_source_icons(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
58    db_alias = schema_editor.connection.alias
59    for app_label, model_name, field in FILE_FIELDS:
60        model = apps.get_model(app_label, model_name)
61        for old, new in MOVED_ICONS.items():
62            model.objects.using(db_alias).filter(**{field: old}).update(**{field: new})
class TestMoveSourceIcons(django.test.testcases.TestCase):
20class TestMoveSourceIcons(TestCase):
21    """Test moving stored built-in source icons to their themed folders"""
22
23    def test_move(self):
24        """Test built-in icons are moved, other values are kept"""
25        github = OAuthSource.objects.create(
26            name=generate_id(), slug=generate_id(), icon="/static/authentik/sources/github.svg"
27        )
28        custom = OAuthSource.objects.create(
29            name=generate_id(), slug=generate_id(), icon="sources/github.svg"
30        )
31        app = Application.objects.create(
32            name=generate_id(), slug=generate_id(), meta_icon="/static/authentik/sources/ldap.png"
33        )
34        flow = Flow.objects.create(
35            name=generate_id(),
36            slug=generate_id(),
37            designation=FlowDesignation.AUTHENTICATION,
38            background="/static/authentik/sources/kerberos.png",
39        )
40
41        with connection.schema_editor() as schema_editor:
42            move_source_icons(apps, schema_editor)
43
44        github.refresh_from_db()
45        custom.refresh_from_db()
46        app.refresh_from_db()
47        flow.refresh_from_db()
48        self.assertEqual(github.icon, "/static/authentik/sources/github/%(theme)s.svg")
49        self.assertEqual(custom.icon, "sources/github.svg")
50        self.assertEqual(app.meta_icon, "/static/authentik/sources/ldap/%(theme)s.svg")
51        self.assertEqual(flow.background, "/static/authentik/sources/kerberos/%(theme)s.png")

Test moving stored built-in source icons to their themed folders

def test_move(self):
23    def test_move(self):
24        """Test built-in icons are moved, other values are kept"""
25        github = OAuthSource.objects.create(
26            name=generate_id(), slug=generate_id(), icon="/static/authentik/sources/github.svg"
27        )
28        custom = OAuthSource.objects.create(
29            name=generate_id(), slug=generate_id(), icon="sources/github.svg"
30        )
31        app = Application.objects.create(
32            name=generate_id(), slug=generate_id(), meta_icon="/static/authentik/sources/ldap.png"
33        )
34        flow = Flow.objects.create(
35            name=generate_id(),
36            slug=generate_id(),
37            designation=FlowDesignation.AUTHENTICATION,
38            background="/static/authentik/sources/kerberos.png",
39        )
40
41        with connection.schema_editor() as schema_editor:
42            move_source_icons(apps, schema_editor)
43
44        github.refresh_from_db()
45        custom.refresh_from_db()
46        app.refresh_from_db()
47        flow.refresh_from_db()
48        self.assertEqual(github.icon, "/static/authentik/sources/github/%(theme)s.svg")
49        self.assertEqual(custom.icon, "sources/github.svg")
50        self.assertEqual(app.meta_icon, "/static/authentik/sources/ldap/%(theme)s.svg")
51        self.assertEqual(flow.background, "/static/authentik/sources/kerberos/%(theme)s.png")

Test built-in icons are moved, other values are kept