<s> import hashlib <EOL> import urllib <EOL> import base64 <EOL> import json <EOL> import ast <EOL> from django . test import TestCase <EOL> from django . conf import settings <EOL> from django . core . urlresolvers import reverse <EOL> from adl_lrs . views import register <EOL> class AgentProfileTests ( TestCase ) : <EOL> testagent = '<STR_LIT>' <EOL> otheragent = '<STR_LIT>' <EOL> content_type = "<STR_LIT:application/json>" <EOL> testprofileId1 = "<STR_LIT>" <EOL> testprofileId2 = "<STR_LIT>" <EOL> testprofileId3 = "<STR_LIT>" <EOL> otherprofileId1 = "<STR_LIT>" <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> print "<STR_LIT>" % __name__ <EOL> super ( AgentProfileTests , cls ) . setUpClass ( ) <EOL> def setUp ( self ) : <EOL> self . username = "<STR_LIT>" <EOL> self . email = "<STR_LIT>" <EOL> self . password = "<STR_LIT:test>" <EOL> self . auth = "<STR_LIT>" % base64 . b64encode ( "<STR_LIT>" % ( self . username , self . password ) ) <EOL> form = { '<STR_LIT:username>' : self . username , '<STR_LIT:email>' : self . email , '<STR_LIT:password>' : self . password , '<STR_LIT>' : self . password } <EOL> self . client . post ( reverse ( register ) , form , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . testparams1 = { "<STR_LIT>" : self . testprofileId1 , "<STR_LIT>" : self . testagent } <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( self . testparams1 ) ) <EOL> self . testprofile1 = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:test>" } } <EOL> self . put1 = self . client . put ( path , self . testprofile1 , content_type = self . content_type , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . testparams2 = { "<STR_LIT>" : self . testprofileId2 , "<STR_LIT>" : self . testagent } <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( self . testparams2 ) ) <EOL> self . testprofile2 = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:test>" } } <EOL> self . put2 = self . client . put ( path , self . testprofile2 , content_type = self . content_type , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . testparams3 = { "<STR_LIT>" : self . testprofileId3 , "<STR_LIT>" : self . testagent } <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( self . testparams3 ) ) <EOL> self . testprofile3 = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:test>" } } <EOL> self . put3 = self . client . put ( path , self . testprofile3 , content_type = self . content_type , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . testparams4 = { "<STR_LIT>" : self . otherprofileId1 , "<STR_LIT>" : self . otheragent } <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( self . testparams4 ) ) <EOL> self . otherprofile1 = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } <EOL> self . put4 = self . client . put ( path , self . otherprofile1 , content_type = self . content_type , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> def tearDown ( self ) : <EOL> self . client . delete ( reverse ( '<STR_LIT>' ) , self . testparams1 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . client . delete ( reverse ( '<STR_LIT>' ) , self . testparams2 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . client . delete ( reverse ( '<STR_LIT>' ) , self . testparams3 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . client . delete ( reverse ( '<STR_LIT>' ) , self . testparams4 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> def test_get_agent_not_found ( self ) : <EOL> a = '<STR_LIT>' <EOL> p = '<STR_LIT>' <EOL> param = { "<STR_LIT>" : p , "<STR_LIT>" : a } <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , param , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> def test_put ( self ) : <EOL> self . assertEqual ( self . put1 . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( self . put1 . content , '<STR_LIT>' ) <EOL> self . assertEqual ( self . put2 . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( self . put2 . content , '<STR_LIT>' ) <EOL> self . assertEqual ( self . put3 . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( self . put3 . content , '<STR_LIT>' ) <EOL> self . assertEqual ( self . put4 . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( self . put4 . content , '<STR_LIT>' ) <EOL> def test_put_etag_missing_on_change ( self ) : <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( self . testparams1 ) ) <EOL> profile = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:test>" } } <EOL> response = self . client . put ( path , profile , content_type = self . content_type , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , response . content ) <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , self . testparams1 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> robj = ast . literal_eval ( r . content ) <EOL> self . assertEqual ( robj [ '<STR_LIT:test>' ] , self . testprofile1 [ '<STR_LIT:test>' ] ) <EOL> self . assertEqual ( robj [ '<STR_LIT>' ] [ '<STR_LIT>' ] , self . testprofile1 [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_put_etag_right_on_change ( self ) : <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( self . testparams1 ) ) <EOL> profile = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:test>" } } <EOL> thehash = '<STR_LIT>' % hashlib . sha1 ( '<STR_LIT:%s>' % self . testprofile1 ) . hexdigest ( ) <EOL> response = self . client . put ( path , profile , content_type = self . content_type , If_Match = thehash , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( response . content , '<STR_LIT>' ) <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , self . testparams1 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> robj = ast . literal_eval ( r . content ) <EOL> self . assertEqual ( robj [ '<STR_LIT:test>' ] , profile [ '<STR_LIT:test>' ] ) <EOL> self . assertEqual ( robj [ '<STR_LIT>' ] [ '<STR_LIT>' ] , profile [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_put_etag_wrong_on_change ( self ) : <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( self . testparams1 ) ) <EOL> profile = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:test>" } } <EOL> thehash = '<STR_LIT>' % hashlib . sha1 ( '<STR_LIT:%s>' % '<STR_LIT>' ) . hexdigest ( ) <EOL> response = self . client . put ( path , profile , content_type = self . content_type , If_Match = thehash , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , response . content ) <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , self . testparams1 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> robj = ast . literal_eval ( r . content ) <EOL> self . assertEqual ( robj [ '<STR_LIT:test>' ] , self . testprofile1 [ '<STR_LIT:test>' ] ) <EOL> self . assertEqual ( robj [ '<STR_LIT>' ] [ '<STR_LIT>' ] , self . testprofile1 [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_put_etag_if_none_match_good ( self ) : <EOL> params = { "<STR_LIT>" : '<STR_LIT>' , "<STR_LIT>" : self . testagent } <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( params ) ) <EOL> profile = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:test>" } } <EOL> response = self . client . put ( path , profile , content_type = self . content_type , If_None_Match = '<STR_LIT:*>' , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( response . content , '<STR_LIT>' ) <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , params , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> robj = ast . literal_eval ( r . content ) <EOL> self . assertEqual ( robj [ '<STR_LIT:test>' ] , profile [ '<STR_LIT:test>' ] ) <EOL> self . assertEqual ( robj [ '<STR_LIT>' ] [ '<STR_LIT>' ] , profile [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> r = self . client . delete ( reverse ( '<STR_LIT>' ) , params , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> def test_put_etag_if_none_match_bad ( self ) : <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( self . testparams1 ) ) <EOL> profile = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:test>" } } <EOL> response = self . client . put ( path , profile , content_type = self . content_type , If_None_Match = '<STR_LIT:*>' , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( response . content , '<STR_LIT>' ) <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , self . testparams1 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> robj = ast . literal_eval ( r . content ) <EOL> self . assertEqual ( robj [ '<STR_LIT:test>' ] , self . testprofile1 [ '<STR_LIT:test>' ] ) <EOL> self . assertEqual ( robj [ '<STR_LIT>' ] [ '<STR_LIT>' ] , self . testprofile1 [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_get_invalid_agent_structure ( self ) : <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , { "<STR_LIT>" : self . testprofileId1 , "<STR_LIT>" : "<STR_LIT>" } , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( r . content , "<STR_LIT>" ) <EOL> def test_get_invalid_agent ( self ) : <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , { "<STR_LIT>" : self . testprofileId1 , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:foo>" } } , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( r . content , "<STR_LIT>" ) <EOL> def test_get ( self ) : <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , self . testparams1 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> robj = ast . literal_eval ( r . content ) <EOL> self . assertEqual ( robj [ '<STR_LIT:test>' ] , self . testprofile1 [ '<STR_LIT:test>' ] ) <EOL> self . assertEqual ( robj [ '<STR_LIT>' ] [ '<STR_LIT>' ] , self . testprofile1 [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( r [ '<STR_LIT>' ] , '<STR_LIT>' % hashlib . sha1 ( '<STR_LIT:%s>' % self . testprofile1 ) . hexdigest ( ) ) <EOL> r2 = self . client . get ( reverse ( '<STR_LIT>' ) , self . testparams2 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r2 . status_code , <NUM_LIT:200> ) <EOL> robj2 = ast . literal_eval ( r2 . content ) <EOL> self . assertEqual ( robj2 [ '<STR_LIT:test>' ] , self . testprofile2 [ '<STR_LIT:test>' ] ) <EOL> self . assertEqual ( robj2 [ '<STR_LIT>' ] [ '<STR_LIT>' ] , self . testprofile2 [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( r2 [ '<STR_LIT>' ] , '<STR_LIT>' % hashlib . sha1 ( '<STR_LIT:%s>' % self . testprofile2 ) . hexdigest ( ) ) <EOL> r3 = self . client . get ( reverse ( '<STR_LIT>' ) , self . testparams3 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r3 . status_code , <NUM_LIT:200> ) <EOL> robj3 = ast . literal_eval ( r3 . content ) <EOL> self . assertEqual ( robj3 [ '<STR_LIT:test>' ] , self . testprofile3 [ '<STR_LIT:test>' ] ) <EOL> self . assertEqual ( robj3 [ '<STR_LIT>' ] [ '<STR_LIT>' ] , self . testprofile3 [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( r3 [ '<STR_LIT>' ] , '<STR_LIT>' % hashlib . sha1 ( '<STR_LIT:%s>' % self . testprofile3 ) . hexdigest ( ) ) <EOL> r4 = self . client . get ( reverse ( '<STR_LIT>' ) , self . testparams4 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r4 . status_code , <NUM_LIT:200> ) <EOL> robj4 = ast . literal_eval ( r4 . content ) <EOL> self . assertEqual ( robj4 [ '<STR_LIT:test>' ] , self . otherprofile1 [ '<STR_LIT:test>' ] ) <EOL> self . assertEqual ( robj4 [ '<STR_LIT>' ] [ '<STR_LIT>' ] , self . otherprofile1 [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( r4 [ '<STR_LIT>' ] , '<STR_LIT>' % hashlib . sha1 ( '<STR_LIT:%s>' % self . otherprofile1 ) . hexdigest ( ) ) <EOL> def test_get_no_params ( self ) : <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , r . content ) <EOL> def test_get_no_agent ( self ) : <EOL> params = { "<STR_LIT>" : self . testprofileId1 } <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , params , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , r . content ) <EOL> def test_get_no_profileId ( self ) : <EOL> params = { "<STR_LIT>" : self . testagent } <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , params , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> def test_delete ( self ) : <EOL> prof_id = "<STR_LIT>" <EOL> params = { "<STR_LIT>" : prof_id , "<STR_LIT>" : self . testagent } <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( params ) ) <EOL> profile = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:test>" } } <EOL> response = self . client . put ( path , profile , content_type = self . content_type , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , params , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> robj = ast . literal_eval ( r . content ) <EOL> self . assertEqual ( robj [ '<STR_LIT:test>' ] , profile [ '<STR_LIT:test>' ] ) <EOL> self . assertEqual ( robj [ '<STR_LIT>' ] [ '<STR_LIT>' ] , profile [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> r = self . client . delete ( reverse ( '<STR_LIT>' ) , params , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , params , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> def test_get_agent_since ( self ) : <EOL> prof_id = "<STR_LIT>" <EOL> updated = "<STR_LIT>" <EOL> params = { "<STR_LIT>" : prof_id , "<STR_LIT>" : self . testagent } <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( params ) ) <EOL> profile = { "<STR_LIT>" : "<STR_LIT>" % updated , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:test>" } } <EOL> response = self . client . put ( path , profile , content_type = self . content_type , updated = updated , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , params , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> robj = ast . literal_eval ( r . content ) <EOL> self . assertEqual ( robj [ '<STR_LIT>' ] , profile [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( robj [ '<STR_LIT>' ] [ '<STR_LIT>' ] , profile [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> since = "<STR_LIT>" <EOL> params2 = { "<STR_LIT>" : self . testagent , "<STR_LIT>" : since } <EOL> r2 = self . client . get ( reverse ( '<STR_LIT>' ) , params2 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertNotIn ( prof_id , r2 . content ) <EOL> self . client . delete ( reverse ( '<STR_LIT>' ) , params , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> def test_get_agent_since_tz ( self ) : <EOL> prof_id = "<STR_LIT>" <EOL> updated = "<STR_LIT>" <EOL> params = { "<STR_LIT>" : prof_id , "<STR_LIT>" : self . testagent } <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( params ) ) <EOL> profile = { "<STR_LIT>" : "<STR_LIT>" % updated , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:test>" } } <EOL> response = self . client . put ( path , profile , content_type = self . content_type , updated = updated , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , params , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> robj = ast . literal_eval ( r . content ) <EOL> self . assertEqual ( robj [ '<STR_LIT>' ] , profile [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( robj [ '<STR_LIT>' ] [ '<STR_LIT>' ] , profile [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> prof_id2 = "<STR_LIT>" <EOL> updated2 = "<STR_LIT>" <EOL> params2 = { "<STR_LIT>" : prof_id2 , "<STR_LIT>" : self . testagent } <EOL> path2 = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( params2 ) ) <EOL> profile2 = { "<STR_LIT>" : "<STR_LIT>" % updated2 , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:test>" } } <EOL> response = self . client . put ( path2 , profile2 , content_type = self . content_type , updated = updated2 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> r2 = self . client . get ( reverse ( '<STR_LIT>' ) , params2 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r2 . status_code , <NUM_LIT:200> ) <EOL> robj2 = ast . literal_eval ( r2 . content ) <EOL> self . assertEqual ( robj2 [ '<STR_LIT>' ] , profile2 [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( robj2 [ '<STR_LIT>' ] [ '<STR_LIT>' ] , profile2 [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> since = "<STR_LIT>" <EOL> par = { "<STR_LIT>" : self . testagent , "<STR_LIT>" : since } <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , par , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertNotIn ( prof_id , r . content ) <EOL> self . assertIn ( prof_id2 , r . content ) <EOL> self . client . delete ( reverse ( '<STR_LIT>' ) , params , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . client . delete ( reverse ( '<STR_LIT>' ) , params2 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> def test_post_put_delete ( self ) : <EOL> prof_id = "<STR_LIT>" <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( { "<STR_LIT>" : "<STR_LIT>" } ) ) <EOL> content = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:test>" , "<STR_LIT>" : "<STR_LIT>" } } <EOL> thedata = "<STR_LIT>" % ( prof_id , self . testagent , content , self . auth ) <EOL> response = self . client . post ( path , thedata , content_type = "<STR_LIT>" ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , { "<STR_LIT>" : prof_id , "<STR_LIT>" : self . testagent } , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> import ast <EOL> c = ast . literal_eval ( r . content ) <EOL> self . assertEqual ( c [ '<STR_LIT:test>' ] , content [ '<STR_LIT:test>' ] ) <EOL> thedata = "<STR_LIT>" % ( prof_id , self . testagent , self . auth ) <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( { "<STR_LIT>" : "<STR_LIT>" } ) ) <EOL> r = self . client . post ( path , thedata , content_type = "<STR_LIT>" , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> r = self . client . get ( reverse ( '<STR_LIT>' ) , { "<STR_LIT>" : prof_id , "<STR_LIT>" : self . testagent } , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> def test_group_as_agent ( self ) : <EOL> ot = "<STR_LIT>" <EOL> name = "<STR_LIT>" <EOL> mbox = "<STR_LIT>" <EOL> members = [ { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] <EOL> testagent = json . dumps ( { "<STR_LIT>" : ot , "<STR_LIT:name>" : name , "<STR_LIT>" : mbox , "<STR_LIT>" : members } ) <EOL> testprofileId = "<STR_LIT>" <EOL> testparams1 = { "<STR_LIT>" : testprofileId , "<STR_LIT>" : testagent } <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( testparams1 ) ) <EOL> testprofile = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } <EOL> put1 = self . client . put ( path , testprofile , content_type = self . content_type , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( put1 . status_code , <NUM_LIT> ) <EOL> getr = self . client . get ( reverse ( '<STR_LIT>' ) , testparams1 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( getr . status_code , <NUM_LIT:200> ) <EOL> robj = ast . literal_eval ( getr . content ) <EOL> self . assertEqual ( robj [ '<STR_LIT:test>' ] , testprofile [ '<STR_LIT:test>' ] ) <EOL> self . assertEqual ( robj [ '<STR_LIT>' ] [ '<STR_LIT>' ] , testprofile [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . client . delete ( reverse ( '<STR_LIT>' ) , testparams1 , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> def test_post_new_profile ( self ) : <EOL> params = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . testagent } <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( params ) ) <EOL> prof = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } <EOL> post = self . client . post ( path , prof , content_type = "<STR_LIT:application/json>" , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( post . status_code , <NUM_LIT> ) <EOL> get = self . client . get ( path , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( get . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( ast . literal_eval ( get . content ) , prof ) <EOL> self . assertEqual ( get . get ( '<STR_LIT>' ) , '<STR_LIT>' % hashlib . sha1 ( get . content ) . hexdigest ( ) ) <EOL> self . client . delete ( path , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> def test_post_blank_profile ( self ) : <EOL> params = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . testagent } <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( params ) ) <EOL> prof = "<STR_LIT>" <EOL> post = self . client . post ( path , prof , content_type = "<STR_LIT:application/json>" , Authorization = self . auth , 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_post_and_put_profile ( self ) : <EOL> params = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . testagent } <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( params ) ) <EOL> prof = { "<STR_LIT:test>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } <EOL> post = self . client . post ( path , json . dumps ( prof ) , content_type = "<STR_LIT:application/json>" , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( post . status_code , <NUM_LIT> ) <EOL> get = self . client . get ( path , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( get . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( json . loads ( get . content ) , prof ) <EOL> self . assertEqual ( get . get ( '<STR_LIT>' ) , '<STR_LIT>' % hashlib . sha1 ( get . content ) . hexdigest ( ) ) <EOL> params = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : self . testagent } <EOL> path = '<STR_LIT>' % ( reverse ( '<STR_LIT>' ) , urllib . urlencode ( params ) ) <EOL> prof = { "<STR_LIT>" : "<STR_LIT>" } <EOL> thehash = get . get ( '<STR_LIT>' ) <EOL> put = self . client . put ( path , json . dumps ( prof ) , content_type = "<STR_LIT:application/json>" , If_Match = thehash , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( put . status_code , <NUM_LIT> ) <EOL> get = self . client . get ( path , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( get . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( json . loads ( get . content ) , prof ) <EOL> etag = '<STR_LIT>' % hashlib . sha1 ( get . content ) . hexdigest ( ) <EOL> self . assertEqual ( get . get ( '<STR_LIT>' ) , etag ) <EOL> self . client . delete ( path , Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) </s>
