authentik.sources.oauth.tests.test_api
1from django.urls import reverse 2from rest_framework.test import APITestCase 3 4from authentik.core.tests.utils import create_test_admin_user 5from authentik.lib.generators import generate_id 6from authentik.sources.oauth.models import OAuthSource 7 8 9class TestOAuthSourceAPI(APITestCase): 10 def setUp(self): 11 self.source = OAuthSource.objects.create( 12 name=generate_id(), 13 slug=generate_id(), 14 provider_type="openidconnect", 15 authorization_url="", 16 profile_url="", 17 consumer_key=generate_id(), 18 ) 19 self.user = create_test_admin_user() 20 21 def test_patch_no_type(self): 22 self.client.force_login(self.user) 23 res = self.client.patch( 24 reverse("authentik_api:oauthsource-detail", kwargs={"slug": self.source.slug}), 25 { 26 "authorization_url": f"https://{generate_id()}", 27 "profile_url": f"https://{generate_id()}", 28 "access_token_url": f"https://{generate_id()}", 29 }, 30 ) 31 self.assertEqual(res.status_code, 200)
class
TestOAuthSourceAPI(rest_framework.test.APITestCase):
10class TestOAuthSourceAPI(APITestCase): 11 def setUp(self): 12 self.source = OAuthSource.objects.create( 13 name=generate_id(), 14 slug=generate_id(), 15 provider_type="openidconnect", 16 authorization_url="", 17 profile_url="", 18 consumer_key=generate_id(), 19 ) 20 self.user = create_test_admin_user() 21 22 def test_patch_no_type(self): 23 self.client.force_login(self.user) 24 res = self.client.patch( 25 reverse("authentik_api:oauthsource-detail", kwargs={"slug": self.source.slug}), 26 { 27 "authorization_url": f"https://{generate_id()}", 28 "profile_url": f"https://{generate_id()}", 29 "access_token_url": f"https://{generate_id()}", 30 }, 31 ) 32 self.assertEqual(res.status_code, 200)
Similar to TransactionTestCase, but use transaction.atomic() to achieve
test isolation.
In most situations, TestCase should be preferred to TransactionTestCase as it allows faster execution. However, there are some situations where using TransactionTestCase might be necessary (e.g. testing some transactional behavior).
On database backends with no transaction support, TestCase behaves as TransactionTestCase.
def
setUp(self):
11 def setUp(self): 12 self.source = OAuthSource.objects.create( 13 name=generate_id(), 14 slug=generate_id(), 15 provider_type="openidconnect", 16 authorization_url="", 17 profile_url="", 18 consumer_key=generate_id(), 19 ) 20 self.user = create_test_admin_user()
Hook method for setting up the test fixture before exercising it.
def
test_patch_no_type(self):
22 def test_patch_no_type(self): 23 self.client.force_login(self.user) 24 res = self.client.patch( 25 reverse("authentik_api:oauthsource-detail", kwargs={"slug": self.source.slug}), 26 { 27 "authorization_url": f"https://{generate_id()}", 28 "profile_url": f"https://{generate_id()}", 29 "access_token_url": f"https://{generate_id()}", 30 }, 31 ) 32 self.assertEqual(res.status_code, 200)