Ejemplo n.º 1
0
 def test_agent_mbox_sha1sum_create(self):
     msha = hashlib.sha1("*****@*****.**").hexdigest()
     bob = agent(mbox_sha1sum=msha)
     self.assertEquals(bob.mbox_sha1sum, msha)
     self.assertEquals(bob.objectType, "Agent")
     self.assertFalse(bob.name)
     self.assertFalse(bob.mbox)
Ejemplo n.º 2
0
 def test_agent_mbox_sha1sum_create(self):
     msha = hashlib.sha1("*****@*****.**").hexdigest()
     bob = agent(mbox_sha1sum=msha)
     self.assertEquals(bob.mbox_sha1sum, msha)
     self.assertEquals(bob.objectType, "Agent")
     self.assertFalse(bob.name)
     self.assertFalse(bob.mbox)
Ejemplo n.º 3
0
 def test_agent_openid_create(self):
     openid = "bob.openid.com"
     bob = agent(openid=openid)
     self.assertEquals(bob.openid, openid)
     self.assertEquals(bob.objectType, "Agent")
     self.assertFalse(bob.name)
     self.assertFalse(bob.mbox)
     self.assertFalse(bob.mbox_sha1sum)
     self.assertFalse(bob.account)
Ejemplo n.º 4
0
 def test_agent_openid_create(self):
     openid = "bob.openid.com"
     bob = agent(openid=openid)
     self.assertEquals(bob.openid, openid)
     self.assertEquals(bob.objectType, "Agent")
     self.assertFalse(bob.name)
     self.assertFalse(bob.mbox)
     self.assertFalse(bob.mbox_sha1sum)
     self.assertFalse(bob.account)
Ejemplo n.º 5
0
    def __populate(self, the_agent, the_object):
        try:
            objtype = the_object['objectType']
        except KeyError:
            objtype = 'Person'

        if not the_agent:
            if objtype == 'Agent':
                the_agent = models.agent(objectType='Agent')
            elif objtype == 'Group':
                the_agent = models.group(objectType='Group')
            else:
                the_agent = models.person(objectType='Person')
            the_agent.save()
        else:
            if not the_agent.objectType:
                the_agent.objectType = objtype
        
        #if the_agent.objectType == 'Group':
        #    for member in the_object['member']:
        #        a = Actor(json.dumps(member))
        #        print dir(the_agent)
        #        #the_agent.group.agent_group.get_or_create(a.agent)

        for k, v in the_object.items():
            # skipping string values.. only dealing with arrays
            # this is because the only string value is objectType.. 
            # and i just set that
            if isinstance(v, types.StringTypes): continue
            for val in v:
                try:
                    # get agent_
                    fun = 'agent_%s_set' % k
                    the_set = getattr(the_agent, fun)
                    vals = the_set.values_list(k, flat=True) # gets me an array of values for the agent_n_set
                    if not vals or val not in vals: # is the value list empty or doesn't have the ifp value
                        the_set.create(**{k:val})
                except:
                    try: 
                        fun = 'person_%s_set' % k.lower()
                        the_set = getattr(the_agent.person, fun)
                        vals = the_set.values_list(k, flat=True) # gets me an array of values for the agent_n_set
                        if not vals or val not in vals: # is the value list empty or doesn't have the ifp value
                            the_set.create(**{k:val})
                    except:
                        to_create = {}
                        account_obj = val
                        if 'accountName' in val:
                            to_create['accountName'] = val['accountName']
                        if 'accountServiceHomePage' in val:
                            to_create['accountServiceHomePage'] = val['accountServiceHomePage']
                        vals = the_agent.agent_account_set.all()
                        the_agent.agent_account_set.get_or_create(**to_create)  
        return the_agent     
Ejemplo n.º 6
0
 def test_agent_account_create(self):
     account = {"homePage":"http://www.adlnet.gov","name":"freakshow"}
     bobacc = agent_account(**account)
     bob = agent(account=bobacc)
     bob.save()
     a = bob.account
     self.assertEquals(a.name, "freakshow")
     self.assertEquals(a.homePage, "http://www.adlnet.gov")
     self.assertEquals(a.agent, bob)
     self.assertFalse(bob.name)
     self.assertFalse(bob.mbox)
     self.assertFalse(bob.mbox_sha1sum)
     self.assertFalse(bob.openid)
Ejemplo n.º 7
0
 def test_agent_account_create(self):
     account = {"homePage": "http://www.adlnet.gov", "name": "freakshow"}
     bobacc = agent_account(**account)
     bob = agent(account=bobacc)
     bob.save()
     a = bob.account
     self.assertEquals(a.name, "freakshow")
     self.assertEquals(a.homePage, "http://www.adlnet.gov")
     self.assertEquals(a.agent, bob)
     self.assertFalse(bob.name)
     self.assertFalse(bob.mbox)
     self.assertFalse(bob.mbox_sha1sum)
     self.assertFalse(bob.openid)
Ejemplo n.º 8
0
    def test_agent_del(self):
        ag = agent(name="the agent")
        ag.save()
        acc = agent_account(agent=ag, homePage="http://adlnet.gov/agent/1", name="agent 1 account")
        acc.save()

        self.assertEquals(ag.name, "the agent")
        self.assertEquals(ag.agent_account.name, "agent 1 account")
        self.assertEquals(ag.agent_account.homePage, "http://adlnet.gov/agent/1")
        self.assertEquals(1, len(agent.objects.all()))
        self.assertEquals(1, len(agent_account.objects.all()))

        ag.delete()

        self.assertEquals(0, len(agent.objects.all()))
        self.assertEquals(0, len(agent_account.objects.all()))
Ejemplo n.º 9
0
 def test_agent_mbox_create(self):
     mbox = "*****@*****.**"
     bob = agent(mbox=mbox)
     self.assertEquals(bob.mbox, mbox)
     self.assertEquals(bob.objectType, "Agent")
     self.assertFalse(bob.name)
Ejemplo n.º 10
0
 def test_agent_mbox_create(self):
     mbox = "*****@*****.**"
     bob = agent(mbox=mbox)
     self.assertEquals(bob.mbox, mbox)
     self.assertEquals(bob.objectType, "Agent")
     self.assertFalse(bob.name)