def testSupportMultipleIdentitiesPerContact(self):
    """Ensure that the SUPPORT_MULTIPLE_IDENTITIES_PER_CONTACT migration works correctly."""
    identity_key = 'Email:' + self._user2.email

    # Create an identity to exercise the 'contact_user_id' field of the down-level response.
    self._UpdateOrAllocateDBObject(Identity, key=identity_key, user_id=21)

    # This contact is for a registered user.
    contact_dict = Contact.CreateContactDict(user_id=self._user.user_id,
                                             identities_properties=[(identity_key, 'work'),
                                                                    ('Email:' + self._user3.email, 'home'),
                                                                    ('Phone:+13191234567', 'mobile')],
                                             timestamp=1,
                                             contact_source=Contact.GMAIL,
                                             name='Mike Purtell',
                                             given_name='Mike',
                                             family_name='Purtell',
                                             rank=3)
    self._UpdateOrAllocateDBObject(Contact, **contact_dict)

    # This contact has been removed and shouldn't show up in down-level client queries.
    contact_dict = Contact.CreateContactDict(user_id=self._user.user_id,
                                             identities_properties=None,
                                             timestamp=1,
                                             contact_source=Contact.GMAIL,
                                             contact_id='gm:onetwothree',
                                             sort_key=Contact.CreateSortKey('gm:onetwothree', 1),
                                             labels=[Contact.REMOVED])
    self._UpdateOrAllocateDBObject(Contact, **contact_dict)

    # This contact has unknown identities.
    contact_dict = Contact.CreateContactDict(user_id=self._user.user_id,
                                             identities_properties=[('Email:someone@somewhere.com', 'work'),
                                                                    ('Email:somebody@somewhere.com', 'home'),
                                                                    ('Phone:+13191234567', 'mobile')],
                                             timestamp=1,
                                             contact_source=Contact.GMAIL,
                                             name='Some One',
                                             given_name='Some',
                                             family_name='Body',
                                             rank=5)
    self._UpdateOrAllocateDBObject(Contact, **contact_dict)

    # This contact has just a phone number and shouldn't show up in down-level client queries.
    contact_dict = Contact.CreateContactDict(user_id=self._user.user_id,
                                             identities_properties=[('Phone:+13191234567', 'mobile')],
                                             timestamp=1,
                                             contact_source=Contact.GMAIL,
                                             name='Some One with just a phone',
                                             given_name='Some',
                                             family_name='Body',
                                             rank=42)
    self._UpdateOrAllocateDBObject(Contact, **contact_dict)

    # This contact has no identities and shouldn't show up in down-level client queries.
    contact_dict = Contact.CreateContactDict(user_id=self._user.user_id,
                                             identities_properties=[],
                                             timestamp=1,
                                             contact_source=Contact.GMAIL,
                                             name='Some One with just a phone',
                                             given_name='Some',
                                             family_name='Body',
                                             rank=42)
    self._UpdateOrAllocateDBObject(Contact, **contact_dict)

    response = self._SendRequest('query_contacts', self._cookie, {}, version=Message.SUPPRESS_BLANK_COVER_PHOTO)

    # Verify response is what we expect for down-level client.
    self.assertEqual(response['headers'], {'version': Message.SUPPRESS_BLANK_COVER_PHOTO})
    self.assertEqual(response['num_contacts'], 2)
    response_contact = response['contacts'][1]
    self.assertEqual(response_contact['name'], 'Mike Purtell')
    self.assertEqual(response_contact['given_name'], 'Mike')
    self.assertEqual(response_contact['family_name'], 'Purtell')
    self.assertEqual(response_contact['rank'], 3)
    self.assertEqual(response_contact['contact_user_id'], 21)
    self.assertEqual(response_contact['identity'], identity_key)
    self.assertFalse(response_contact in 'identities')
    self.assertFalse('contact_id' in response_contact)
    self.assertFalse('contact_source' in response_contact)
    self.assertFalse('labels' in response_contact)

    response_contact = response['contacts'][0]
    self.assertEqual(response_contact['name'], 'Some One')
    self.assertEqual(response_contact['given_name'], 'Some')
    self.assertEqual(response_contact['family_name'], 'Body')
    self.assertEqual(response_contact['rank'], 5)
    self.assertEqual(response_contact['identity'], 'Email:someone@somewhere.com')
    self.assertFalse('contact_user_id' in response_contact)
    self.assertFalse('identities' in response_contact)
    self.assertFalse('contact_id' in response_contact)
    self.assertFalse('contact_source' in response_contact)
    self.assertFalse('labels' in response_contact)
dataset/ETHPy150Open viewfinderco/viewfinder/backend/www/test/versioning_test.py/VersioningTestCase.testSupportMultipleIdentitiesPerContact/swapped operands of `in`