1+ import json
2+
13from django .test import TestCase , RequestFactory
2- from django .test .utils import override_settings
34
45from ..backends import get_oauthlib_core
6+ from ..oauth2_backends import OAuthLibCore , JSONOAuthLibCore
57
68
7- @override_settings (OAUTH2_BACKEND_CLASS = 'oauth2_provider.oauth2_backends.OAuthLibCore' )
89class TestOAuthLibCoreBackend (TestCase ):
910 def setUp (self ):
1011 self .factory = RequestFactory ()
11- self .oauthlib_core = get_oauthlib_core ()
12+ self .oauthlib_core = OAuthLibCore ()
1213
1314 def test_form_urlencoded_extract_params (self ):
1415 payload = "grant_type=password&username=john&password=123456"
@@ -33,6 +34,25 @@ def test_application_json_extract_params(self):
3334 self .assertNotIn ("password=123456" , body )
3435
3536
37+ class TestJSONOAuthLibCoreBackend (TestCase ):
38+ def setUp (self ):
39+ self .factory = RequestFactory ()
40+ self .oauthlib_core = JSONOAuthLibCore ()
41+
42+ def test_application_json_extract_params (self ):
43+ payload = json .dumps ({
44+ "grant_type" : "password" ,
45+ "username" : "john" ,
46+ "password" : "123456" ,
47+ })
48+ request = self .factory .post ("/o/token/" , payload , content_type = "application/json" )
49+
50+ uri , http_method , body , headers = self .oauthlib_core ._extract_params (request )
51+ self .assertIn ("grant_type=password" , body )
52+ self .assertIn ("username=john" , body )
53+ self .assertIn ("password=123456" , body )
54+
55+
3656class TestOAuthLibCore (TestCase ):
3757 def setUp (self ):
3858 self .factory = RequestFactory ()
0 commit comments