Skip to content

Commit f9f50b1

Browse files
committed
tested OAuthLibCoreBackend's _get_extra_credentials method overriding
1 parent 3c02de0 commit f9f50b1

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

oauth2_provider/oauth2_backends.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def _get_extra_credentials(self, request):
4343
"""
4444
return None
4545

46-
4746
def _extract_params(self, request):
4847
"""
4948
Extract parameters from the Django request object. Such parameters will then be passed to

oauth2_provider/tests/test_oauth2_backends.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import mock
23

34
from django.test import TestCase, RequestFactory
45

@@ -34,6 +35,33 @@ def test_application_json_extract_params(self):
3435
self.assertNotIn("password=123456", body)
3536

3637

38+
class TestCustomOAuthLibCoreBackend(TestCase):
39+
"""
40+
Tests that the public API behaves as expected when we override
41+
the OAuthLibCoreBackend core methods.
42+
"""
43+
class MyOAuthLibCore(OAuthLibCore):
44+
def _get_extra_credentials(self, request):
45+
return 1
46+
47+
def setUp(self):
48+
self.factory = RequestFactory()
49+
50+
def test_create_token_response_gets_extra_credentials(self):
51+
"""
52+
Make sures that extra_credentials parameter is passed to oauthlib
53+
"""
54+
payload = "grant_type=password&username=john&password=123456"
55+
request = self.factory.post("/o/token/", payload, content_type="application/x-www-form-urlencoded")
56+
57+
with mock.patch('oauthlib.oauth2.Server.create_token_response') as create_token_response:
58+
mocked = mock.MagicMock()
59+
create_token_response.return_value = mocked, mocked, mocked
60+
core = self.MyOAuthLibCore()
61+
core.create_token_response(request)
62+
self.assertTrue(create_token_response.call_args[0][4] == 1)
63+
64+
3765
class TestJSONOAuthLibCoreBackend(TestCase):
3866
def setUp(self):
3967
self.factory = RequestFactory()

0 commit comments

Comments
 (0)