def test_contacts_as_a_generator(self):
        contacts = make_contacts(BATCH_SAVING_SIZE_LIMIT)
        connection = self._make_connection_for_contacts(contacts)

        contacts_generator = iter(contacts)
        with connection:
            save_contacts(contacts_generator, connection)
Example #2
0
 def save_contact_to_hub(self):
     """
     Calls hubspot api and created a contact (if not exists) and saves it to 
     the HubSpot Account registered 
     """
     try:
         self.logger.debug('Inside save_contact_to_hub() function')
         self.vid = self.phone_number
         self.logger.debug("Saving contact to hub {}{}{}{}{}".format(self.vid,self.first_name,\
         self.last_name,self.email,self.phone_number))
         with PortalConnection(self.authentication_key,
                               self.app_name) as connection:
             for contact in get_all_contacts(connection,
                                             property_names=('phone', )):
                 if 'unassigned' in contact.email_address and \
                 'unassigned' in self.email:
                     raise Exception('Contact {} already saved in hubspot'.\
                     format(self.phone_number))
             contact = []
             contact.append(Contact(vid=self.vid, email_address=self.email, \
             properties={u'lastname':self.last_name, u'firstname': \
             self.first_name,u'phone':str(self.phone_number),u'channelid':str(self.channel_id)},))
             save_contacts(contact, connection)
     except Exception as e:
         self.logger.exception("Error saving contact to Hubspot. {}".format(
             e.message))
    def test_some_contacts(self):
        saved_contacts = make_contacts(1)
        with self._make_connection_for_contacts(saved_contacts) as connection:
            with assert_raises(HubspotServerError) as context_manager:
                save_contacts(saved_contacts, connection)

        eq_(self._STUB_EXCEPTION, context_manager.exception)
    def _test_invalid_property_value(
        self,
        property_,
        property_value,
        exc_message_template,
        ):
        saved_contacts = make_contacts(1)
        connection = \
            self._make_connection_for_contacts(saved_contacts, property_)

        contact_with_invalid_property_value = \
            make_contact(1, {property_.name: property_value})
        exc_message = exc_message_template.format(repr(property_value))
        with assert_raises_regexp(HubspotPropertyValueError, exc_message):
            with connection:
                save_contacts([contact_with_invalid_property_value], connection)
Example #5
0
def _update_random_contact(connection):
    all_contacts = get_all_contacts(connection)
    first_contact = next(all_contacts)

    del first_contact.properties['lastmodifieddate']
    first_contact.properties['lastname'] = 'First User'

    return save_contacts([first_contact], connection)
    def _assert_property_value_cast_equals(
        self,
        property_definition,
        original_value,
        expected_cast_value,
        ):
        contact = make_contact(1, {property_definition.name: original_value})
        contacts = [contact]
        connection = \
            self._make_connection_for_contacts(contacts, property_definition)
        with connection:
            save_contacts(contacts, connection)

        api_call = connection.api_calls[-1]
        contact_data = api_call.request_body_deserialization[0]
        contact_properties_data = contact_data['properties']
        contact_property_data = contact_properties_data[0]
        eq_(expected_cast_value, contact_property_data['value'])
def test_save_contacts():
    with _get_portal_connection() as connection:
        all_contacts = get_all_contacts(connection)
        first_contact = next(all_contacts)

        del first_contact.properties['lastmodifieddate']

        result = save_contacts([first_contact], connection)
        assert_is_none(result)
def test_save_contacts():
    with _get_portal_connection() as connection:
        all_contacts = get_all_contacts(connection)
        first_contact = next(all_contacts)

        del first_contact.properties['lastmodifieddate']

        result = save_contacts([first_contact], connection)
        assert_is_none(result)
Example #9
0
 def save_contact_to_hub(self):
     """
     calls hubspot api and created a contact (if not exists) and saves it to 
     the HubSpot Account registered 
     """
     try:
         self.logger.debug('Inside save_contact_to_hub() function')
         self.logger.debug("Saving contact to hub {}{}{}{}{}".format(self.vid,self.first_name,\
         self.last_name,self.email,self.phone_number))
         self.obtain_hubspot_config()
         authentication_key = APIKey(self.api_key)
         with PortalConnection(authentication_key,
                               self.app_name) as connection:
             contact = []
             contact.append(Contact(vid=self.vid, email_address=self.email, \
             properties={u'lastname':self.last_name, u'firstname': \
             self.first_name,u'phone':str(self.phone_number),},))
             save_contacts(contact, connection)
     except Exception as e:
         self.logger.exception("Error saving contact to Hubspot. {}".format(
             e.message))
 def test_no_contacts(self):
     contacts = []
     with self._make_connection_for_contacts(contacts) as connection:
         save_contacts(contacts, connection)
 def _check_saved_contacts_match(cls, contacts, available_property=None):
     connection = \
         cls._make_connection_for_contacts(contacts, available_property)
     with connection:
         save_contacts(contacts, connection)