@@ -43,29 +43,27 @@ def get(self, request, *args, **kwargs):
4343
4444@pytest .mark .usefixtures ("oauth2_settings" )
4545class BaseTest (TestCase ):
46- def setUp (self ):
47- self .factory = RequestFactory ()
48- self .
test_user = UserModel .
objects .
create_user (
"test_user" ,
"[email protected] " ,
"123456" )
49- self .
dev_user = UserModel .
objects .
create_user (
"dev_user" ,
"[email protected] " ,
"123456" )
46+ factory = RequestFactory ()
5047
51- self .oauth2_settings .ALLOWED_REDIRECT_URI_SCHEMES = ["http" , "custom-scheme" ]
52- self .oauth2_settings .PKCE_REQUIRED = False
48+ @classmethod
49+ def setUpTestData (cls ):
50+ cls .
test_user = UserModel .
objects .
create_user (
"test_user" ,
"[email protected] " ,
"123456" )
51+ cls .
dev_user = UserModel .
objects .
create_user (
"dev_user" ,
"[email protected] " ,
"123456" )
5352
54- self .application = Application .objects .create (
53+ cls .application = Application .objects .create (
5554 name = "Test Application" ,
5655 redirect_uris = (
5756 "http://localhost http://example.com http://example.org custom-scheme://example.com"
5857 ),
59- user = self .dev_user ,
58+ user = cls .dev_user ,
6059 client_type = Application .CLIENT_CONFIDENTIAL ,
6160 authorization_grant_type = Application .GRANT_AUTHORIZATION_CODE ,
6261 client_secret = CLEARTEXT_SECRET ,
6362 )
6463
65- def tearDown (self ):
66- self .application .delete ()
67- self .test_user .delete ()
68- self .dev_user .delete ()
64+ def setUp (self ):
65+ self .oauth2_settings .ALLOWED_REDIRECT_URI_SCHEMES = ["http" , "custom-scheme" ]
66+ self .oauth2_settings .PKCE_REQUIRED = False
6967
7068
7169class TestRegressionIssue315 (BaseTest ):
@@ -1592,10 +1590,11 @@ def test_code_exchange_succeed_when_redirect_uri_match_with_multiple_query_param
15921590
15931591@pytest .mark .oauth2_settings (presets .OIDC_SETTINGS_RW )
15941592class TestOIDCAuthorizationCodeTokenView (BaseAuthorizationCodeTokenView ):
1595- def setUp (self ):
1596- super ().setUp ()
1597- self .application .algorithm = Application .RS256_ALGORITHM
1598- self .application .save ()
1593+ @classmethod
1594+ def setUpTestData (cls ):
1595+ super ().setUpTestData ()
1596+ cls .application .algorithm = Application .RS256_ALGORITHM
1597+ cls .application .save ()
15991598
16001599 def test_id_token_public (self ):
16011600 """
@@ -1669,11 +1668,15 @@ def test_id_token_code_exchange_succeed_when_redirect_uri_match_with_multiple_qu
16691668
16701669@pytest .mark .oauth2_settings (presets .OIDC_SETTINGS_RW )
16711670class TestOIDCAuthorizationCodeHSAlgorithm (BaseAuthorizationCodeTokenView ):
1671+ @classmethod
1672+ def setUpTestData (cls ):
1673+ super ().setUpTestData ()
1674+ cls .application .algorithm = Application .HS256_ALGORITHM
1675+ cls .application .save ()
1676+
16721677 def setUp (self ):
16731678 super ().setUp ()
16741679 self .oauth2_settings .OIDC_RSA_PRIVATE_KEY = None
1675- self .application .algorithm = Application .HS256_ALGORITHM
1676- self .application .save ()
16771680
16781681 def test_id_token (self ):
16791682 """
@@ -1765,10 +1768,11 @@ def test_resource_access_deny(self):
17651768
17661769@pytest .mark .oauth2_settings (presets .OIDC_SETTINGS_RW )
17671770class TestOIDCAuthorizationCodeProtectedResource (BaseTest ):
1768- def setUp (self ):
1769- super ().setUp ()
1770- self .application .algorithm = Application .RS256_ALGORITHM
1771- self .application .save ()
1771+ @classmethod
1772+ def setUpTestData (cls ):
1773+ super ().setUpTestData ()
1774+ cls .application .algorithm = Application .RS256_ALGORITHM
1775+ cls .application .save ()
17721776
17731777 def test_id_token_resource_access_allowed (self ):
17741778 self .client .login (username = "test_user" , password = "123456" )
0 commit comments