<s> from django . core . urlresolvers import reverse <EOL> from . . test_cases import TokenTestCase <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> import json <EOL> class TestTokenErrors ( TokenTestCase ) : <EOL> def test_grant_type ( self ) : <EOL> from doac . exceptions . unsupported_grant_type import GrantTypeNotProvided , GrantTypeNotValid <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) ) <EOL> self . assertExceptionJson ( request , GrantTypeNotProvided ( ) ) <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertExceptionJson ( request , GrantTypeNotProvided ( ) ) <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertExceptionJson ( request , GrantTypeNotValid ( ) ) <EOL> def test_client_id ( self ) : <EOL> from doac . exceptions . invalid_request import ClientNotProvided <EOL> from doac . exceptions . invalid_client import ClientDoesNotExist <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertExceptionJson ( request , ClientNotProvided ( ) ) <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertExceptionJson ( request , ClientNotProvided ( ) ) <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : <NUM_LIT> } ) <EOL> self . assertExceptionJson ( request , ClientDoesNotExist ( ) ) <EOL> def test_client_secret ( self ) : <EOL> from doac . exceptions . invalid_client import ClientSecretNotValid <EOL> from doac . exceptions . invalid_request import ClientSecretNotProvided <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . oauth_client . id } ) <EOL> self . assertExceptionJson ( request , ClientSecretNotProvided ( ) ) <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . oauth_client . id , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertExceptionJson ( request , ClientSecretNotProvided ( ) ) <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . oauth_client . id , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertExceptionJson ( request , ClientSecretNotValid ( ) ) <EOL> def test_code ( self ) : <EOL> from doac . exceptions . invalid_request import AuthorizationCodeAlreadyUsed , AuthorizationCodeNotProvided , AuthorizationCodeNotValid <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . oauth_client . id , "<STR_LIT>" : self . client_secret } ) <EOL> self . assertExceptionJson ( request , AuthorizationCodeNotProvided ( ) ) <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . oauth_client . id , "<STR_LIT>" : self . client_secret , "<STR_LIT:code>" : "<STR_LIT>" } ) <EOL> self . assertExceptionJson ( request , AuthorizationCodeNotProvided ( ) ) <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . oauth_client . id , "<STR_LIT>" : self . client_secret , "<STR_LIT:code>" : "<STR_LIT>" } ) <EOL> self . assertExceptionJson ( request , AuthorizationCodeNotValid ( ) ) <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . oauth_client . id , "<STR_LIT>" : self . client_secret , "<STR_LIT:code>" : self . authorization_token . token } ) <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . oauth_client . id , "<STR_LIT>" : self . client_secret , "<STR_LIT:code>" : self . authorization_token . token } ) <EOL> self . assertExceptionJson ( request , AuthorizationCodeAlreadyUsed ( ) ) <EOL> def test_refresh_token ( self ) : <EOL> from doac . exceptions . invalid_request import RefreshTokenNotProvided , RefreshTokenNotValid <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . oauth_client . id , "<STR_LIT>" : self . client_secret } ) <EOL> self . assertExceptionJson ( request , RefreshTokenNotProvided ( ) ) <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . oauth_client . id , "<STR_LIT>" : self . client_secret , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertExceptionJson ( request , RefreshTokenNotProvided ( ) ) <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . oauth_client . id , "<STR_LIT>" : self . client_secret , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertExceptionJson ( request , RefreshTokenNotValid ( ) ) <EOL> class TestTokenResponse ( TokenTestCase ) : <EOL> def test_authorization_token ( self ) : <EOL> data = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : self . oauth_client . id , <EOL> "<STR_LIT>" : self . client_secret , <EOL> "<STR_LIT:code>" : self . authorization_token . token , <EOL> } <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , data ) <EOL> response = { <EOL> "<STR_LIT>" : self . authorization_token . refresh_token . token , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : self . authorization_token . refresh_token . access_tokens . all ( ) [ <NUM_LIT:0> ] . token , <EOL> } <EOL> self . assertEqual ( request . content , json . dumps ( response ) ) <EOL> self . assertEqual ( request . status_code , <NUM_LIT:200> ) <EOL> def test_refresh_token ( self ) : <EOL> refresh_token = self . authorization_token . generate_refresh_token ( ) <EOL> data = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : self . oauth_client . id , <EOL> "<STR_LIT>" : self . client_secret , <EOL> "<STR_LIT>" : refresh_token . token , <EOL> } <EOL> request = self . client . post ( reverse ( "<STR_LIT>" ) , data ) <EOL> response = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : refresh_token . access_tokens . all ( ) [ <NUM_LIT:0> ] . token , <EOL> } <EOL> self . assertEqual ( request . content , json . dumps ( response ) ) <EOL> self . assertEqual ( request . status_code , <NUM_LIT:200> ) </s>
