# Path: tests/tests/test_cases.py
# class ApprovalTestCase(OAuthTestCase):
# 
#     def setUp(self):
#         super(ApprovalTestCase, self).setUp()
# 
#         self.redirect_uri = RedirectUri(client=self.oauth_client, url="http://localhost/redirect_endpoint/")
#         self.redirect_uri.save()
# 
#         self.authorization_code = AuthorizationCode(client=self.oauth_client, redirect_uri=self.redirect_uri)
#         self.authorization_code.save()
# 
#         self.authorization_code.scope = [self.scope]
#         self.authorization_code.save()


from django.core.urlresolvers import reverse
from ..test_cases import ApprovalTestCase
        from doac.exceptions.invalid_request import AuthorizationCodeNotValid, AuthorizationCodeNotProvided
        from doac.exceptions.access_denied import AuthorizationDenied
        from doac.models import AuthorizationToken
        from doac.models import AccessToken
        import urllib
        import urllib
    
    def test_denied(self):
        
        data = {
            "code": self.authorization_code.token,
            "code_state": "o2cs",
            "deny_access": None,
        }
        
        request = self.client.post(reverse("oauth2_approval") + "?code=%s" % (self.authorization_code.token, ), data)
        self.assertExceptionRedirect(request, AuthorizationDenied())
    
    def test_approved_code(self):
        
        self.client.login(username="test", password="test")
        
        data = {
            "code": self.authorization_code.token,
            "code_state": "o2cs",
            "approve_access": None,
        }
        
        self.authorization_code.response_type = "code"
        self.authorization_code.save()
        
        request = self.client.post(reverse("oauth2_approval") + "?code=%s" % (self.authorization_code.token, ), data)
        self.assertEqual(request.status_code, 302)
        
        args = {
            "state": "o2cs",

# Path: tests/tests/test_cases.py
# class ApprovalTestCase(OAuthTestCase):
# 
#     def setUp(self):
#         super(ApprovalTestCase, self).setUp()
# 
#         self.redirect_uri = RedirectUri(client=self.oauth_client, url="http://localhost/redirect_endpoint/")
#         self.redirect_uri.save()
# 
#         self.authorization_code = AuthorizationCode(client=self.oauth_client, redirect_uri=self.redirect_uri)
#         self.authorization_code.save()
# 
#         self.authorization_code.scope = [self.scope]
#         self.authorization_code.save()


# Path: tests/tests/views/test_approval.py
from django.core.urlresolvers import reverse
from ..test_cases import ApprovalTestCase
        from doac.exceptions.invalid_request import AuthorizationCodeNotValid, AuthorizationCodeNotProvided
        from doac.exceptions.access_denied import AuthorizationDenied
        from doac.models import AuthorizationToken
        from doac.models import AccessToken
        import urllib
        import urllib

    
    def test_denied(self):
        
        data = {
            "code": self.authorization_code.token,
            "code_state": "o2cs",
            "deny_access": None,
        }
        
        request = self.client.post(reverse("oauth2_approval") + "?code=%s" % (self.authorization_code.token, ), data)
        self.assertExceptionRedirect(request, AuthorizationDenied())
    
    def test_approved_code(self):
        
        self.client.login(username="test", password="test")
        
        data = {
            "code": self.authorization_code.token,
            "code_state": "o2cs",
            "approve_access": None,
        }
        
        self.authorization_code.response_type = "code"
        self.authorization_code.save()
        
        request = self.client.post(reverse("oauth2_approval") + "?code=%s" % (self.authorization_code.token, ), data)
        self.assertEqual(request.status_code, 302)
        
        args = {
            "state": "o2cs",

            "code": AuthorizationToken.objects.all()[0].token,