def test_update(self): # Find a company by id company = Company.find(id=self.company.id) # Update a company now = get_timestamp() updated_name = 'Company %s' % (now) company.name = updated_name company.save() company = Company.find(id=self.company.id) self.assertEqual(company.name, updated_name)
def get_or_create_company(timestamp): name = 'Company %s' % (timestamp) # get company try: company = Company.find(name=name) except ResourceNotFound: # Create a company company = Company.create(company_id=timestamp, name=name) return company
def get_or_create_company(timestamp): name = 'Company %s' % (timestamp) # get company try: company = Company.find(name=name) except ResourceNotFound: # Create a company company = Company.create( company_id=timestamp, name=name) return company
def it_raises_error_on_load(self): data = { 'type': 'user', 'id': 'aaaaaaaaaaaaaaaaaaaaaaaa', 'company_id': '4', 'name': 'MyCo' } side_effect = [data, None] with patch.object(Intercom, 'get', side_effect=side_effect) as mock_method: # noqa company = Company.find(company_id='4') with assert_raises(intercom.HttpError): company.load() eq_([call('/companies', company_id='4'), call('/companies/aaaaaaaaaaaaaaaaaaaaaaaa')], # noqa mock_method.mock_calls)
def it_raises_error_on_load(self): data = { 'type': 'user', 'id': 'aaaaaaaaaaaaaaaaaaaaaaaa', 'company_id': '4', 'name': 'MyCo' } side_effect = [data, None] with patch.object(Intercom, 'get', side_effect=side_effect) as mock_method: # noqa company = Company.find(company_id='4') with assert_raises(intercom.HttpError): company.load() eq_( [ call('/companies', company_id='4'), call('/companies/aaaaaaaaaaaaaaaaaaaaaaaa') ], # noqa mock_method.mock_calls)
def test_add_user_custom_attributes(self): user = User.find(email=self.user.email) user.companies = [ { "id": 6, "name": "Intercom", "custom_attributes": { "referral_source": "Google" } } ] user.save() user = User.find(email=self.user.email) self.assertEqual(len(user.companies), 2) self.assertEqual(user.companies[0].company_id, "9") # check the custom attributes company = Company.find(company_id=6) self.assertEqual( company.custom_attributes['referral_source'], "Google")
def test_users(self): company = Company.find(id=self.company.id) # Get a list of users in a company for user in company.users: self.assertIsNotNone(user.email)
def test_find_by_id(self): # Find a company by _id company = Company.find(id=self.company.id) self.assertEqual(company.company_id, self.company.company_id)
def test_find_by_company_name(self): # Find a company by name company = Company.find(name=self.company.name) self.assertEqual(company.name, self.company.name)
def it_raises_error_if_no_response_on_find(self): with patch.object(Intercom, 'get', return_value=None) as mock_method: with assert_raises(intercom.HttpError): Company.find(company_id='4') mock_method.assert_called_once_with('/companies', company_id='4')
def test_untag_companies(self): # Untag companies tag = Tag.untag_companies("red", [self.user.companies[0].id]) self.assertEqual(tag.name, "red") company = Company.find(id=self.user.companies[0].id) self.assertEqual(0, len(company.tags))