6
6
7
7
from oauthlib .oauth2 import Server
8
8
9
- from ..views .mixins import OAuthLibMixin , ScopedResourceMixin
9
+ from ..views .mixins import OAuthLibMixin , ScopedResourceMixin , ProtectedResourceMixin
10
10
from ..oauth2_validators import OAuth2Validator
11
11
12
12
13
- class TestOAuthLibMixin (TestCase ):
13
+ class BaseTest (TestCase ):
14
14
@classmethod
15
15
def setUpClass (cls ):
16
16
cls .request_factory = RequestFactory ()
17
17
18
+
19
+ class TestOAuthLibMixin (BaseTest ):
18
20
def test_missing_server_class (self ):
19
21
class TestView (OAuthLibMixin , View ):
20
22
validator_class = OAuth2Validator
@@ -59,11 +61,7 @@ class TestView(OAuthLibMixin, View):
59
61
AnotherOauthLibBackend )
60
62
61
63
62
- class TestScopedResourceMixin (TestCase ):
63
- @classmethod
64
- def setUpClass (cls ):
65
- cls .request_factory = RequestFactory ()
66
-
64
+ class TestScopedResourceMixin (BaseTest ):
67
65
def test_missing_required_scopes (self ):
68
66
class TestView (ScopedResourceMixin , View ):
69
67
pass
@@ -79,3 +77,15 @@ class TestView(ScopedResourceMixin, View):
79
77
test_view = TestView ()
80
78
81
79
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