|
1 | 1 | import json |
| 2 | +import mock |
2 | 3 |
|
3 | 4 | from django.test import TestCase, RequestFactory |
4 | 5 |
|
@@ -34,6 +35,33 @@ def test_application_json_extract_params(self): |
34 | 35 | self.assertNotIn("password=123456", body) |
35 | 36 |
|
36 | 37 |
|
| 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 | + |
37 | 65 | class TestJSONOAuthLibCoreBackend(TestCase): |
38 | 66 | def setUp(self): |
39 | 67 | self.factory = RequestFactory() |
|
0 commit comments