authentik.api.tests.test_schema
Schema generation tests
1"""Schema generation tests""" 2 3from pathlib import Path 4from tempfile import gettempdir 5from uuid import uuid4 6 7from django.core.management import call_command 8from django.urls import reverse 9from rest_framework.test import APITestCase 10from yaml import safe_load 11 12from authentik.lib.config import CONFIG 13 14 15class TestSchemaGeneration(APITestCase): 16 """Generic admin tests""" 17 18 def test_schema(self): 19 """Test generation""" 20 response = self.client.get( 21 reverse("authentik_api:schema"), 22 ) 23 self.assertTrue(safe_load(response.content.decode())) 24 25 def test_browser(self): 26 """Test API Browser""" 27 response = self.client.get( 28 reverse("authentik_api:schema-browser"), 29 ) 30 self.assertEqual(response.status_code, 200) 31 32 def test_build_schema(self): 33 """Test schema build command""" 34 tmp = Path(gettempdir()) 35 blueprint_file = tmp / f"{str(uuid4())}.json" 36 api_file = tmp / f"{str(uuid4())}.yml" 37 with ( 38 CONFIG.patch("debug", True), 39 CONFIG.patch("tenants.enabled", True), 40 CONFIG.patch("outposts.disable_embedded_outpost", True), 41 ): 42 call_command("build_schema", blueprint_file=blueprint_file, api_file=api_file) 43 self.assertTrue(blueprint_file.exists()) 44 self.assertTrue(api_file.exists())
class
TestSchemaGeneration(rest_framework.test.APITestCase):
16class TestSchemaGeneration(APITestCase): 17 """Generic admin tests""" 18 19 def test_schema(self): 20 """Test generation""" 21 response = self.client.get( 22 reverse("authentik_api:schema"), 23 ) 24 self.assertTrue(safe_load(response.content.decode())) 25 26 def test_browser(self): 27 """Test API Browser""" 28 response = self.client.get( 29 reverse("authentik_api:schema-browser"), 30 ) 31 self.assertEqual(response.status_code, 200) 32 33 def test_build_schema(self): 34 """Test schema build command""" 35 tmp = Path(gettempdir()) 36 blueprint_file = tmp / f"{str(uuid4())}.json" 37 api_file = tmp / f"{str(uuid4())}.yml" 38 with ( 39 CONFIG.patch("debug", True), 40 CONFIG.patch("tenants.enabled", True), 41 CONFIG.patch("outposts.disable_embedded_outpost", True), 42 ): 43 call_command("build_schema", blueprint_file=blueprint_file, api_file=api_file) 44 self.assertTrue(blueprint_file.exists()) 45 self.assertTrue(api_file.exists())
Generic admin tests
def
test_schema(self):
19 def test_schema(self): 20 """Test generation""" 21 response = self.client.get( 22 reverse("authentik_api:schema"), 23 ) 24 self.assertTrue(safe_load(response.content.decode()))
Test generation
def
test_browser(self):
26 def test_browser(self): 27 """Test API Browser""" 28 response = self.client.get( 29 reverse("authentik_api:schema-browser"), 30 ) 31 self.assertEqual(response.status_code, 200)
Test API Browser
def
test_build_schema(self):
33 def test_build_schema(self): 34 """Test schema build command""" 35 tmp = Path(gettempdir()) 36 blueprint_file = tmp / f"{str(uuid4())}.json" 37 api_file = tmp / f"{str(uuid4())}.yml" 38 with ( 39 CONFIG.patch("debug", True), 40 CONFIG.patch("tenants.enabled", True), 41 CONFIG.patch("outposts.disable_embedded_outpost", True), 42 ): 43 call_command("build_schema", blueprint_file=blueprint_file, api_file=api_file) 44 self.assertTrue(blueprint_file.exists()) 45 self.assertTrue(api_file.exists())
Test schema build command