Skip to content

Commit 487d23a

Browse files
David Mullermasci
authored andcommitted
Add test for skip_authorization_completely bool flag
1 parent 6f72dba commit 487d23a

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

oauth2_provider/tests/test_implicit.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from __future__ import unicode_literals
22

3+
import mock
4+
35
from django.test import TestCase, RequestFactory
46
from django.core.urlresolvers import reverse
57

68
from ..compat import urlparse, parse_qs, urlencode, get_user_model
79
from ..models import get_application_model
810
from ..settings import oauth2_settings
9-
from ..views import ProtectedResourceView
11+
from ..views import ProtectedResourceView, AuthorizationView
1012

1113

1214
Application = get_application_model()
@@ -140,6 +142,29 @@ def test_post_auth_allow(self):
140142
self.assertIn('access_token=', response['Location'])
141143
self.assertIn('state=random_state_string', response['Location'])
142144

145+
@mock.patch('oauth2_provider.views.base.AuthorizationView.skip_authorization_completely', True)
146+
def test_skip_authorization_completely(self):
147+
"""
148+
If skip_authorization_completely = True, should skip the authorization page.
149+
"""
150+
self.client.login(username="test_user", password="123456")
151+
152+
query_string = urlencode({
153+
'client_id': self.application.client_id,
154+
'response_type': 'token',
155+
'state': 'random_state_string',
156+
'scope': 'read write',
157+
'redirect_uri': 'http://example.it',
158+
})
159+
160+
url = "{url}?{qs}".format(url=reverse('oauth2_provider:authorize'), qs=query_string)
161+
162+
response = self.client.get(url)
163+
self.assertEqual(response.status_code, 302)
164+
self.assertIn('http://example.it#', response['Location'])
165+
self.assertIn('access_token=', response['Location'])
166+
self.assertIn('state=random_state_string', response['Location'])
167+
143168
def test_token_post_auth_deny(self):
144169
"""
145170
Test error when resource owner deny access

0 commit comments

Comments
 (0)