human
Complete this python program:
def _TestUploadContacts(tester, user_cookie, request_dict):
assistant
#Here is the Python program you requested.

    """Called by the ServiceTester in order to test upload_contacts
    service API call.
    """
    def _ValidateUploadOneContact(contact):
        contact = deepcopy(contact)
        identities_properties = [(identity_properties['identity'], identity_properties.get('description', None)) for identity_properties in contact['identities']]
        contact.pop('identities')
        contact_dict = Contact.CreateContactDict(user_id, identities_properties, op_dict['op_timestamp'], **contact)
        predicate = (lambda c: (c.contact_id == contact_dict['contact_id']))
        existing_contacts = validator.QueryModelObjects(Contact, predicate=predicate)
        if ((len(existing_contacts) == 0) or existing_contacts[(-1)].IsRemoved()):
            if (len(existing_contacts) != 0):
                validator.ValidateDeleteDBObject(Contact, DBKey(user_id, existing_contacts[(-1)].sort_key))
            validator.ValidateCreateContact(**contact_dict)
        return contact_dict['contact_id']
    validator = tester.validator
    (user_id, device_id) = tester.GetIdsFromCookie(user_cookie)
    request_dict = deepcopy(request_dict)
    actual_dict = tester.SendRequest('upload_contacts', user_cookie, request_dict)
    op_dict = tester._DeriveNotificationOpDict(user_id, device_id, request_dict)
    result_contact_ids = []
    for contact in request_dict['contacts']:
        contact_id = _ValidateUploadOneContact(contact)
        result_contact_ids.append(contact_id)
    invalidate = {'contacts': {'start_key': Contact.CreateSortKey(None, op_dict['op_timestamp'])}}
    validator.ValidateNotification('upload_contacts', user_id, op_dict, invalidate)
    util._TEST_TIME += 1
    tester._CompareResponseDicts('upload_contacts', user_id, request_dict, {'contact_ids': result_contact_ids}, actual_dict)
    return actual_dict