Ejemplo n.º 1
0
 def testQueryBoundContact(self):
     """Fetch a contact that is bound to a user."""
     self._CreateContact([('Local:1', None, 100)])
     response_dict = self._tester.QueryContacts(self._cookie)
     contact_dict = {
         'identities_properties': [('Local:1', None)],
         'contact_source': Contact.GMAIL
     }
     contact_dict['contact_id'] = Contact.CalculateContactId(contact_dict)
     contact_dict['identities'] = [{'identity': 'Local:1', 'user_id': 100}]
     contact_dict.pop('identities_properties')
     self.assertEqual(response_dict['contacts'][0], contact_dict)
Ejemplo n.º 2
0
 def testQueryContactNoIdentity(self):
     """Fetch a contact with no corresponding identity object."""
     self._CreateContact([('Local:1', None)], no_identity=True)
     response_dict = self._tester.QueryContacts(self._cookie)
     contact_dict = {
         'identities_properties': [('Local:1', None)],
         'contact_source': Contact.GMAIL
     }
     contact_dict['contact_id'] = Contact.CalculateContactId(contact_dict)
     contact_dict['identities'] = [{'identity': 'Local:1'}]
     contact_dict.pop('identities_properties')
     self.assertEqual(response_dict['contacts'][0], contact_dict)
Ejemplo n.º 3
0
  def ValidateRewriteContacts(self, identity_key, op_dict):
    """Validates that all contacts that reference "identity_key" have been updated with the
    new timestamp.
    """
    # Iterate over all contacts that reference the identity.
    for co in self.QueryModelObjects(Contact, predicate=lambda co: identity_key in co.identities):
      # Validate that contact has been updated.
      contact_dict = co._asdict()
      contact_dict['timestamp'] = op_dict['op_timestamp']
      sort_key = Contact.CreateSortKey(Contact.CalculateContactId(contact_dict), contact_dict['timestamp'])
      contact_dict['sort_key'] = sort_key
      self.ValidateUpdateDBObject(Contact, **contact_dict)

      # Validate that any old contacts have been deleted.
      if sort_key != co.sort_key:
        self.ValidateDeleteDBObject(Contact, co.GetKey())
Ejemplo n.º 4
0
  def ValidateCreateContact(self, user_id, identities_properties, timestamp, contact_source, **op_dict):
    """Validates creation of contact along with derived attributes.
    Returns created contact.
    """
    contact_dict = op_dict
    contact_dict['user_id'] = user_id
    contact_dict['timestamp'] = timestamp
    if identities_properties is not None:
      contact_dict['identities_properties'] = identities_properties
      contact_dict['identities'] = set([Identity.Canonicalize(identity_properties[0])
                                        for identity_properties in identities_properties])
    else:
      contact_dict['identities_properties'] = None
    contact_dict['contact_source'] = contact_source
    if 'contact_id' not in contact_dict:
      contact_dict['contact_id'] = Contact.CalculateContactId(contact_dict)
    if 'sort_key' not in contact_dict:
      contact_dict['sort_key'] = Contact.CreateSortKey(contact_dict['contact_id'], timestamp)

    return self.ValidateCreateDBObject(Contact, **contact_dict)