authentik.blueprints.tests.test_v1_conditions

Test blueprints v1

 1"""Test blueprints v1"""
 2
 3from django.test import TransactionTestCase
 4
 5from authentik.blueprints.v1.importer import Importer
 6from authentik.flows.models import Flow
 7from authentik.lib.generators import generate_id
 8from authentik.lib.tests.utils import load_fixture
 9
10
11class TestBlueprintsV1Conditions(TransactionTestCase):
12    """Test Blueprints conditions attribute"""
13
14    def test_conditions_fulfilled(self):
15        """Test conditions fulfilled"""
16        flow_slug1 = generate_id()
17        flow_slug2 = generate_id()
18        import_yaml = load_fixture(
19            "fixtures/conditions_fulfilled.yaml", id1=flow_slug1, id2=flow_slug2
20        )
21
22        importer = Importer.from_string(import_yaml)
23        self.assertTrue(importer.validate()[0])
24        self.assertTrue(importer.apply())
25        # Ensure objects exist
26        flow: Flow = Flow.objects.filter(slug=flow_slug1).first()
27        self.assertEqual(flow.slug, flow_slug1)
28        flow: Flow = Flow.objects.filter(slug=flow_slug2).first()
29        self.assertEqual(flow.slug, flow_slug2)
30
31    def test_conditions_not_fulfilled(self):
32        """Test conditions not fulfilled"""
33        flow_slug1 = generate_id()
34        flow_slug2 = generate_id()
35        import_yaml = load_fixture(
36            "fixtures/conditions_not_fulfilled.yaml", id1=flow_slug1, id2=flow_slug2
37        )
38
39        importer = Importer.from_string(import_yaml)
40        self.assertTrue(importer.validate()[0])
41        self.assertTrue(importer.apply())
42        # Ensure objects do not exist
43        self.assertFalse(Flow.objects.filter(slug=flow_slug1))
44        self.assertFalse(Flow.objects.filter(slug=flow_slug2))
class TestBlueprintsV1Conditions(django.test.testcases.TransactionTestCase):
12class TestBlueprintsV1Conditions(TransactionTestCase):
13    """Test Blueprints conditions attribute"""
14
15    def test_conditions_fulfilled(self):
16        """Test conditions fulfilled"""
17        flow_slug1 = generate_id()
18        flow_slug2 = generate_id()
19        import_yaml = load_fixture(
20            "fixtures/conditions_fulfilled.yaml", id1=flow_slug1, id2=flow_slug2
21        )
22
23        importer = Importer.from_string(import_yaml)
24        self.assertTrue(importer.validate()[0])
25        self.assertTrue(importer.apply())
26        # Ensure objects exist
27        flow: Flow = Flow.objects.filter(slug=flow_slug1).first()
28        self.assertEqual(flow.slug, flow_slug1)
29        flow: Flow = Flow.objects.filter(slug=flow_slug2).first()
30        self.assertEqual(flow.slug, flow_slug2)
31
32    def test_conditions_not_fulfilled(self):
33        """Test conditions not fulfilled"""
34        flow_slug1 = generate_id()
35        flow_slug2 = generate_id()
36        import_yaml = load_fixture(
37            "fixtures/conditions_not_fulfilled.yaml", id1=flow_slug1, id2=flow_slug2
38        )
39
40        importer = Importer.from_string(import_yaml)
41        self.assertTrue(importer.validate()[0])
42        self.assertTrue(importer.apply())
43        # Ensure objects do not exist
44        self.assertFalse(Flow.objects.filter(slug=flow_slug1))
45        self.assertFalse(Flow.objects.filter(slug=flow_slug2))

Test Blueprints conditions attribute

def test_conditions_fulfilled(self):
15    def test_conditions_fulfilled(self):
16        """Test conditions fulfilled"""
17        flow_slug1 = generate_id()
18        flow_slug2 = generate_id()
19        import_yaml = load_fixture(
20            "fixtures/conditions_fulfilled.yaml", id1=flow_slug1, id2=flow_slug2
21        )
22
23        importer = Importer.from_string(import_yaml)
24        self.assertTrue(importer.validate()[0])
25        self.assertTrue(importer.apply())
26        # Ensure objects exist
27        flow: Flow = Flow.objects.filter(slug=flow_slug1).first()
28        self.assertEqual(flow.slug, flow_slug1)
29        flow: Flow = Flow.objects.filter(slug=flow_slug2).first()
30        self.assertEqual(flow.slug, flow_slug2)

Test conditions fulfilled

def test_conditions_not_fulfilled(self):
32    def test_conditions_not_fulfilled(self):
33        """Test conditions not fulfilled"""
34        flow_slug1 = generate_id()
35        flow_slug2 = generate_id()
36        import_yaml = load_fixture(
37            "fixtures/conditions_not_fulfilled.yaml", id1=flow_slug1, id2=flow_slug2
38        )
39
40        importer = Importer.from_string(import_yaml)
41        self.assertTrue(importer.validate()[0])
42        self.assertTrue(importer.apply())
43        # Ensure objects do not exist
44        self.assertFalse(Flow.objects.filter(slug=flow_slug1))
45        self.assertFalse(Flow.objects.filter(slug=flow_slug2))

Test conditions not fulfilled