<s> import uuid <EOL> import json <EOL> import urllib <EOL> import os <EOL> import base64 <EOL> import time <EOL> import string <EOL> import random <EOL> import oauth2 as oauth <EOL> from Crypto . PublicKey import RSA <EOL> from django . conf import settings <EOL> from django . contrib . auth . models import User <EOL> from django . core . urlresolvers import reverse <EOL> from django . test import TestCase <EOL> from . . models import Activity , Agent <EOL> from adl_lrs . views import register , regclient <EOL> from oauth_provider . models import Consumer , Token , Nonce <EOL> from oauth_provider . utils import SignatureMethod_RSA_SHA1 <EOL> TEST_SERVER = '<STR_LIT>' <EOL> INITIATE_ENDPOINT = TEST_SERVER + "<STR_LIT>" <EOL> AUTHORIZATION_ENDPOINT = TEST_SERVER + "<STR_LIT>" <EOL> TOKEN_ENDPOINT = TEST_SERVER + "<STR_LIT>" <EOL> class OAuthTests ( TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> print "<STR_LIT>" % __name__ <EOL> super ( OAuthTests , cls ) . setUpClass ( ) <EOL> def setUp ( self ) : <EOL> if not settings . OAUTH_ENABLED : <EOL> settings . OAUTH_ENABLED = True <EOL> form = { "<STR_LIT:username>" : "<STR_LIT>" , "<STR_LIT:email>" : "<STR_LIT>" , "<STR_LIT:password>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> self . client . post ( reverse ( register ) , form , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . user = User . objects . get ( username = '<STR_LIT>' ) <EOL> self . name = "<STR_LIT>" <EOL> self . desc = "<STR_LIT>" <EOL> form = { "<STR_LIT:name>" : self . name , "<STR_LIT:description>" : self . desc } <EOL> self . client . post ( reverse ( regclient ) , form ) <EOL> self . consumer = Consumer . objects . get ( name = self . name ) <EOL> self . name2jane = "<STR_LIT>" <EOL> self . desc2jane = "<STR_LIT>" <EOL> form2jane = { "<STR_LIT:name>" : self . name2jane , "<STR_LIT:description>" : self . desc2jane } <EOL> self . client . post ( reverse ( regclient ) , form2jane ) <EOL> self . consumer2jane = Consumer . objects . get ( name = self . name2jane ) <EOL> self . client . logout ( ) <EOL> self . jane_auth = "<STR_LIT>" % base64 . b64encode ( "<STR_LIT>" % ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . user2 = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . name2 = "<STR_LIT>" <EOL> self . desc2 = "<STR_LIT>" <EOL> form2 = { "<STR_LIT:name>" : self . name2 , "<STR_LIT:description>" : self . desc2 } <EOL> self . client . post ( reverse ( regclient ) , form2 ) <EOL> self . consumer2 = Consumer . objects . get ( name = self . name2 ) <EOL> self . client . logout ( ) <EOL> self . dick_auth = "<STR_LIT>" % base64 . b64encode ( "<STR_LIT>" % ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def tearDown ( self ) : <EOL> if settings . OAUTH_ENABLED : <EOL> settings . OAUTH_ENABLED = False <EOL> Token . objects . all ( ) . delete ( ) <EOL> Consumer . objects . all ( ) . delete ( ) <EOL> Nonce . objects . all ( ) . delete ( ) <EOL> User . objects . all ( ) . delete ( ) <EOL> attach_folder_path = os . path . join ( settings . MEDIA_ROOT , "<STR_LIT>" ) <EOL> for the_file in os . listdir ( attach_folder_path ) : <EOL> file_path = os . path . join ( attach_folder_path , the_file ) <EOL> try : <EOL> os . unlink ( file_path ) <EOL> except Exception , e : <EOL> raise e <EOL> def oauth_handshake ( self , scope = True , scope_type = None , parameters = None , param_type = '<STR_LIT>' , change_scope = [ ] , <EOL> request_nonce = '<STR_LIT>' , access_nonce = '<STR_LIT>' , resource_nonce = '<STR_LIT>' , consumer = None ) : <EOL> if not request_nonce : <EOL> request_nonce = '<STR_LIT>' . join ( random . choice ( string . ascii_uppercase + string . digits ) for _ in range ( <NUM_LIT:6> ) ) <EOL> if not consumer : <EOL> consumer = self . consumer <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( consumer . key , str ( int ( time . time ( ) ) ) , request_nonce ) <EOL> request_token_params = { } <EOL> if parameters : <EOL> request_token_params = parameters <EOL> if scope : <EOL> if scope_type : <EOL> request_token_params [ '<STR_LIT>' ] = scope_type <EOL> else : <EOL> request_token_params [ '<STR_LIT>' ] = "<STR_LIT:all>" <EOL> if param_type == '<STR_LIT>' : <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( request_token_params ) ) <EOL> else : <EOL> request_token_path = INITIATE_ENDPOINT <EOL> oauth_header_request_token_params_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in oauth_header_request_token_params_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> if param_type == '<STR_LIT>' : <EOL> oauth_request = oauth . Request . from_consumer_and_token ( consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> else : <EOL> oauth_request = oauth . Request . from_consumer_and_token ( consumer , token = None , http_method = '<STR_LIT:POST>' , <EOL> http_url = request_token_path , parameters = dict ( oauth_header_request_token_params_dict . items ( ) + request_token_params . items ( ) ) ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> if param_type == '<STR_LIT>' : <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> else : <EOL> request_resp = self . client . post ( request_token_path , Authorization = oauth_header_request_token_params , data = request_token_params , <EOL> content_type = "<STR_LIT>" ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> token_secret = request_resp . content . split ( '<STR_LIT:&>' ) [ <NUM_LIT:0> ] . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> request_token = Token . objects . get ( secret = token_secret ) <EOL> authorize_param = { '<STR_LIT>' : request_token . key } <EOL> authorize_path = "<STR_LIT>" % ( AUTHORIZATION_ENDPOINT , urllib . urlencode ( authorize_param ) ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_resp [ '<STR_LIT>' ] ) <EOL> self . assertIn ( request_token . key , auth_resp [ '<STR_LIT>' ] ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . assertEqual ( request_token . is_approved , False ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT:200> ) <EOL> auth_form = auth_resp . context [ '<STR_LIT>' ] <EOL> data = auth_form . initial <EOL> data [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> data [ '<STR_LIT>' ] = request_token . key <EOL> if change_scope : <EOL> data [ '<STR_LIT>' ] = change_scope <EOL> auth_post = self . client . post ( AUTHORIZATION_ENDPOINT , data ) <EOL> self . assertEqual ( auth_post . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> token_key = auth_post [ '<STR_LIT>' ] . split ( '<STR_LIT:?>' ) [ <NUM_LIT:1> ] . split ( '<STR_LIT:&>' ) [ <NUM_LIT:1> ] . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> request_token_after_auth = Token . objects . get ( key = token_key ) <EOL> self . assertIn ( request_token_after_auth . key , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( request_token_after_auth . is_approved , True ) <EOL> if not access_nonce : <EOL> access_nonce = "<STR_LIT>" <EOL> oauth_header_access_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( consumer . key , request_token_after_auth . key , str ( int ( time . time ( ) ) ) , access_nonce , request_token_after_auth . verifier ) <EOL> param_list = oauth_header_access_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_access_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_access_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_access_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( request_token_after_auth , http_method = '<STR_LIT:GET>' , <EOL> http_url = TOKEN_ENDPOINT , parameters = oauth_header_access_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , consumer , request_token_after_auth ) <EOL> oauth_header_access_token_params += '<STR_LIT>' % signature <EOL> access_resp = self . client . get ( TOKEN_ENDPOINT , Authorization = oauth_header_access_token_params ) <EOL> self . assertEqual ( access_resp . status_code , <NUM_LIT:200> ) <EOL> content = access_resp . content . split ( '<STR_LIT:&>' ) <EOL> access_token_secret = content [ <NUM_LIT:0> ] . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> access_token_key = content [ <NUM_LIT:1> ] . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> access_token = Token . objects . get ( secret = access_token_secret , key = access_token_key ) <EOL> if not resource_nonce : <EOL> resource_nonce = "<STR_LIT>" <EOL> oauth_header_resource_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( consumer . key , access_token . key , str ( int ( time . time ( ) ) ) , resource_nonce ) <EOL> self . client . logout ( ) <EOL> return oauth_header_resource_params , access_token <EOL> def oauth_handshake2 ( self , scope = True , scope_type = None , parameters = None , param_type = '<STR_LIT>' , change_scope = [ ] , <EOL> request_nonce = '<STR_LIT>' , access_nonce = '<STR_LIT>' , resource_nonce = '<STR_LIT>' ) : <EOL> if not request_nonce : <EOL> request_nonce = "<STR_LIT>" <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer2 . key , str ( int ( time . time ( ) ) ) , request_nonce ) <EOL> request_token_params = { } <EOL> if parameters : <EOL> request_token_params = parameters <EOL> if scope : <EOL> if scope_type : <EOL> request_token_params [ '<STR_LIT>' ] = scope_type <EOL> else : <EOL> request_token_params [ '<STR_LIT>' ] = "<STR_LIT:all>" <EOL> if param_type == '<STR_LIT>' : <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( request_token_params ) ) <EOL> else : <EOL> request_token_path = INITIATE_ENDPOINT <EOL> oauth_header_request_token_params_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in oauth_header_request_token_params_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> if param_type == '<STR_LIT>' : <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer2 , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> else : <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer2 , token = None , http_method = '<STR_LIT:POST>' , <EOL> http_url = request_token_path , parameters = dict ( oauth_header_request_token_params_dict . items ( ) + request_token_params . items ( ) ) ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer2 , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> if param_type == '<STR_LIT>' : <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> else : <EOL> request_resp = self . client . post ( request_token_path , Authorization = oauth_header_request_token_params , data = request_token_params , <EOL> content_type = "<STR_LIT>" ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> request_token = Token . objects . get ( consumer = self . consumer2 ) <EOL> authorize_param = { '<STR_LIT>' : request_token . key } <EOL> authorize_path = "<STR_LIT>" % ( AUTHORIZATION_ENDPOINT , urllib . urlencode ( authorize_param ) ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_resp [ '<STR_LIT>' ] ) <EOL> self . assertIn ( request_token . key , auth_resp [ '<STR_LIT>' ] ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . assertEqual ( request_token . is_approved , False ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT:200> ) <EOL> auth_form = auth_resp . context [ '<STR_LIT>' ] <EOL> data = auth_form . initial <EOL> data [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> data [ '<STR_LIT>' ] = request_token . key <EOL> if change_scope : <EOL> data [ '<STR_LIT>' ] = change_scope <EOL> auth_post = self . client . post ( AUTHORIZATION_ENDPOINT , data ) <EOL> self . assertEqual ( auth_post . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> request_token_after_auth = Token . objects . get ( consumer = self . consumer2 ) <EOL> self . assertIn ( request_token_after_auth . key , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( request_token_after_auth . is_approved , True ) <EOL> if not access_nonce : <EOL> access_nonce = "<STR_LIT>" <EOL> oauth_header_access_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer2 . key , request_token_after_auth . key , str ( int ( time . time ( ) ) ) , access_nonce , request_token_after_auth . verifier ) <EOL> param_list = oauth_header_access_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_access_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_access_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_access_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( request_token_after_auth , http_method = '<STR_LIT:GET>' , <EOL> http_url = TOKEN_ENDPOINT , parameters = oauth_header_access_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer2 , request_token_after_auth ) <EOL> oauth_header_access_token_params += '<STR_LIT>' % signature <EOL> access_resp = self . client . get ( TOKEN_ENDPOINT , Authorization = oauth_header_access_token_params ) <EOL> self . assertEqual ( access_resp . status_code , <NUM_LIT:200> ) <EOL> content = access_resp . content . split ( '<STR_LIT:&>' ) <EOL> access_token_secret = content [ <NUM_LIT:0> ] . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> access_token_key = content [ <NUM_LIT:1> ] . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> access_token = Token . objects . get ( secret = access_token_secret , key = access_token_key ) <EOL> if not resource_nonce : <EOL> resource_nonce = "<STR_LIT>" <EOL> oauth_header_resource_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer2 . key , access_token . key , str ( int ( time . time ( ) ) ) , resource_nonce ) <EOL> self . client . logout ( ) <EOL> return oauth_header_resource_params , access_token <EOL> def test_request_token_missing_headers ( self ) : <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = INITIATE_ENDPOINT , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> resp = self . client . get ( INITIATE_ENDPOINT ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> def test_request_token_unsupported_headers ( self ) : <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = INITIATE_ENDPOINT , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> resp = self . client . get ( INITIATE_ENDPOINT ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> def test_request_token_duplicated_headers ( self ) : <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = INITIATE_ENDPOINT , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> resp = self . client . get ( INITIATE_ENDPOINT ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> def test_request_token_unsupported_signature_method ( self ) : <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = INITIATE_ENDPOINT , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> resp = self . client . get ( INITIATE_ENDPOINT ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> def test_request_token_invalid_consumer_credentials ( self ) : <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( "<STR_LIT>" , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = INITIATE_ENDPOINT , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> resp = self . client . get ( INITIATE_ENDPOINT , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> def test_request_token_unknown_scope ( self ) : <EOL> form_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = INITIATE_ENDPOINT , parameters = dict ( oauth_header_request_token_params_dict . items ( ) + form_data . items ( ) ) ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( INITIATE_ENDPOINT , Authorization = oauth_header_request_token_params , data = form_data , <EOL> content_type = "<STR_LIT>" ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( request_resp . content , '<STR_LIT>' ) <EOL> def test_request_token_wrong_scope ( self ) : <EOL> form_data = { <EOL> '<STR_LIT>' : '<STR_LIT:all>' , <EOL> } <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = INITIATE_ENDPOINT , parameters = dict ( oauth_header_request_token_params_dict . items ( ) + form_data . items ( ) ) ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> form_data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> request_resp = self . client . get ( INITIATE_ENDPOINT , Authorization = oauth_header_request_token_params , data = form_data , <EOL> content_type = "<STR_LIT>" ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( request_resp . content , '<STR_LIT>' ) <EOL> def test_request_token_same_nonce_and_time ( self ) : <EOL> now_time = str ( int ( time . time ( ) ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , now_time ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = INITIATE_ENDPOINT , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( INITIATE_ENDPOINT , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> oauth_header_request_token_params2 = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , now_time ) <EOL> request_token_param_list2 = oauth_header_request_token_params2 . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict2 = { } <EOL> for p in request_token_param_list2 : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict2 [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict2 [ '<STR_LIT>' ] <EOL> oauth_request2 = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = INITIATE_ENDPOINT , parameters = oauth_header_request_token_params_dict2 ) <EOL> signature_method2 = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature2 = signature_method2 . sign ( oauth_request2 , self . consumer , None ) <EOL> oauth_header_request_token_params2 = oauth_header_request_token_params2 + "<STR_LIT>" % signature2 <EOL> request_resp2 = self . client . get ( INITIATE_ENDPOINT , Authorization = oauth_header_request_token_params2 ) <EOL> self . assertEqual ( request_resp2 . status_code , <NUM_LIT> ) <EOL> def test_request_token_no_scope ( self ) : <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = INITIATE_ENDPOINT , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( INITIATE_ENDPOINT , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> def test_request_token_scope_in_form ( self ) : <EOL> form_data = { <EOL> '<STR_LIT>' : '<STR_LIT:all>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:POST>' , <EOL> http_url = INITIATE_ENDPOINT , parameters = dict ( oauth_header_request_token_params_dict . items ( ) + form_data . items ( ) ) ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . post ( INITIATE_ENDPOINT , Authorization = oauth_header_request_token_params , data = form_data , <EOL> content_type = "<STR_LIT>" ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> def test_request_token_scope_in_qs ( self ) : <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT:all>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> def test_request_token_plaintext ( self ) : <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT:all>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_PLAINTEXT ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> def test_request_token_rsa_sha1 ( self ) : <EOL> rsa_key = RSA . importKey ( """<STR_LIT>""" ) <EOL> self . consumer . secret = rsa_key . exportKey ( ) <EOL> self . consumer . save ( ) <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT:all>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = SignatureMethod_RSA_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> def test_request_token_rsa_sha1_full_workflow ( self ) : <EOL> User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> name = "<STR_LIT>" <EOL> desc = "<STR_LIT>" <EOL> rsa_key = """<STR_LIT>""" <EOL> form = { "<STR_LIT:name>" : name , "<STR_LIT:description>" : desc , "<STR_LIT>" : True , "<STR_LIT>" : rsa_key } <EOL> my_regclient = self . client . post ( reverse ( regclient ) , form ) <EOL> self . assertEqual ( my_regclient . status_code , <NUM_LIT:200> ) <EOL> consumer = Consumer . objects . get ( name = name ) <EOL> self . client . logout ( ) <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT:all>' , <EOL> '<STR_LIT>' : name <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = SignatureMethod_RSA_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> request_token = Token . objects . get ( consumer = consumer ) <EOL> authorize_param = { '<STR_LIT>' : request_token . key } <EOL> authorize_path = "<STR_LIT>" % ( AUTHORIZATION_ENDPOINT , urllib . urlencode ( authorize_param ) ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_resp [ '<STR_LIT>' ] ) <EOL> self . assertIn ( request_token . key , auth_resp [ '<STR_LIT>' ] ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . assertEqual ( request_token . is_approved , False ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT:200> ) <EOL> auth_form = auth_resp . context [ '<STR_LIT>' ] <EOL> data = auth_form . initial <EOL> data [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> data [ '<STR_LIT>' ] = request_token . key <EOL> auth_post = self . client . post ( AUTHORIZATION_ENDPOINT , data ) <EOL> self . assertEqual ( auth_post . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> request_token_after_auth = Token . objects . get ( consumer = consumer ) <EOL> self . assertIn ( request_token_after_auth . key , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( request_token_after_auth . is_approved , True ) <EOL> oauth_header_access_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( consumer . key , request_token_after_auth . key , str ( int ( time . time ( ) ) ) , "<STR_LIT>" , request_token_after_auth . verifier ) <EOL> param_list = oauth_header_access_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_access_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_access_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_access_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( request_token_after_auth , http_method = '<STR_LIT:GET>' , <EOL> http_url = TOKEN_ENDPOINT , parameters = oauth_header_access_params_dict ) <EOL> signature_method = SignatureMethod_RSA_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , consumer , request_token_after_auth ) <EOL> oauth_header_access_token_params += '<STR_LIT>' % signature <EOL> access_resp = self . client . get ( TOKEN_ENDPOINT , Authorization = oauth_header_access_token_params ) <EOL> self . assertEqual ( access_resp . status_code , <NUM_LIT:200> ) <EOL> content = access_resp . content . split ( '<STR_LIT:&>' ) <EOL> access_token_secret = content [ <NUM_LIT:0> ] . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> access_token_key = content [ <NUM_LIT:1> ] . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> access_token = Token . objects . get ( secret = urllib . unquote_plus ( access_token_secret ) , key = access_token_key ) <EOL> oauth_header_resource_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( consumer . key , access_token . key , str ( int ( time . time ( ) ) ) , "<STR_LIT>" ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> path = TEST_SERVER + "<STR_LIT>" <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = SignatureMethod_RSA_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . get ( path , Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> def test_request_token_rsa_sha1_wrong_key ( self ) : <EOL> rsa_key = RSA . importKey ( """<STR_LIT>""" ) <EOL> self . consumer . secret = rsa_key . exportKey ( ) <EOL> self . consumer . save ( ) <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT:all>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % "<STR_LIT>" <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT> ) <EOL> def test_request_token_wrong_oauth_version ( self ) : <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT:all>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_PLAINTEXT ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT> ) <EOL> def test_request_token_wrong_signature ( self ) : <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT:all>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % "<STR_LIT>" <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( request_resp . content , '<STR_LIT>' ) <EOL> def test_auth_correct ( self ) : <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT:all>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_PLAINTEXT ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> token = Token . objects . get ( consumer = self . consumer ) <EOL> param = { '<STR_LIT>' : token . key } <EOL> authorize_path = "<STR_LIT>" % ( AUTHORIZATION_ENDPOINT , urllib . urlencode ( param ) ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_resp [ '<STR_LIT>' ] ) <EOL> self . assertIn ( token . key , auth_resp [ '<STR_LIT>' ] ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . assertEqual ( token . is_approved , False ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT:200> ) <EOL> auth_form = auth_resp . context [ '<STR_LIT>' ] <EOL> data = auth_form . initial <EOL> data [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> data [ '<STR_LIT>' ] = token . key <EOL> auth_post = self . client . post ( AUTHORIZATION_ENDPOINT , data ) <EOL> self . assertEqual ( auth_post . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> access_token = Token . objects . get ( consumer = self . consumer ) <EOL> self . assertIn ( access_token . key , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( access_token . is_approved , True ) <EOL> def test_auth_scope_up ( self ) : <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_PLAINTEXT ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> token = Token . objects . get ( consumer = self . consumer ) <EOL> param = { '<STR_LIT>' : token . key } <EOL> authorize_path = "<STR_LIT>" % ( AUTHORIZATION_ENDPOINT , urllib . urlencode ( param ) ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_resp [ '<STR_LIT>' ] ) <EOL> self . assertIn ( token . key , auth_resp [ '<STR_LIT>' ] ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . assertEqual ( token . is_approved , False ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT:200> ) <EOL> auth_form = auth_resp . context [ '<STR_LIT>' ] <EOL> data = auth_form . initial <EOL> data [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> data [ '<STR_LIT>' ] = token . key <EOL> data [ '<STR_LIT>' ] = [ '<STR_LIT:all>' ] <EOL> auth_post = self . client . post ( AUTHORIZATION_ENDPOINT , data ) <EOL> self . assertEqual ( auth_post . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( auth_post . content , '<STR_LIT>' ) <EOL> def test_auth_wrong_auth ( self ) : <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_PLAINTEXT ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> token = Token . objects . get ( consumer = self . consumer ) <EOL> param = { '<STR_LIT>' : token . key } <EOL> authorize_path = "<STR_LIT>" % ( AUTHORIZATION_ENDPOINT , urllib . urlencode ( param ) ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_resp [ '<STR_LIT>' ] ) <EOL> self . assertIn ( token . key , auth_resp [ '<STR_LIT>' ] ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . assertEqual ( token . is_approved , False ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( auth_resp . content , '<STR_LIT>' ) <EOL> def test_auth_no_scope_chosen ( self ) : <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_PLAINTEXT ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> token = Token . objects . get ( consumer = self . consumer ) <EOL> param = { '<STR_LIT>' : token . key } <EOL> authorize_path = "<STR_LIT>" % ( AUTHORIZATION_ENDPOINT , urllib . urlencode ( param ) ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_resp [ '<STR_LIT>' ] ) <EOL> self . assertIn ( token . key , auth_resp [ '<STR_LIT>' ] ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . assertEqual ( token . is_approved , False ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT:200> ) <EOL> auth_form = auth_resp . context [ '<STR_LIT>' ] <EOL> data = auth_form . initial <EOL> data [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> data [ '<STR_LIT>' ] = token . key <EOL> data [ '<STR_LIT>' ] = [ ] <EOL> auth_post = self . client . post ( AUTHORIZATION_ENDPOINT , data ) <EOL> self . assertEqual ( auth_post . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( auth_post . content , '<STR_LIT>' ) <EOL> def test_access_token_invalid_token ( self ) : <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT:all>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_PLAINTEXT ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> token = Token . objects . get ( consumer = self . consumer ) <EOL> param = { '<STR_LIT>' : token . key } <EOL> authorize_path = "<STR_LIT>" % ( AUTHORIZATION_ENDPOINT , urllib . urlencode ( param ) ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_resp [ '<STR_LIT>' ] ) <EOL> self . assertIn ( token . key , auth_resp [ '<STR_LIT>' ] ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . assertEqual ( token . is_approved , False ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT:200> ) <EOL> auth_form = auth_resp . context [ '<STR_LIT>' ] <EOL> data = auth_form . initial <EOL> data [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> data [ '<STR_LIT>' ] = token . key <EOL> auth_post = self . client . post ( AUTHORIZATION_ENDPOINT , data ) <EOL> self . assertEqual ( auth_post . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> access_token = Token . objects . get ( consumer = self . consumer ) <EOL> self . assertIn ( access_token . key , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( access_token . is_approved , True ) <EOL> access_token . is_approved = False <EOL> access_token . save ( ) <EOL> oauth_header_access_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , token . key , self . consumer . secret , token . secret , str ( int ( time . time ( ) ) ) , token . verifier ) <EOL> access_resp = self . client . get ( TOKEN_ENDPOINT , Authorization = oauth_header_access_params ) <EOL> self . assertEqual ( access_resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( access_resp . content , "<STR_LIT>" ) <EOL> def test_access_token_access_resources ( self ) : <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT:all>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_PLAINTEXT ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( request_token_path , Authorization = oauth_header_request_token_params ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> token = Token . objects . get ( consumer = self . consumer ) <EOL> param = { '<STR_LIT>' : token . key } <EOL> authorize_path = "<STR_LIT>" % ( AUTHORIZATION_ENDPOINT , urllib . urlencode ( param ) ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_resp [ '<STR_LIT>' ] ) <EOL> self . assertIn ( token . key , auth_resp [ '<STR_LIT>' ] ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . assertEqual ( token . is_approved , False ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT:200> ) <EOL> auth_form = auth_resp . context [ '<STR_LIT>' ] <EOL> data = auth_form . initial <EOL> data [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> data [ '<STR_LIT>' ] = token . key <EOL> auth_post = self . client . post ( AUTHORIZATION_ENDPOINT , data ) <EOL> self . assertEqual ( auth_post . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> request_token = Token . objects . get ( consumer = self . consumer ) <EOL> self . assertIn ( request_token . key , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( request_token . is_approved , True ) <EOL> oauth_header_access_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , token . key , self . consumer . secret , request_token . secret , str ( int ( time . time ( ) ) ) , request_token . verifier ) <EOL> access_resp = self . client . get ( TOKEN_ENDPOINT , Authorization = oauth_header_access_params ) <EOL> self . assertEqual ( access_resp . status_code , <NUM_LIT:200> ) <EOL> content = access_resp . content . split ( '<STR_LIT:&>' ) <EOL> access_token_secret = content [ <NUM_LIT:0> ] . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> access_token_key = content [ <NUM_LIT:1> ] . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> access_token = Token . objects . get ( secret = access_token_secret , key = access_token_key ) <EOL> oauth_header_resource_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , access_token . key , str ( int ( time . time ( ) ) ) ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> path = TEST_SERVER + "<STR_LIT>" <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . get ( path , Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> def test_unicode ( self ) : <EOL> param = { <EOL> '<STR_LIT>' : '<STR_LIT:all>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> request_token_path = "<STR_LIT>" % ( INITIATE_ENDPOINT , urllib . urlencode ( param ) ) <EOL> oauth_header_request_token_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , str ( int ( time . time ( ) ) ) ) <EOL> request_token_param_list = oauth_header_request_token_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_request_token_params_dict = { } <EOL> for p in request_token_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_request_token_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_request_token_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_consumer_and_token ( self . consumer , token = None , http_method = '<STR_LIT:GET>' , <EOL> http_url = request_token_path , parameters = oauth_header_request_token_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , None ) <EOL> oauth_header_request_token_params = oauth_header_request_token_params + "<STR_LIT>" % signature <EOL> request_resp = self . client . get ( request_token_path , Authorization = unicode ( oauth_header_request_token_params ) ) <EOL> self . assertEqual ( request_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> self . assertIn ( '<STR_LIT>' , request_resp . content ) <EOL> token = Token . objects . get ( consumer = self . consumer ) <EOL> param = { '<STR_LIT>' : token . key } <EOL> authorize_path = "<STR_LIT>" % ( AUTHORIZATION_ENDPOINT , urllib . urlencode ( param ) ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_resp [ '<STR_LIT>' ] ) <EOL> self . assertIn ( token . key , auth_resp [ '<STR_LIT>' ] ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . assertEqual ( token . is_approved , False ) <EOL> auth_resp = self . client . get ( authorize_path ) <EOL> self . assertEqual ( auth_resp . status_code , <NUM_LIT:200> ) <EOL> auth_form = auth_resp . context [ '<STR_LIT>' ] <EOL> data = auth_form . initial <EOL> data [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> data [ '<STR_LIT>' ] = token . key <EOL> auth_post = self . client . post ( AUTHORIZATION_ENDPOINT , data ) <EOL> self . assertEqual ( auth_post . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , auth_post [ '<STR_LIT>' ] ) <EOL> request_token = Token . objects . get ( consumer = self . consumer ) <EOL> self . assertIn ( request_token . key , auth_post [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( request_token . is_approved , True ) <EOL> oauth_header_access_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , token . key , str ( int ( time . time ( ) ) ) , request_token . verifier ) <EOL> param_list = oauth_header_access_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_access_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_access_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_access_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( request_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = TOKEN_ENDPOINT , parameters = oauth_header_access_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , request_token ) <EOL> oauth_header_access_params += '<STR_LIT>' % signature <EOL> access_resp = self . client . get ( TOKEN_ENDPOINT , Authorization = unicode ( oauth_header_access_params ) ) <EOL> self . assertEqual ( access_resp . status_code , <NUM_LIT:200> ) <EOL> content = access_resp . content . split ( '<STR_LIT:&>' ) <EOL> access_token_secret = content [ <NUM_LIT:0> ] . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> access_token_key = content [ <NUM_LIT:1> ] . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> access_token = Token . objects . get ( secret = access_token_secret , key = access_token_key ) <EOL> oauth_header_resource_params = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ( self . consumer . key , access_token . key , str ( int ( time . time ( ) ) ) ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> path = TEST_SERVER + "<STR_LIT>" <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . get ( path , Authorization = unicode ( oauth_header_resource_params ) , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> def test_oauth_disabled ( self ) : <EOL> if settings . OAUTH_ENABLED : <EOL> settings . OAUTH_ENABLED = False <EOL> put_guid = str ( uuid . uuid1 ( ) ) <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } } ) <EOL> param = { "<STR_LIT>" : put_guid } <EOL> path = "<STR_LIT>" % ( '<STR_LIT>' , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . put ( path , data = stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , "<STR_LIT>" ) <EOL> def test_stmt_put ( self ) : <EOL> put_guid = str ( uuid . uuid1 ( ) ) <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } } ) <EOL> param = { "<STR_LIT>" : put_guid } <EOL> path = "<STR_LIT>" % ( '<STR_LIT>' , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . put ( path , data = stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> def test_stmt_post_no_scope ( self ) : <EOL> stmt = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } } <EOL> stmt_json = json . dumps ( stmt ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope = False ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:POST>' , <EOL> http_url = '<STR_LIT>' , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> post = self . client . post ( '<STR_LIT>' , data = stmt_json , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( post . status_code , <NUM_LIT:200> ) <EOL> def test_stmt_simple_get ( self ) : <EOL> guid = str ( uuid . uuid1 ( ) ) <EOL> stmt_data = { "<STR_LIT:id>" : guid , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } } <EOL> stmt_post = self . client . post ( reverse ( '<STR_LIT>' ) , json . dumps ( stmt_data ) , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . jane_auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( stmt_post . status_code , <NUM_LIT:200> ) <EOL> param = { "<STR_LIT>" : guid } <EOL> path = "<STR_LIT>" % ( '<STR_LIT>' , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . get ( path , Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> rsp = resp . content <EOL> self . assertIn ( guid , rsp ) <EOL> def test_stmt_complex_get ( self ) : <EOL> stmt_data = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } } <EOL> stmt_post = self . client . post ( reverse ( '<STR_LIT>' ) , json . dumps ( stmt_data ) , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . jane_auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( stmt_post . status_code , <NUM_LIT:200> ) <EOL> param = { "<STR_LIT>" : "<STR_LIT>" } <EOL> path = "<STR_LIT>" % ( '<STR_LIT>' , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . get ( path , Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> def test_stmt_get_then_wrong_scope ( self ) : <EOL> guid = str ( uuid . uuid1 ( ) ) <EOL> stmt_data = { "<STR_LIT:id>" : guid , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } } <EOL> stmt_post = self . client . post ( reverse ( '<STR_LIT>' ) , json . dumps ( stmt_data ) , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . jane_auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( stmt_post . status_code , <NUM_LIT:200> ) <EOL> param = { "<STR_LIT>" : guid } <EOL> path = "<STR_LIT>" % ( '<STR_LIT>' , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope_type = "<STR_LIT>" ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . get ( path , Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> rsp = resp . content <EOL> self . assertIn ( guid , rsp ) <EOL> post_stmt = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } } <EOL> post_stmt_json = json . dumps ( post_stmt ) <EOL> oauth_header_resource_params_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> oauth_request2 = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:POST>' , <EOL> http_url = '<STR_LIT>' , parameters = oauth_header_resource_params_dict ) <EOL> signature_method2 = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature2 = signature_method2 . sign ( oauth_request2 , self . consumer , access_token ) <EOL> oauth_header_resource_params = oauth_header_resource_params . replace ( '<STR_LIT>' % signature , '<STR_LIT>' % signature2 ) <EOL> oauth_header_resource_params = oauth_header_resource_params . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> post = self . client . post ( '<STR_LIT>' , data = post_stmt_json , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( post . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( post . content , '<STR_LIT>' ) <EOL> def test_activity_state_put_then_wrong_scope ( self ) : <EOL> url = TEST_SERVER + '<STR_LIT>' <EOL> testagent = '<STR_LIT>' <EOL> activityId = "<STR_LIT>" <EOL> stateId = "<STR_LIT>" <EOL> activity = Activity ( activity_id = activityId ) <EOL> activity . save ( ) <EOL> testparams = { "<STR_LIT>" : stateId , "<STR_LIT>" : activityId , "<STR_LIT>" : testagent } <EOL> teststate = { "<STR_LIT:test>" : "<STR_LIT>" } <EOL> path = '<STR_LIT>' % ( url , urllib . urlencode ( testparams ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope_type = '<STR_LIT:state>' ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> put = self . client . put ( path , data = teststate , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( put . status_code , <NUM_LIT> ) <EOL> guid = str ( uuid . uuid1 ( ) ) <EOL> stmt_data = { "<STR_LIT:id>" : guid , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } } <EOL> stmt_post = self . client . post ( reverse ( '<STR_LIT>' ) , json . dumps ( stmt_data ) , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . jane_auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( stmt_post . status_code , <NUM_LIT:200> ) <EOL> param = { "<STR_LIT>" : guid } <EOL> path = "<STR_LIT>" % ( '<STR_LIT>' , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature2 = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params_new = oauth_header_resource_params . replace ( '<STR_LIT>' % signature , '<STR_LIT>' % signature2 ) <EOL> new_oauth_headers = oauth_header_resource_params_new . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> get = self . client . get ( path , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = new_oauth_headers , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( get . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( get . content , '<STR_LIT>' ) <EOL> def stmt_get_then_wrong_profile_scope ( self ) : <EOL> guid = str ( uuid . uuid1 ( ) ) <EOL> stmt_data = { "<STR_LIT:id>" : guid , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } } <EOL> stmt_post = self . client . post ( reverse ( '<STR_LIT>' ) , json . dumps ( stmt_data ) , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . jane_auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( stmt_post . status_code , <NUM_LIT:200> ) <EOL> param = { "<STR_LIT>" : guid } <EOL> path = "<STR_LIT>" % ( '<STR_LIT>' , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope_type = "<STR_LIT>" ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . get ( path , Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> rsp = resp . content <EOL> self . assertIn ( guid , rsp ) <EOL> url = '<STR_LIT>' <EOL> params = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } <EOL> path = "<STR_LIT>" % ( url , urllib . urlencode ( params ) ) <EOL> oauth_header_resource_params_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method2 = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature2 = signature_method2 . sign ( oauth_request , self . consumer , access_token ) <EOL> new_sig_params = oauth_header_resource_params . replace ( '<STR_LIT>' % signature , '<STR_LIT>' % signature2 ) <EOL> new_oauth_headers = new_sig_params . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> r = self . client . get ( path , Authorization = new_oauth_headers , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> def test_consumer_state ( self ) : <EOL> stmt_data = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } } <EOL> stmt_post = self . client . post ( reverse ( '<STR_LIT>' ) , json . dumps ( stmt_data ) , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . jane_auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( stmt_post . status_code , <NUM_LIT:200> ) <EOL> param = { "<STR_LIT:object>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:id>" : "<STR_LIT>" } } <EOL> path = "<STR_LIT>" % ( '<STR_LIT>' , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> consumer = access_token . consumer <EOL> consumer . status = <NUM_LIT:4> <EOL> consumer . save ( ) <EOL> resp = self . client . get ( path , Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> def test_simple_stmt_get_mine_only ( self ) : <EOL> guid = str ( uuid . uuid1 ( ) ) <EOL> username = "<STR_LIT>" <EOL> email = "<STR_LIT>" <EOL> password = "<STR_LIT:test>" <EOL> auth = "<STR_LIT>" % base64 . b64encode ( "<STR_LIT>" % ( username , password ) ) <EOL> form = { "<STR_LIT:username>" : username , "<STR_LIT:email>" : email , "<STR_LIT:password>" : password , "<STR_LIT>" : password } <EOL> self . client . post ( reverse ( register ) , form , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . client . logout ( ) <EOL> param = { "<STR_LIT>" : guid } <EOL> path = "<STR_LIT>" % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( param ) ) <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } } ) <EOL> put_resp = self . client . put ( path , stmt , content_type = "<STR_LIT:application/json>" , Authorization = auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( put_resp . status_code , <NUM_LIT> ) <EOL> param = { "<STR_LIT>" : guid } <EOL> path = "<STR_LIT>" % ( '<STR_LIT>' , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope_type = "<STR_LIT>" ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . get ( path , Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> oauth_agent1 = Agent . objects . get ( account_name = self . consumer . key ) <EOL> oauth_agent2 = Agent . objects . get ( mbox = "<STR_LIT>" ) <EOL> oauth_group = Agent . objects . get ( member__in = [ oauth_agent1 , oauth_agent2 ] ) <EOL> guid = str ( uuid . uuid1 ( ) ) <EOL> stmt_data = { "<STR_LIT:id>" : guid , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } , "<STR_LIT>" : oauth_group . to_dict ( ) } <EOL> settings . ALLOW_EMPTY_HTTP_AUTH = True <EOL> stmt_post = self . client . post ( reverse ( '<STR_LIT>' ) , json . dumps ( stmt_data ) , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = "<STR_LIT>" % base64 . b64encode ( "<STR_LIT>" % ( '<STR_LIT>' , '<STR_LIT>' ) ) , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( stmt_post . status_code , <NUM_LIT:200> ) <EOL> param = { "<STR_LIT>" : guid } <EOL> path = "<STR_LIT>" % ( '<STR_LIT>' , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> oauth_request2 = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method2 = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature2 = signature_method2 . sign ( oauth_request2 , self . consumer , access_token ) <EOL> sig = oauth_header_resource_params . replace ( '<STR_LIT>' % signature , '<STR_LIT>' % signature2 ) <EOL> new_oauth_headers = sig . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> get = self . client . get ( path , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = new_oauth_headers , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( get . status_code , <NUM_LIT:200> ) <EOL> settings . ALLOW_EMPTY_HTTP_AUTH = False <EOL> def test_complex_stmt_get_mine_only ( self ) : <EOL> guid = str ( uuid . uuid1 ( ) ) <EOL> username = "<STR_LIT>" <EOL> email = "<STR_LIT>" <EOL> password = "<STR_LIT:test>" <EOL> auth = "<STR_LIT>" % base64 . b64encode ( "<STR_LIT>" % ( username , password ) ) <EOL> form = { "<STR_LIT:username>" : username , "<STR_LIT:email>" : email , "<STR_LIT:password>" : password , "<STR_LIT>" : password } <EOL> self . client . post ( reverse ( register ) , form , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . client . logout ( ) <EOL> param = { "<STR_LIT>" : guid } <EOL> path = "<STR_LIT>" % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( param ) ) <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } } ) <EOL> put_response = self . client . put ( path , stmt , content_type = "<STR_LIT:application/json>" , Authorization = auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( put_response . status_code , <NUM_LIT> ) <EOL> param = { "<STR_LIT>" : guid } <EOL> path = "<STR_LIT>" % ( '<STR_LIT>' , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope_type = "<STR_LIT>" ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . get ( path , Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> oauth_header_resource_params_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> oauth_request2 = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = '<STR_LIT>' , parameters = oauth_header_resource_params_dict ) <EOL> signature_method2 = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature2 = signature_method2 . sign ( oauth_request2 , self . consumer , access_token ) <EOL> sig = oauth_header_resource_params . replace ( '<STR_LIT>' % signature , '<STR_LIT>' % signature2 ) <EOL> new_oauth_headers = sig . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> get = self . client . get ( '<STR_LIT>' , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = new_oauth_headers , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> get_content = json . loads ( get . content ) <EOL> self . assertEqual ( get . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( get_content [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> oauth_agent1 = Agent . objects . get ( account_name = self . consumer . key ) <EOL> oauth_agent2 = Agent . objects . get ( mbox = "<STR_LIT>" ) <EOL> oauth_group = Agent . objects . get ( member__in = [ oauth_agent1 , oauth_agent2 ] ) <EOL> guid = str ( uuid . uuid1 ( ) ) <EOL> stmt_data = { "<STR_LIT:id>" : guid , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } , "<STR_LIT>" : oauth_group . to_dict ( ) } <EOL> stmt_post = self . client . post ( reverse ( '<STR_LIT>' ) , json . dumps ( stmt_data ) , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . jane_auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( stmt_post . status_code , <NUM_LIT:200> ) <EOL> oauth_header_resource_params_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> oauth_request3 = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = '<STR_LIT>' , parameters = oauth_header_resource_params_dict ) <EOL> signature_method3 = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature3 = signature_method3 . sign ( oauth_request3 , self . consumer , access_token ) <EOL> sig2 = oauth_header_resource_params . replace ( '<STR_LIT>' % signature , '<STR_LIT>' % signature3 ) <EOL> new_oauth_headers2 = sig2 . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> get2 = self . client . get ( '<STR_LIT>' , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = new_oauth_headers2 , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> get_content2 = json . loads ( get2 . content ) <EOL> self . assertEqual ( get2 . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( get_content2 [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( get_content2 [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def test_state_wrong_auth ( self ) : <EOL> url = '<STR_LIT>' <EOL> testagent = '<STR_LIT>' <EOL> activityId = "<STR_LIT>" <EOL> stateId = "<STR_LIT>" <EOL> activity = Activity ( activity_id = activityId ) <EOL> activity . save ( ) <EOL> testparams = { "<STR_LIT>" : stateId , "<STR_LIT>" : activityId , "<STR_LIT>" : testagent } <EOL> teststate = { "<STR_LIT:test>" : "<STR_LIT>" } <EOL> path = '<STR_LIT>' % ( url , urllib . urlencode ( testparams ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope_type = '<STR_LIT:state>' ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> put = self . client . put ( path , data = teststate , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( put . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( put . content , "<STR_LIT>" ) <EOL> def test_profile_wrong_auth ( self ) : <EOL> agent = Agent ( name = "<STR_LIT>" , mbox = "<STR_LIT>" ) <EOL> agent . save ( ) <EOL> url = '<STR_LIT>' <EOL> testparams = { "<STR_LIT>" : '<STR_LIT>' } <EOL> path = '<STR_LIT>' % ( url , urllib . urlencode ( testparams ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope_type = '<STR_LIT>' ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> get = self . client . get ( path , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( get . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( get . content , "<STR_LIT>" ) <EOL> def test_define_scope_activity ( self ) : <EOL> url = '<STR_LIT>' <EOL> guid = str ( uuid . uuid1 ( ) ) <EOL> stmt_data = { "<STR_LIT:id>" : guid , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } } <EOL> stmt_post = self . client . post ( reverse ( '<STR_LIT>' ) , json . dumps ( stmt_data ) , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . jane_auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( stmt_post . status_code , <NUM_LIT:200> ) <EOL> put_guid = str ( uuid . uuid1 ( ) ) <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT:description>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : [ ] } } } ) <EOL> param = { "<STR_LIT>" : put_guid } <EOL> path = "<STR_LIT>" % ( url , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope_type = '<STR_LIT>' ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . put ( path , data = stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> acts = Activity . objects . all ( ) <EOL> self . assertEqual ( len ( acts ) , <NUM_LIT:1> ) <EOL> get_params = { "<STR_LIT>" : "<STR_LIT>" } <EOL> path = "<STR_LIT>" % ( url , urllib . urlencode ( get_params ) ) <EOL> oauth_header_resource_params_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> oauth_request2 = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method2 = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature2 = signature_method2 . sign ( oauth_request2 , self . consumer , access_token ) <EOL> sig = oauth_header_resource_params . replace ( '<STR_LIT>' % signature , '<STR_LIT>' % signature2 ) <EOL> new_oauth_headers = sig . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> get_resp = self . client . get ( path , X_Experience_API_Version = settings . XAPI_VERSION , Authorization = new_oauth_headers ) <EOL> self . assertEqual ( get_resp . status_code , <NUM_LIT:200> ) <EOL> content = json . loads ( get_resp . content ) <EOL> self . assertEqual ( len ( content [ '<STR_LIT>' ] ) , <NUM_LIT:2> ) <EOL> self . client . logout ( ) <EOL> post_stmt = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT:description>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : [ ] } } } <EOL> stmt_json = json . dumps ( post_stmt ) <EOL> post_oauth_header_resource_params , post_access_token = self . oauth_handshake2 ( scope_type = '<STR_LIT>' ) <EOL> post_param_list = post_oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> post_oauth_header_resource_params_dict = { } <EOL> for p in post_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> post_oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del post_oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> post_oauth_request = oauth . Request . from_token_and_callback ( post_access_token , http_method = '<STR_LIT:POST>' , <EOL> http_url = '<STR_LIT>' , <EOL> parameters = post_oauth_header_resource_params_dict ) <EOL> post_signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> post_signature = post_signature_method . sign ( post_oauth_request , self . consumer2 , post_access_token ) <EOL> post_oauth_header_resource_params += '<STR_LIT>' % post_signature <EOL> post = self . client . post ( '<STR_LIT>' , data = stmt_json , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = post_oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( post . status_code , <NUM_LIT:200> ) <EOL> acts = Activity . objects . all ( ) <EOL> self . assertEqual ( len ( acts ) , <NUM_LIT:1> ) <EOL> self . assertNotIn ( "<STR_LIT>" , acts [ <NUM_LIT:0> ] . return_activity_with_lang_format ( ) . keys ( ) ) <EOL> def test_define_scope_agent ( self ) : <EOL> url = '<STR_LIT>' <EOL> guid = str ( uuid . uuid1 ( ) ) <EOL> stmt_data = { "<STR_LIT:id>" : guid , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , "<STR_LIT:object>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" } } <EOL> stmt_post = self . client . post ( reverse ( '<STR_LIT>' ) , json . dumps ( stmt_data ) , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . jane_auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( stmt_post . status_code , <NUM_LIT:200> ) <EOL> put_guid = str ( uuid . uuid1 ( ) ) <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } } ) <EOL> param = { "<STR_LIT>" : put_guid } <EOL> path = "<STR_LIT>" % ( url , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope_type = '<STR_LIT>' ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . put ( path , data = stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> agents = Agent . objects . all ( ) . values_list ( '<STR_LIT:name>' , flat = True ) <EOL> self . assertEqual ( len ( agents ) , <NUM_LIT:7> ) <EOL> self . assertIn ( '<STR_LIT>' , agents ) <EOL> self . assertNotIn ( '<STR_LIT>' , agents ) <EOL> get_params = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , "<STR_LIT>" : True } <EOL> path = "<STR_LIT>" % ( url , urllib . urlencode ( get_params ) ) <EOL> oauth_header_resource_params_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> oauth_request2 = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:GET>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method2 = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature2 = signature_method2 . sign ( oauth_request2 , self . consumer , access_token ) <EOL> sig = oauth_header_resource_params . replace ( '<STR_LIT>' % signature , '<STR_LIT>' % signature2 ) <EOL> new_oauth_headers = sig . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> get_resp = self . client . get ( path , X_Experience_API_Version = settings . XAPI_VERSION , <EOL> Authorization = new_oauth_headers ) <EOL> self . assertEqual ( get_resp . status_code , <NUM_LIT:200> ) <EOL> content = json . loads ( get_resp . content ) <EOL> self . assertEqual ( len ( content [ '<STR_LIT>' ] ) , <NUM_LIT:2> ) <EOL> self . client . logout ( ) <EOL> ot = "<STR_LIT>" <EOL> members = [ { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] <EOL> kwargs = { "<STR_LIT>" : ot , "<STR_LIT>" : members , "<STR_LIT:name>" : "<STR_LIT>" } <EOL> global_group , created = Agent . objects . retrieve_or_create ( ** kwargs ) <EOL> members = [ { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] <EOL> kwargs1 = { "<STR_LIT>" : ot , "<STR_LIT>" : members , "<STR_LIT:name>" : "<STR_LIT>" } <EOL> post_stmt = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : kwargs1 } <EOL> stmt_json = json . dumps ( post_stmt ) <EOL> post_oauth_header_resource_params , post_access_token = self . oauth_handshake2 ( scope_type = '<STR_LIT>' ) <EOL> post_param_list = post_oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> post_oauth_header_resource_params_dict = { } <EOL> for p in post_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> post_oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del post_oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> post_oauth_request = oauth . Request . from_token_and_callback ( post_access_token , http_method = '<STR_LIT:POST>' , <EOL> http_url = '<STR_LIT>' , <EOL> parameters = post_oauth_header_resource_params_dict ) <EOL> post_signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> post_signature = post_signature_method . sign ( post_oauth_request , self . consumer2 , <EOL> post_access_token ) <EOL> post_oauth_header_resource_params += '<STR_LIT>' % post_signature <EOL> post = self . client . post ( '<STR_LIT>' , data = stmt_json , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = post_oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( post . status_code , <NUM_LIT:200> ) <EOL> agents = Agent . objects . all ( ) . values_list ( '<STR_LIT:name>' , flat = True ) <EOL> self . assertEqual ( len ( agents ) , <NUM_LIT:15> ) <EOL> self . assertIn ( '<STR_LIT>' , agents ) <EOL> self . assertNotIn ( '<STR_LIT>' , agents ) <EOL> self . assertIn ( '<STR_LIT>' , agents ) <EOL> self . assertIn ( '<STR_LIT>' , agents ) <EOL> self . assertIn ( '<STR_LIT>' , agents ) <EOL> self . assertIn ( '<STR_LIT>' , agents ) <EOL> self . assertIn ( '<STR_LIT>' , agents ) <EOL> self . assertIn ( '<STR_LIT>' , agents ) <EOL> self . assertIn ( '<STR_LIT>' , agents ) <EOL> self . assertIn ( '<STR_LIT>' , agents ) <EOL> self . assertIn ( '<STR_LIT>' , agents ) <EOL> def test_default_scope_multiple_requests ( self ) : <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope = False ) <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } } ) <EOL> post_param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> post_oauth_header_resource_params_dict = { } <EOL> for p in post_param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> post_oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del post_oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> post_oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:POST>' , <EOL> http_url = TEST_SERVER + '<STR_LIT>' , parameters = post_oauth_header_resource_params_dict ) <EOL> post_signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> post_signature = post_signature_method . sign ( post_oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % post_signature <EOL> post = self . client . post ( TEST_SERVER + '<STR_LIT>' , data = stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( post . status_code , <NUM_LIT:200> ) <EOL> stmt2 = json . dumps ( { "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } } ) <EOL> post_oauth_header_resource_params_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> post_oauth_request2 = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT:POST>' , <EOL> http_url = TEST_SERVER + '<STR_LIT>' , parameters = post_oauth_header_resource_params_dict ) <EOL> post_signature_method2 = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> post_signature2 = post_signature_method2 . sign ( post_oauth_request2 , self . consumer , access_token ) <EOL> sig = oauth_header_resource_params . replace ( '<STR_LIT>' % post_signature , '<STR_LIT>' % post_signature2 ) <EOL> new_oauth_headers = sig . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> resp = self . client . post ( TEST_SERVER + '<STR_LIT>' , data = stmt2 , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = new_oauth_headers , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> def test_update_activity_with_oauth_containing_user ( self ) : <EOL> url = '<STR_LIT>' <EOL> guid = str ( uuid . uuid1 ( ) ) <EOL> stmt_data = { "<STR_LIT:id>" : guid , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } } <EOL> stmt_post = self . client . post ( reverse ( '<STR_LIT>' ) , json . dumps ( stmt_data ) , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . jane_auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( stmt_post . status_code , <NUM_LIT:200> ) <EOL> put_guid = str ( uuid . uuid1 ( ) ) <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT:description>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : [ ] } } } ) <EOL> param = { "<STR_LIT>" : put_guid } <EOL> path = "<STR_LIT>" % ( url , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope_type = '<STR_LIT>' ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . put ( path , data = stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> acts = Activity . objects . all ( ) <EOL> self . assertEqual ( len ( acts ) , <NUM_LIT:1> ) <EOL> act = acts [ <NUM_LIT:0> ] . return_activity_with_lang_format ( ) <EOL> self . assertEqual ( act [ '<STR_LIT:id>' ] , '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , act ) <EOL> def test_update_activity_created_with_oauth ( self ) : <EOL> url = '<STR_LIT>' <EOL> put_guid = str ( uuid . uuid1 ( ) ) <EOL> stmt = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } } <EOL> param = { "<STR_LIT>" : put_guid } <EOL> path = "<STR_LIT>" % ( url , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope_type = '<STR_LIT>' ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . put ( path , data = stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT:description>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : [ ] } } } ) <EOL> stmt_post = self . client . post ( reverse ( '<STR_LIT>' ) , stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . jane_auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( stmt_post . status_code , <NUM_LIT:200> ) <EOL> acts = Activity . objects . all ( ) <EOL> self . assertEqual ( len ( acts ) , <NUM_LIT:1> ) <EOL> act = acts [ <NUM_LIT:0> ] . return_activity_with_lang_format ( ) <EOL> self . assertEqual ( act [ '<STR_LIT:id>' ] , '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , act ) <EOL> def test_multiple_client_get ( self ) : <EOL> url = '<STR_LIT>' <EOL> put_guid = str ( uuid . uuid1 ( ) ) <EOL> stmt = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } } <EOL> param = { "<STR_LIT>" : put_guid } <EOL> path = "<STR_LIT>" % ( url , urllib . urlencode ( param ) ) <EOL> oauth_header_resource_params , access_token = self . oauth_handshake ( scope_type = '<STR_LIT>' ) <EOL> param_list = oauth_header_resource_params . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict = { } <EOL> for p in param_list : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict [ '<STR_LIT>' ] <EOL> oauth_request = oauth . Request . from_token_and_callback ( access_token , http_method = '<STR_LIT>' , <EOL> http_url = path , parameters = oauth_header_resource_params_dict ) <EOL> signature_method = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature = signature_method . sign ( oauth_request , self . consumer , access_token ) <EOL> oauth_header_resource_params += '<STR_LIT>' % signature <EOL> resp = self . client . put ( path , data = stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> put_guid2 = str ( uuid . uuid1 ( ) ) <EOL> stmt2 = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" } } <EOL> param2 = { "<STR_LIT>" : put_guid2 } <EOL> path2 = "<STR_LIT>" % ( url , urllib . urlencode ( param2 ) ) <EOL> oauth_header_resource_params2 , access_token2 = self . oauth_handshake ( scope_type = '<STR_LIT>' , consumer = self . consumer2jane ) <EOL> param_list2 = oauth_header_resource_params2 . split ( "<STR_LIT:U+002C>" ) <EOL> oauth_header_resource_params_dict2 = { } <EOL> for p in param_list2 : <EOL> item = p . split ( "<STR_LIT:=>" ) <EOL> oauth_header_resource_params_dict2 [ str ( item [ <NUM_LIT:0> ] ) . strip ( ) ] = str ( item [ <NUM_LIT:1> ] ) . strip ( '<STR_LIT:">' ) <EOL> del oauth_header_resource_params_dict2 [ '<STR_LIT>' ] <EOL> oauth_request2 = oauth . Request . from_token_and_callback ( access_token2 , http_method = '<STR_LIT>' , <EOL> http_url = path2 , parameters = oauth_header_resource_params_dict2 ) <EOL> signature_method2 = oauth . SignatureMethod_HMAC_SHA1 ( ) <EOL> signature2 = signature_method2 . sign ( oauth_request2 , self . consumer2jane , access_token2 ) <EOL> oauth_header_resource_params2 += '<STR_LIT>' % signature2 <EOL> resp2 = self . client . put ( path2 , data = stmt2 , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = oauth_header_resource_params2 , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( resp2 . status_code , <NUM_LIT> ) <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT:object>" : { "<STR_LIT:id>" : "<STR_LIT>" , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT:description>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : [ ] } } } ) <EOL> stmt_post = self . client . post ( reverse ( '<STR_LIT>' ) , stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . jane_auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( stmt_post . status_code , <NUM_LIT:200> ) <EOL> stmt_get = self . client . get ( reverse ( '<STR_LIT>' ) , X_Experience_API_Version = settings . XAPI_VERSION , Authorization = self . jane_auth ) <EOL> self . assertEqual ( stmt_get . status_code , <NUM_LIT:200> ) <EOL> content = json . loads ( stmt_get . content ) <EOL> self . assertEqual ( len ( content [ '<STR_LIT>' ] ) , <NUM_LIT:3> ) <EOL> jane_clients = Consumer . objects . filter ( user = self . user ) <EOL> self . assertEqual ( len ( jane_clients ) , <NUM_LIT:2> ) </s>
