<s> import hashlib <EOL> import json <EOL> import base64 <EOL> from django . test import TestCase <EOL> from django . core . urlresolvers import reverse <EOL> from django . conf import settings <EOL> from . . models import Agent , Statement <EOL> from adl_lrs . views import register <EOL> class AgentManagerTests ( TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> print "<STR_LIT>" % __name__ <EOL> super ( AgentManagerTests , 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> def test_agent_mbox_create ( self ) : <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" } , <EOL> "<STR_LIT:object>" : { '<STR_LIT:id>' : '<STR_LIT>' } } ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> st_id = json . loads ( response . content ) <EOL> st = Statement . objects . get ( statement_id = st_id [ <NUM_LIT:0> ] ) <EOL> bob = st . actor <EOL> self . assertEquals ( bob . objectType , "<STR_LIT>" ) <EOL> self . assertFalse ( bob . name ) <EOL> def test_agent_mbox_sha1sum_create ( self ) : <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : hashlib . sha1 ( "<STR_LIT>" ) . hexdigest ( ) } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" } , <EOL> "<STR_LIT:object>" : { '<STR_LIT:id>' : '<STR_LIT>' } } ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> st_id = json . loads ( response . content ) <EOL> st = Statement . objects . get ( statement_id = st_id [ <NUM_LIT:0> ] ) <EOL> bob = st . actor <EOL> self . assertEquals ( bob . mbox_sha1sum , hashlib . sha1 ( "<STR_LIT>" ) . hexdigest ( ) ) <EOL> self . assertEquals ( bob . objectType , "<STR_LIT>" ) <EOL> self . assertFalse ( bob . name ) <EOL> self . assertFalse ( bob . mbox ) <EOL> def test_agent_bogus_mbox_sha1sum_create ( self ) : <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" } , <EOL> "<STR_LIT:object>" : { '<STR_LIT:id>' : '<STR_LIT>' } } ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , stmt , content_type = "<STR_LIT:application/json>" , <EOL> 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> def test_agent_openID_create ( self ) : <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" } , <EOL> "<STR_LIT:object>" : { '<STR_LIT:id>' : '<STR_LIT>' } } ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> st_id = json . loads ( response . content ) <EOL> st = Statement . objects . get ( statement_id = st_id [ <NUM_LIT:0> ] ) <EOL> bob = st . actor <EOL> self . assertEquals ( bob . openid , "<STR_LIT>" ) <EOL> self . assertEquals ( bob . objectType , "<STR_LIT>" ) <EOL> self . assertFalse ( bob . name ) <EOL> self . assertFalse ( bob . mbox ) <EOL> self . assertFalse ( bob . mbox_sha1sum ) <EOL> def test_agent_account_create ( self ) : <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" } , <EOL> "<STR_LIT:object>" : { '<STR_LIT:id>' : '<STR_LIT>' } } ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , stmt , content_type = "<STR_LIT:application/json>" , <EOL> Authorization = self . auth , X_Experience_API_Version = settings . XAPI_VERSION ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> st_id = json . loads ( response . content ) <EOL> st = Statement . objects . get ( statement_id = st_id [ <NUM_LIT:0> ] ) <EOL> bob = st . actor <EOL> self . assertEquals ( bob . account_name , "<STR_LIT>" ) <EOL> self . assertEquals ( bob . account_homePage , "<STR_LIT>" ) <EOL> self . assertFalse ( bob . name ) <EOL> self . assertFalse ( bob . mbox ) <EOL> self . assertFalse ( bob . mbox_sha1sum ) <EOL> self . assertFalse ( bob . openid ) <EOL> def test_agent_kwargs_basic ( self ) : <EOL> ot = "<STR_LIT>" <EOL> name = "<STR_LIT>" <EOL> mbox = "<STR_LIT>" <EOL> kwargs = { "<STR_LIT>" : ot , "<STR_LIT:name>" : name , "<STR_LIT>" : mbox } <EOL> bob , created = Agent . objects . retrieve_or_create ( ** kwargs ) <EOL> self . assertTrue ( created ) <EOL> bob . save ( ) <EOL> self . assertEquals ( bob . objectType , ot ) <EOL> self . assertEquals ( bob . name , name ) <EOL> self . assertEquals ( bob . mbox , mbox ) <EOL> bob2 , created = Agent . objects . retrieve_or_create ( ** kwargs ) <EOL> self . assertFalse ( created ) <EOL> self . assertEquals ( bob . pk , bob2 . pk ) <EOL> self . assertEquals ( bob , bob2 ) <EOL> kwargs [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> bob3 , created = Agent . objects . retrieve_or_create ( ** kwargs ) <EOL> self . assertTrue ( created ) <EOL> bob3 . save ( ) <EOL> self . assertNotEqual ( bob . pk , bob3 . pk ) <EOL> def test_agent_kwargs_basic_account ( self ) : <EOL> ot = "<STR_LIT>" <EOL> name = "<STR_LIT>" <EOL> account = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } <EOL> kwargs = { "<STR_LIT>" : ot , "<STR_LIT:name>" : name , "<STR_LIT>" : account } <EOL> bob , created = Agent . objects . retrieve_or_create ( ** kwargs ) <EOL> self . assertTrue ( created ) <EOL> self . assertEquals ( bob . objectType , ot ) <EOL> self . assertEquals ( bob . name , name ) <EOL> self . assertEquals ( bob . account_homePage , "<STR_LIT>" ) <EOL> self . assertEquals ( bob . account_name , "<STR_LIT>" ) <EOL> def test_group_kwargs ( self ) : <EOL> ot = "<STR_LIT>" <EOL> name = "<STR_LIT>" <EOL> kwargs = { "<STR_LIT>" : ot , "<STR_LIT:name>" : name , "<STR_LIT>" : "<STR_LIT>" } <EOL> bob , created = Agent . objects . retrieve_or_create ( ** kwargs ) <EOL> ot = "<STR_LIT>" <EOL> name = "<STR_LIT>" <EOL> kwargs = { "<STR_LIT>" : ot , "<STR_LIT:name>" : name , "<STR_LIT>" : "<STR_LIT>" } <EOL> john , created = Agent . objects . retrieve_or_create ( ** kwargs ) <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 } <EOL> gr , created = Agent . objects . retrieve_or_create ( ** kwargs ) <EOL> self . assertTrue ( created ) <EOL> kwargs1 = { "<STR_LIT>" : ot , "<STR_LIT>" : members , "<STR_LIT:name>" : "<STR_LIT>" } <EOL> gr1 , created = Agent . objects . retrieve_or_create ( ** kwargs1 ) <EOL> self . assertTrue ( created ) <EOL> self . assertEquals ( gr1 . name , "<STR_LIT>" ) <EOL> agents = Agent . objects . all ( ) <EOL> self . assertEquals ( len ( agents ) , <NUM_LIT:5> ) <EOL> self . assertEquals ( len ( agents . filter ( objectType = '<STR_LIT>' ) ) , <NUM_LIT:2> ) <EOL> self . assertEquals ( len ( agents . filter ( objectType = '<STR_LIT>' ) ) , <NUM_LIT:3> ) <EOL> def test_agent_json_no_ids ( self ) : <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" } , <EOL> "<STR_LIT:object>" : { '<STR_LIT:id>' : '<STR_LIT>' } } ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , stmt , content_type = "<STR_LIT:application/json>" , <EOL> 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> def test_agent_json_many_ids ( self ) : <EOL> stmt = json . dumps ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" } , <EOL> "<STR_LIT:object>" : { '<STR_LIT:id>' : '<STR_LIT>' } } ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , stmt , content_type = "<STR_LIT:application/json>" , <EOL> 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> def test_group ( 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> kwargs = { "<STR_LIT>" : ot , "<STR_LIT:name>" : name , "<STR_LIT>" : mbox , "<STR_LIT>" : members } <EOL> g , created = Agent . objects . retrieve_or_create ( ** kwargs ) <EOL> self . assertTrue ( created ) <EOL> self . assertEquals ( g . name , name ) <EOL> self . assertEquals ( g . mbox , mbox ) <EOL> mems = g . member . values_list ( '<STR_LIT:name>' , flat = True ) <EOL> self . assertEquals ( len ( mems ) , <NUM_LIT:2> ) <EOL> self . assertIn ( '<STR_LIT>' , mems ) <EOL> self . assertIn ( '<STR_LIT>' , mems ) <EOL> gr_dict = g . to_dict ( ) <EOL> self . assertEquals ( gr_dict [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> for member in gr_dict [ '<STR_LIT>' ] : <EOL> self . assertEquals ( member [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> if member [ '<STR_LIT:name>' ] == '<STR_LIT>' : <EOL> self . assertEquals ( member [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> elif member [ '<STR_LIT:name>' ] == '<STR_LIT>' : <EOL> self . assertEquals ( member [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_group_from_agent_object ( 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> kwargs = { "<STR_LIT>" : ot , "<STR_LIT:name>" : name , "<STR_LIT>" : mbox , "<STR_LIT>" : members } <EOL> g = Agent . objects . retrieve_or_create ( ** kwargs ) [ <NUM_LIT:0> ] <EOL> self . assertEquals ( g . name , name ) <EOL> self . assertEquals ( g . mbox , mbox ) <EOL> mems = g . member . values_list ( '<STR_LIT:name>' , flat = True ) <EOL> self . assertEquals ( len ( mems ) , <NUM_LIT:2> ) <EOL> self . assertIn ( '<STR_LIT>' , mems ) <EOL> self . assertIn ( '<STR_LIT>' , mems ) <EOL> def test_group_from_agent_string ( 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> kwargs = { "<STR_LIT>" : ot , "<STR_LIT:name>" : name , "<STR_LIT>" : mbox , "<STR_LIT>" : members } <EOL> g = Agent . objects . retrieve_or_create ( ** kwargs ) [ <NUM_LIT:0> ] <EOL> self . assertEquals ( g . name , name ) <EOL> self . assertEquals ( g . mbox , mbox ) <EOL> mems = g . member . values_list ( '<STR_LIT:name>' , flat = True ) <EOL> self . assertEquals ( len ( mems ) , <NUM_LIT:2> ) <EOL> self . assertIn ( '<STR_LIT>' , mems ) <EOL> self . assertIn ( '<STR_LIT>' , mems ) <EOL> def test_agent_format ( self ) : <EOL> ot_s = "<STR_LIT>" <EOL> name_s = "<STR_LIT>" <EOL> mbox_s = "<STR_LIT>" <EOL> kwargs_s = { "<STR_LIT>" : ot_s , "<STR_LIT:name>" : name_s , "<STR_LIT>" : mbox_s } <EOL> clark , created = Agent . objects . retrieve_or_create ( ** kwargs_s ) <EOL> self . assertTrue ( created ) <EOL> clark . save ( ) <EOL> self . assertEquals ( clark . objectType , ot_s ) <EOL> self . assertEquals ( clark . name , name_s ) <EOL> self . assertEquals ( clark . mbox , mbox_s ) <EOL> clark_exact = clark . to_dict ( ) <EOL> self . assertEquals ( clark_exact [ '<STR_LIT>' ] , ot_s ) <EOL> self . assertEquals ( clark_exact [ '<STR_LIT:name>' ] , name_s ) <EOL> self . assertEquals ( clark_exact [ '<STR_LIT>' ] , mbox_s ) <EOL> clark_ids = clark . to_dict ( ids_only = True ) <EOL> self . assertFalse ( '<STR_LIT>' in str ( clark_ids ) , "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT:name>' in str ( clark_ids ) , "<STR_LIT>" ) <EOL> self . assertEquals ( clark_ids [ '<STR_LIT>' ] , mbox_s ) <EOL> ot_ww = "<STR_LIT>" <EOL> name_ww = "<STR_LIT>" <EOL> mbox_sha1sum_ww = hashlib . sha1 ( "<STR_LIT>" ) . hexdigest ( ) <EOL> kwargs_ww = { "<STR_LIT>" : ot_ww , "<STR_LIT:name>" : name_ww , "<STR_LIT>" : mbox_sha1sum_ww } <EOL> diana , created = Agent . objects . retrieve_or_create ( ** kwargs_ww ) <EOL> self . assertTrue ( created ) <EOL> diana . save ( ) <EOL> self . assertEquals ( diana . objectType , ot_ww ) <EOL> self . assertEquals ( diana . name , name_ww ) <EOL> self . assertEquals ( diana . mbox_sha1sum , mbox_sha1sum_ww ) <EOL> diana_exact = diana . to_dict ( ) <EOL> self . assertEquals ( diana_exact [ '<STR_LIT>' ] , ot_ww ) <EOL> self . assertEquals ( diana_exact [ '<STR_LIT:name>' ] , name_ww ) <EOL> self . assertEquals ( diana_exact [ '<STR_LIT>' ] , mbox_sha1sum_ww ) <EOL> diana_ids = diana . to_dict ( ids_only = True ) <EOL> self . assertFalse ( '<STR_LIT>' in str ( diana_ids ) , "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT:name>' in str ( diana_ids ) , "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT>' in diana_ids . items ( ) , "<STR_LIT>" ) <EOL> self . assertEquals ( diana_ids [ '<STR_LIT>' ] , mbox_sha1sum_ww ) <EOL> ot_b = "<STR_LIT>" <EOL> name_b = "<STR_LIT>" <EOL> openid_b = "<STR_LIT>" <EOL> kwargs_b = { "<STR_LIT>" : ot_b , "<STR_LIT:name>" : name_b , "<STR_LIT>" : openid_b } <EOL> bruce , created = Agent . objects . retrieve_or_create ( ** kwargs_b ) <EOL> self . assertTrue ( created ) <EOL> bruce . save ( ) <EOL> self . assertEquals ( bruce . objectType , ot_b ) <EOL> self . assertEquals ( bruce . name , name_b ) <EOL> self . assertEquals ( bruce . openid , openid_b ) <EOL> bruce_exact = bruce . to_dict ( ) <EOL> self . assertEquals ( bruce_exact [ '<STR_LIT>' ] , ot_b ) <EOL> self . assertEquals ( bruce_exact [ '<STR_LIT:name>' ] , name_b ) <EOL> self . assertEquals ( bruce_exact [ '<STR_LIT>' ] , openid_b ) <EOL> bruce_ids = bruce . to_dict ( ids_only = True ) <EOL> self . assertFalse ( '<STR_LIT>' in str ( bruce_ids ) , "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT:name>' in str ( bruce_ids ) , "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT>' in str ( bruce_ids ) , "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT>' in str ( bruce_ids ) , "<STR_LIT>" ) <EOL> self . assertEquals ( bruce_ids [ '<STR_LIT>' ] , openid_b ) <EOL> ot_f = "<STR_LIT>" <EOL> name_f = "<STR_LIT>" <EOL> account_f = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } <EOL> kwargs_f = { "<STR_LIT>" : ot_f , "<STR_LIT:name>" : name_f , "<STR_LIT>" : account_f } <EOL> barry , created = Agent . objects . retrieve_or_create ( ** kwargs_f ) <EOL> self . assertTrue ( created ) <EOL> barry . save ( ) <EOL> self . assertEquals ( barry . objectType , ot_f ) <EOL> self . assertEquals ( barry . name , name_f ) <EOL> self . assertEquals ( barry . account_homePage , account_f [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( barry . account_name , account_f [ '<STR_LIT:name>' ] ) <EOL> barry_exact = barry . to_dict ( ) <EOL> self . assertEquals ( barry_exact [ '<STR_LIT>' ] , ot_f ) <EOL> self . assertEquals ( barry_exact [ '<STR_LIT:name>' ] , name_f ) <EOL> self . assertEquals ( barry_exact [ '<STR_LIT>' ] [ '<STR_LIT>' ] , account_f [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( barry_exact [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] , account_f [ '<STR_LIT:name>' ] ) <EOL> barry_ids = barry . to_dict ( ids_only = True ) <EOL> self . assertFalse ( '<STR_LIT>' in str ( barry_ids ) , "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT:name>' in barry_ids . items ( ) , "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT>' in barry_ids . items ( ) , "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT>' in str ( barry_ids ) , "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT>' in str ( barry_ids ) , "<STR_LIT>" ) <EOL> self . assertEquals ( barry_ids [ '<STR_LIT>' ] [ '<STR_LIT>' ] , account_f [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( barry_ids [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] , account_f [ '<STR_LIT:name>' ] ) <EOL> ot_j = "<STR_LIT>" <EOL> name_j = "<STR_LIT>" <EOL> mbox_j = "<STR_LIT>" <EOL> kwargs_j = { "<STR_LIT>" : ot_j , "<STR_LIT:name>" : name_j , "<STR_LIT>" : mbox_j , "<STR_LIT>" : [ kwargs_s , kwargs_ww , kwargs_f , kwargs_b ] } <EOL> justiceleague , created = Agent . objects . retrieve_or_create ( ** kwargs_j ) <EOL> self . assertTrue ( created ) <EOL> justiceleague . save ( ) <EOL> self . assertEquals ( justiceleague . objectType , ot_j ) <EOL> self . assertEquals ( justiceleague . name , name_j ) <EOL> self . assertEquals ( justiceleague . mbox , mbox_j ) <EOL> justiceleague_exact = justiceleague . to_dict ( ) <EOL> self . assertEquals ( justiceleague_exact [ '<STR_LIT>' ] , ot_j ) <EOL> self . assertEquals ( justiceleague_exact [ '<STR_LIT:name>' ] , name_j ) <EOL> self . assertEquals ( justiceleague_exact [ '<STR_LIT>' ] , mbox_j ) <EOL> justiceleague_ids = justiceleague . to_dict ( ids_only = True ) <EOL> self . assertTrue ( '<STR_LIT>' in str ( justiceleague_ids ) , "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT:name>' in str ( justiceleague_ids ) , "<STR_LIT>" ) <EOL> self . assertEquals ( justiceleague_ids [ '<STR_LIT>' ] , mbox_j ) <EOL> badguy_ds = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } <EOL> badguy_m = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:name>" : "<STR_LIT>" } <EOL> ot_bg = "<STR_LIT>" <EOL> members_bg = [ badguy_ds , badguy_m ] <EOL> kwargs_bg = { "<STR_LIT>" : ot_bg , "<STR_LIT>" : members_bg } <EOL> badguys , created = Agent . objects . retrieve_or_create ( ** kwargs_bg ) <EOL> self . assertTrue ( created ) <EOL> badguys . save ( ) <EOL> self . assertEquals ( badguys . objectType , ot_bg ) <EOL> bg_members = badguys . member . all ( ) <EOL> self . assertEquals ( len ( bg_members ) , <NUM_LIT:2> ) <EOL> for bg in bg_members : <EOL> self . assertTrue ( bg . name in str ( kwargs_bg [ '<STR_LIT>' ] ) ) <EOL> badguys_exact = badguys . to_dict ( ) <EOL> self . assertEquals ( badguys_exact [ '<STR_LIT>' ] , ot_bg ) <EOL> for m in badguys_exact [ '<STR_LIT>' ] : <EOL> if m [ '<STR_LIT:name>' ] == badguy_ds [ '<STR_LIT:name>' ] : <EOL> self . assertEquals ( m [ '<STR_LIT>' ] , badguy_ds [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( m [ '<STR_LIT>' ] , badguy_ds [ '<STR_LIT>' ] ) <EOL> elif m [ '<STR_LIT:name>' ] == badguy_m [ '<STR_LIT:name>' ] : <EOL> self . assertEquals ( m [ '<STR_LIT>' ] , badguy_m [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( m [ '<STR_LIT>' ] , badguy_m [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" % m [ '<STR_LIT:name>' ] ) <EOL> badguys_ids = badguys . to_dict ( ids_only = True ) <EOL> self . assertTrue ( '<STR_LIT>' in str ( badguys_ids ) , "<STR_LIT>" ) <EOL> for m in badguys_ids [ '<STR_LIT>' ] : <EOL> self . assertFalse ( '<STR_LIT>' in str ( m ) , "<STR_LIT>" ) <EOL> self . assertFalse ( '<STR_LIT:name>' in str ( m ) , "<STR_LIT>" ) <EOL> if m [ '<STR_LIT>' ] == badguy_ds [ '<STR_LIT>' ] : <EOL> self . assertEquals ( m [ '<STR_LIT>' ] , badguy_ds [ '<STR_LIT>' ] ) <EOL> elif m [ '<STR_LIT>' ] == badguy_m [ '<STR_LIT>' ] : <EOL> self . assertEquals ( m [ '<STR_LIT>' ] , badguy_m [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" % m [ '<STR_LIT>' ] ) </s>
