def test_agent_format(self):
        ot_s = "Agent"
        name_s = "superman"
        mbox_s = "mailto:superman@example.com"
        kwargs_s = {"objectType":ot_s,"name":name_s,"mbox":mbox_s}
        clark, created = Agent.objects.retrieve_or_create(**kwargs_s)
        self.assertTrue(created)
        clark.save()
        self.assertEquals(clark.objectType, ot_s)
        self.assertEquals(clark.name, name_s)
        self.assertEquals(clark.mbox, mbox_s)

        clark_exact = clark.to_dict()
        self.assertEquals(clark_exact['objectType'], ot_s)
        self.assertEquals(clark_exact['name'], name_s)
        self.assertEquals(clark_exact['mbox'], mbox_s)

        clark_ids = clark.to_dict(ids_only=True)
        self.assertFalse('objectType' in str(clark_ids), "object type was found in agent json")
        self.assertFalse('name' in str(clark_ids), "name was found in agent json")
        self.assertEquals(clark_ids['mbox'], mbox_s)

        ot_ww = "Agent"
        name_ww = "wonder woman"
        mbox_sha1sum_ww = hashlib.sha1("mailto:wonderwoman@example.com").hexdigest()
        kwargs_ww = {"objectType":ot_ww,"name":name_ww,"mbox_sha1sum":mbox_sha1sum_ww}
        diana, created = Agent.objects.retrieve_or_create(**kwargs_ww)
        self.assertTrue(created)
        diana.save()
        self.assertEquals(diana.objectType, ot_ww)
        self.assertEquals(diana.name, name_ww)
        self.assertEquals(diana.mbox_sha1sum, mbox_sha1sum_ww)

        diana_exact = diana.to_dict()
        self.assertEquals(diana_exact['objectType'], ot_ww)
        self.assertEquals(diana_exact['name'], name_ww)
        self.assertEquals(diana_exact['mbox_sha1sum'], mbox_sha1sum_ww)

        diana_ids = diana.to_dict(ids_only=True)
        self.assertFalse('objectType' in str(diana_ids), "object type was found in agent json")
        self.assertFalse('name' in str(diana_ids), "name was found in agent json")
        self.assertFalse('mbox' in diana_ids.items(), "mbox was found in agent json")
        self.assertEquals(diana_ids['mbox_sha1sum'], mbox_sha1sum_ww)

        ot_b = "Agent"
        name_b = "batman"
        openid_b = "id:batman"
        kwargs_b = {"objectType":ot_b,"name":name_b,"openid":openid_b}
        bruce, created = Agent.objects.retrieve_or_create(**kwargs_b)
        self.assertTrue(created)
        bruce.save()
        self.assertEquals(bruce.objectType, ot_b)
        self.assertEquals(bruce.name, name_b)
        self.assertEquals(bruce.openid, openid_b)

        bruce_exact = bruce.to_dict()
        self.assertEquals(bruce_exact['objectType'], ot_b)
        self.assertEquals(bruce_exact['name'], name_b)
        self.assertEquals(bruce_exact['openid'], openid_b)

        bruce_ids = bruce.to_dict(ids_only=True)
        self.assertFalse('objectType' in str(bruce_ids), "object type was found in agent json")
        self.assertFalse('name' in str(bruce_ids), "name was found in agent json")
        self.assertFalse('mbox' in str(bruce_ids), "mbox was found in agent json")
        self.assertFalse('mbox_sha1sum' in str(bruce_ids), "mbox_sha1sum was found in agent json")
        self.assertEquals(bruce_ids['openid'], openid_b)

        ot_f = "Agent"
        name_f = "the flash"
        account_f = {"homePage":"http://ultrasecret.justiceleague.com/accounts/", "name":"theflash"}
        kwargs_f = {"objectType":ot_f,"name":name_f,"account":account_f}
        barry, created = Agent.objects.retrieve_or_create(**kwargs_f)
        self.assertTrue(created)
        barry.save()
        self.assertEquals(barry.objectType, ot_f)
        self.assertEquals(barry.name, name_f)
        self.assertEquals(barry.account_homePage, account_f['homePage'])
        self.assertEquals(barry.account_name, account_f['name'])

        barry_exact = barry.to_dict()
        self.assertEquals(barry_exact['objectType'], ot_f)
        self.assertEquals(barry_exact['name'], name_f)
        self.assertEquals(barry_exact['account']['homePage'], account_f['homePage'])
        self.assertEquals(barry_exact['account']['name'], account_f['name'])

        barry_ids = barry.to_dict(ids_only=True)
        self.assertFalse('objectType' in str(barry_ids), "object type was found in agent json")
        self.assertFalse('name' in barry_ids.items(), "name was found in agent json")
        self.assertFalse('mbox' in barry_ids.items(), "mbox was found in agent json")
        self.assertFalse('mbox_sha1sum' in str(barry_ids), "mbox_sha1sum was found in agent json")
        self.assertFalse('openid' in str(barry_ids), "openid was found in agent json")
        self.assertEquals(barry_ids['account']['homePage'], account_f['homePage'])
        self.assertEquals(barry_ids['account']['name'], account_f['name'])

        ot_j = "Group"
        name_j = "Justice League"
        mbox_j = "mailto:justiceleague@example.com"
        kwargs_j = {"objectType":ot_j,"name":name_j,"mbox":mbox_j, "member":[kwargs_s,kwargs_ww,kwargs_f,kwargs_b]}
        justiceleague, created = Agent.objects.retrieve_or_create(**kwargs_j)
        self.assertTrue(created)
        justiceleague.save()
        self.assertEquals(justiceleague.objectType, ot_j)
        self.assertEquals(justiceleague.name, name_j)
        self.assertEquals(justiceleague.mbox, mbox_j)

        justiceleague_exact = justiceleague.to_dict()
        self.assertEquals(justiceleague_exact['objectType'], ot_j)
        self.assertEquals(justiceleague_exact['name'], name_j)
        self.assertEquals(justiceleague_exact['mbox'], mbox_j)

        justiceleague_ids = justiceleague.to_dict(ids_only=True)
        self.assertTrue('objectType' in str(justiceleague_ids), "object type was not found in group json")
        self.assertFalse('name' in str(justiceleague_ids), "name was found in agent json")
        self.assertEquals(justiceleague_ids['mbox'], mbox_j)

        badguy_ds = {"objectType":"Agent", "mbox":"mailto:darkseid@example.com", "name":"Darkseid"}
        badguy_m = {"objectType":"Agent", "mbox":"mailto:mantis@example.com", "name":"Mantis"}

        ot_bg = "Group"
        members_bg = [badguy_ds, badguy_m]
        kwargs_bg = {"objectType":ot_bg,"member":members_bg}
        badguys, created = Agent.objects.retrieve_or_create(**kwargs_bg)
        self.assertTrue(created)
        badguys.save()
        self.assertEquals(badguys.objectType, ot_bg)
        bg_members = badguys.member.all()
        self.assertEquals(len(bg_members), 2)
        for bg in bg_members:
            self.assertTrue(bg.name in str(kwargs_bg['member']))

        badguys_exact = badguys.to_dict()
        self.assertEquals(badguys_exact['objectType'], ot_bg)
        for m in badguys_exact['member']:
            if m['name'] == badguy_ds['name']:
                self.assertEquals(m['objectType'], badguy_ds['objectType'])
                self.assertEquals(m['mbox'], badguy_ds['mbox'])
            elif m['name'] == badguy_m['name']:
                self.assertEquals(m['objectType'], badguy_m['objectType'])
                self.assertEquals(m['mbox'], badguy_m['mbox'])
            else:
                self.fail("got an unexpected name: " % m['name'])

        badguys_ids = badguys.to_dict(ids_only=True)
        self.assertTrue('objectType' in str(badguys_ids), "object type was not found in group json")
        for m in badguys_ids['member']:
            self.assertFalse('objectType' in str(m), "object type was found in member agent")
            self.assertFalse('name' in str(m), "name was found in member agent")
            if m['mbox'] == badguy_ds['mbox']:
                self.assertEquals(m['mbox'], badguy_ds['mbox'])
            elif m['mbox'] == badguy_m['mbox']:
                self.assertEquals(m['mbox'], badguy_m['mbox'])
            else:
                self.fail("got an unexpected mbox: " % m['mbox'])
dataset/ETHPy150Open adlnet/ADL_LRS/lrs/tests/test_AgentManager.py/AgentManagerTests.test_agent_format/original