Skip to content

Commit 6728a4a

Browse files
committed
tests added
1 parent c210f23 commit 6728a4a

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

oauth2_provider/tests/test_mixins.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66

77
from oauthlib.oauth2 import Server
88

9-
from ..views.mixins import OAuthLibMixin, ScopedResourceMixin
9+
from ..views.mixins import OAuthLibMixin, ScopedResourceMixin, ProtectedResourceMixin
1010
from ..oauth2_validators import OAuth2Validator
1111

1212

13-
class TestOAuthLibMixin(TestCase):
13+
class BaseTest(TestCase):
1414
@classmethod
1515
def setUpClass(cls):
1616
cls.request_factory = RequestFactory()
1717

18+
19+
class TestOAuthLibMixin(BaseTest):
1820
def test_missing_server_class(self):
1921
class TestView(OAuthLibMixin, View):
2022
validator_class = OAuth2Validator
@@ -59,11 +61,7 @@ class TestView(OAuthLibMixin, View):
5961
AnotherOauthLibBackend)
6062

6163

62-
class TestScopedResourceMixin(TestCase):
63-
@classmethod
64-
def setUpClass(cls):
65-
cls.request_factory = RequestFactory()
66-
64+
class TestScopedResourceMixin(BaseTest):
6765
def test_missing_required_scopes(self):
6866
class TestView(ScopedResourceMixin, View):
6967
pass
@@ -79,3 +77,15 @@ class TestView(ScopedResourceMixin, View):
7977
test_view = TestView()
8078

8179
self.assertEqual(test_view.get_scopes(), ['scope1', 'scope2'])
80+
81+
82+
class TestProtectedResourceMixin(BaseTest):
83+
def test_options_shall_pass(self):
84+
class TestView(ProtectedResourceMixin, View):
85+
server_class = Server
86+
validator_class = OAuth2Validator
87+
88+
request = self.request_factory.options("/fake-req")
89+
view = TestView.as_view()
90+
response = view(request)
91+
self.assertEqual(response.status_code, 200)

0 commit comments

Comments
 (0)