Skip to content

Commit

Permalink
tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
masci committed Mar 26, 2015
1 parent c210f23 commit 6728a4a
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions oauth2_provider/tests/test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

from oauthlib.oauth2 import Server

from ..views.mixins import OAuthLibMixin, ScopedResourceMixin
from ..views.mixins import OAuthLibMixin, ScopedResourceMixin, ProtectedResourceMixin
from ..oauth2_validators import OAuth2Validator


class TestOAuthLibMixin(TestCase):
class BaseTest(TestCase):
@classmethod
def setUpClass(cls):
cls.request_factory = RequestFactory()


class TestOAuthLibMixin(BaseTest):
def test_missing_server_class(self):
class TestView(OAuthLibMixin, View):
validator_class = OAuth2Validator
Expand Down Expand Up @@ -59,11 +61,7 @@ class TestView(OAuthLibMixin, View):
AnotherOauthLibBackend)


class TestScopedResourceMixin(TestCase):
@classmethod
def setUpClass(cls):
cls.request_factory = RequestFactory()

class TestScopedResourceMixin(BaseTest):
def test_missing_required_scopes(self):
class TestView(ScopedResourceMixin, View):
pass
Expand All @@ -79,3 +77,15 @@ class TestView(ScopedResourceMixin, View):
test_view = TestView()

self.assertEqual(test_view.get_scopes(), ['scope1', 'scope2'])


class TestProtectedResourceMixin(BaseTest):
def test_options_shall_pass(self):
class TestView(ProtectedResourceMixin, View):
server_class = Server
validator_class = OAuth2Validator

request = self.request_factory.options("/fake-req")
view = TestView.as_view()
response = view(request)
self.assertEqual(response.status_code, 200)

0 comments on commit 6728a4a

Please sign in to comment.