# Path: tests/tests/test_cases.py
# class TokenTestCase(OAuthTestCase):
# 
#     def setUp(self):
#         super(TokenTestCase, self).setUp()
# 
#         self.client_secret = self.oauth_client.secret
# 
#         self.authorization_token = AuthorizationToken(user=self.user, client=self.oauth_client)
#         self.authorization_token.save()
# 
#         self.authorization_token.scope = [self.scope]
#         self.authorization_token.save()


from django.core.urlresolvers import reverse
from ..test_cases import TokenTestCase
        from doac.exceptions.unsupported_grant_type import GrantTypeNotProvided, GrantTypeNotValid
        from doac.exceptions.invalid_request import ClientNotProvided
        from doac.exceptions.invalid_client import ClientDoesNotExist
        from doac.exceptions.invalid_client import ClientSecretNotValid
        from doac.exceptions.invalid_request import ClientSecretNotProvided
        from doac.exceptions.invalid_request import AuthorizationCodeAlreadyUsed, AuthorizationCodeNotProvided, AuthorizationCodeNotValid
        from doac.exceptions.invalid_request import RefreshTokenNotProvided, RefreshTokenNotValid
    import simplejson as json
    import json
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "authorization_code", "client_id": self.oauth_client.id, "client_secret": "notVerySecret"})
        self.assertExceptionJson(request, ClientSecretNotValid())
    
    def test_code(self):
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "authorization_code", "client_id": self.oauth_client.id, "client_secret": self.client_secret})
        self.assertExceptionJson(request, AuthorizationCodeNotProvided())
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "authorization_code", "client_id": self.oauth_client.id, "client_secret": self.client_secret, "code": ""})
        self.assertExceptionJson(request, AuthorizationCodeNotProvided())
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "authorization_code", "client_id": self.oauth_client.id, "client_secret": self.client_secret, "code": "invalid"})
        self.assertExceptionJson(request, AuthorizationCodeNotValid())
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "authorization_code", "client_id": self.oauth_client.id, "client_secret": self.client_secret, "code": self.authorization_token.token})
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "authorization_code", "client_id": self.oauth_client.id, "client_secret": self.client_secret, "code": self.authorization_token.token})
        self.assertExceptionJson(request, AuthorizationCodeAlreadyUsed())
    
    def test_refresh_token(self):
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "refresh_token", "client_id": self.oauth_client.id, "client_secret": self.client_secret})
        self.assertExceptionJson(request, RefreshTokenNotProvided())
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "refresh_token", "client_id": self.oauth_client.id, "client_secret": self.client_secret, "refresh_token": ""})
        self.assertExceptionJson(request, RefreshTokenNotProvided())
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "refresh_token", "client_id": self.oauth_client.id, "client_secret": self.client_secret, "refresh_token": "invalid"})
        self.assertExceptionJson(request, RefreshTokenNotValid())



# Path: tests/tests/test_cases.py
# class TokenTestCase(OAuthTestCase):
# 
#     def setUp(self):
#         super(TokenTestCase, self).setUp()
# 
#         self.client_secret = self.oauth_client.secret
# 
#         self.authorization_token = AuthorizationToken(user=self.user, client=self.oauth_client)
#         self.authorization_token.save()
# 
#         self.authorization_token.scope = [self.scope]
#         self.authorization_token.save()


# Path: tests/tests/views/test_token.py
from django.core.urlresolvers import reverse
from ..test_cases import TokenTestCase
        from doac.exceptions.unsupported_grant_type import GrantTypeNotProvided, GrantTypeNotValid
        from doac.exceptions.invalid_request import ClientNotProvided
        from doac.exceptions.invalid_client import ClientDoesNotExist
        from doac.exceptions.invalid_client import ClientSecretNotValid
        from doac.exceptions.invalid_request import ClientSecretNotProvided
        from doac.exceptions.invalid_request import AuthorizationCodeAlreadyUsed, AuthorizationCodeNotProvided, AuthorizationCodeNotValid
        from doac.exceptions.invalid_request import RefreshTokenNotProvided, RefreshTokenNotValid
    import simplejson as json
    import json

        request = self.client.post(reverse("oauth2_token"), {"grant_type": "authorization_code", "client_id": self.oauth_client.id, "client_secret": "notVerySecret"})
        self.assertExceptionJson(request, ClientSecretNotValid())
    
    def test_code(self):
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "authorization_code", "client_id": self.oauth_client.id, "client_secret": self.client_secret})
        self.assertExceptionJson(request, AuthorizationCodeNotProvided())
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "authorization_code", "client_id": self.oauth_client.id, "client_secret": self.client_secret, "code": ""})
        self.assertExceptionJson(request, AuthorizationCodeNotProvided())
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "authorization_code", "client_id": self.oauth_client.id, "client_secret": self.client_secret, "code": "invalid"})
        self.assertExceptionJson(request, AuthorizationCodeNotValid())
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "authorization_code", "client_id": self.oauth_client.id, "client_secret": self.client_secret, "code": self.authorization_token.token})
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "authorization_code", "client_id": self.oauth_client.id, "client_secret": self.client_secret, "code": self.authorization_token.token})
        self.assertExceptionJson(request, AuthorizationCodeAlreadyUsed())
    
    def test_refresh_token(self):
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "refresh_token", "client_id": self.oauth_client.id, "client_secret": self.client_secret})
        self.assertExceptionJson(request, RefreshTokenNotProvided())
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "refresh_token", "client_id": self.oauth_client.id, "client_secret": self.client_secret, "refresh_token": ""})
        self.assertExceptionJson(request, RefreshTokenNotProvided())
        
        request = self.client.post(reverse("oauth2_token"), {"grant_type": "refresh_token", "client_id": self.oauth_client.id, "client_secret": self.client_secret, "refresh_token": "invalid"})
        self.assertExceptionJson(request, RefreshTokenNotValid())



class TestTokenResponse(TokenTestCase):