本文整理汇总了Python中intercom.user.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_save_user
def test_save_user(self):
user = User(email='[email protected]', custom_data={'age': '42'})
user.save()
self.assertEqual(None, user.user_id)
self.assertEqual('[email protected]', user.email)
self.assertEqual('42', user.custom_data['age'])
self.assertEqual(1, user.session_count)
示例2: test_properties
def test_properties(self):
user = User()
user.email = '[email protected]'
user.user_id = 1234
user.name = 'Joe'
user.last_seen_ip = '192.168.1.100'
user.last_seen_user_agent = 'Mozilla/5.0'
user.created_at = datetime.fromtimestamp(1331764344)
user.custom_data = { 'name': 'Ace' }
user.companies = [{
'id':1,
'name':'Intercom'}]
with self.assertRaises(AttributeError):
# cannot set the relationship score
user.relationship_score = 50
self.assertEqual('[email protected]', user.email)
self.assertEqual(1234, user.user_id)
self.assertEqual('Joe', user.name)
self.assertEqual('192.168.1.100', user.last_seen_ip)
self.assertEqual('Mozilla/5.0', user.last_seen_user_agent)
with self.assertRaises(AttributeError):
# cannot read the companies
user.companies
self.assertEqual(None, user.relationship_score)
self.assertEqual(1331764344,
time.mktime(user.created_at.timetuple()))
self.assertEqual('Ace', user.custom_data['name'])
示例3: test_user_companies
def test_user_companies():
user = User()
user.companies = [{
'id': 1,
'name': 'Intercom',
'created_at': datetime.fromtimestamp(1331764344)}]
raises(AttributeError, lambda: user.companies)
user.companies = {'foo': 'bar'}
示例4: it_allows_easy_setting_of_multiple_companies
def it_allows_easy_setting_of_multiple_companies(self):
user = User()
companies = [
{"name": "Intercom", "company_id": "6"},
{"name": "Test", "company_id": "9"},
]
user.companies = companies
eq_(user.to_dict()["companies"], companies)
示例5: it_allows_easy_setting_of_custom_data
def it_allows_easy_setting_of_custom_data(self):
now = datetime.utcnow()
now_ts = calendar.timegm(now.utctimetuple())
user = User()
user.custom_attributes["mad"] = 123
user.custom_attributes["other"] = now_ts
user.custom_attributes["thing"] = "yay"
attrs = {"mad": 123, "other": now_ts, "thing": "yay"}
eq_(user.to_dict()["custom_attributes"], attrs)
示例6: it_to_dict_itself
def it_to_dict_itself(self):
created_at = datetime.utcnow()
user = User(
email="[email protected]", user_id="12345",
created_at=created_at, name="Jim Bob")
as_dict = user.to_dict()
eq_(as_dict["email"], "[email protected]")
eq_(as_dict["user_id"], "12345")
eq_(as_dict["created_at"], calendar.timegm(created_at.utctimetuple()))
eq_(as_dict["name"], "Jim Bob")
示例7: test_companies
def test_companies(self):
user = User()
user.companies = [{
'id': 1,
'name':' Intercom',
'created_at': datetime.fromtimestamp(1331764344)}]
self.assertRaises(AttributeError, lambda: user.companies)
try:
user.companies = {'foo':'bar'}
self.fail()
except ValueError:
pass
示例8: it_presents_a_complete_user_record_correctly
def it_presents_a_complete_user_record_correctly(self):
user = User.from_api(get_user())
eq_('id-from-customers-app', user.user_id)
eq_('[email protected]', user.email)
eq_('Joe Schmoe', user.name)
eq_('the-app-id', user.app_id)
eq_(123, user.session_count)
eq_(1401970114, calendar.timegm(user.created_at.utctimetuple()))
eq_(1393613864, calendar.timegm(user.remote_created_at.utctimetuple()))
eq_(1401970114, calendar.timegm(user.updated_at.utctimetuple()))
Avatar = define_lightweight_class('avatar', 'Avatar') # noqa
Company = define_lightweight_class('company', 'Company') # noqa
SocialProfile = define_lightweight_class('social_profile', 'SocialProfile') # noqa
LocationData = define_lightweight_class('locaion_data', 'LocationData') # noqa
self.assertIsInstance(user.avatar.__class__, Avatar.__class__)
img_url = 'https://graph.facebook.com/1/picture?width=24&height=24'
eq_(img_url, user.avatar.image_url)
self.assertIsInstance(user.companies, list)
eq_(1, len(user.companies))
self.assertIsInstance(user.companies[0].__class__, Company.__class__)
eq_('123', user.companies[0].company_id)
eq_('bbbbbbbbbbbbbbbbbbbbbbbb', user.companies[0].id)
eq_('the-app-id', user.companies[0].app_id)
eq_('Company 1', user.companies[0].name)
eq_(1390936440, calendar.timegm(
user.companies[0].remote_created_at.utctimetuple()))
eq_(1401970114, calendar.timegm(
user.companies[0].created_at.utctimetuple()))
eq_(1401970114, calendar.timegm(
user.companies[0].updated_at.utctimetuple()))
eq_(1401970113, calendar.timegm(
user.companies[0].last_request_at.utctimetuple()))
eq_(0, user.companies[0].monthly_spend)
eq_(0, user.companies[0].session_count)
eq_(1, user.companies[0].user_count)
eq_([], user.companies[0].tag_ids)
self.assertIsInstance(user.custom_attributes, FlatStore)
eq_('b', user.custom_attributes["a"])
eq_(2, user.custom_attributes["b"])
eq_(4, len(user.social_profiles))
twitter_account = user.social_profiles[0]
self.assertIsInstance(twitter_account.__class__, SocialProfile.__class__)
eq_('twitter', twitter_account.name)
eq_('abc', twitter_account.username)
eq_('http://twitter.com/abc', twitter_account.url)
self.assertIsInstance(user.location_data.__class__, LocationData.__class__)
eq_('Dublin', user.location_data.city_name)
eq_('EU', user.location_data.continent_code)
eq_('Ireland', user.location_data.country_name)
eq_('90', user.location_data.latitude)
eq_('10', user.location_data.longitude)
eq_('IRL', user.location_data.country_code)
ok_(user.unsubscribed_from_emails)
eq_("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11", user.user_agent_data) # noqa
示例9: test_find_by_email
def test_find_by_email(self):
user = User.find_by_email('[email protected]')
self.assertEqual(None, user.user_id)
self.assertEqual('[email protected]', user.email)
self.assertEqual('Joe', user.name)
self.assertEqual('192.168.1.100', user.last_seen_ip)
self.assertEqual('Mozilla/5.0', user.last_seen_user_agent)
self.assertEqual(50, user.relationship_score)
self.assertTrue(isinstance(user.last_impression_at, datetime))
self.assertEqual(1331834352,
time.mktime(user.last_impression_at.timetuple()))
self.assertTrue(isinstance(user.created_at, datetime))
self.assertEqual(1331764344,
time.mktime(user.created_at.timetuple()))
self.assertTrue(1, len(user.social_profiles))
profile = user.social_profiles[0]
self.assertTrue(isinstance(profile, SocialProfile))
self.assertEqual('twitter', profile.type)
self.assertEqual('foo', profile.username)
self.assertEqual('http://twitter.com/foo', profile.url)
self.assertEqual('1234567', profile.id)
self.assertEqual('Santiago', user.location_data['city_name'])
self.assertEqual('Santiago', user.location_data.city_name)
self.assertTrue(isinstance(user.location_data, LocationData))
self.assertEqual('johnny', user.custom_data['nick'])
示例10: it_gets_sets_rw_keys
def it_gets_sets_rw_keys(self):
created_at = datetime.utcnow()
payload = {
'email': '[email protected]',
'user_id': 'abc123',
'name': 'Bob Smith',
'last_seen_ip': '1.2.3.4',
'last_seen_user_agent': 'ie6',
'created_at': calendar.timegm(created_at.utctimetuple())
}
user = User(**payload)
expected_keys = ['custom_attributes']
expected_keys.extend(list(payload.keys()))
eq_(sorted(expected_keys), sorted(user.to_dict().keys()))
for key in list(payload.keys()):
eq_(payload[key], user.to_dict()[key])
示例11: it_can_save_after_increment
def it_can_save_after_increment(self): # noqa
user = User(
email=None, user_id="i-1224242",
companies=[{'company_id': 6, 'name': 'Intercom'}])
body = {
'custom_attributes': {},
'email': "",
'user_id': 'i-1224242',
'companies': [{
'company_id': 6,
'name': 'Intercom'
}]
}
with patch.object(Client, 'post', return_value=body) as mock_method: # noqa
user.increment('mad')
eq_(user.to_dict()['custom_attributes']['mad'], 1)
self.client.users.save(user)
示例12: test_user_company
def test_user_company():
user = User()
# use a Company object
user.company = Company({
'id': 1,
'name': 'Intercom',
'created_at': datetime.fromtimestamp(1331764344)
})
# use a dict object
user.company = {
'id': 1,
'name': 'Intercom',
'created_at': datetime.fromtimestamp(1331764344)
}
raises(AttributeError, lambda: user.company)
user.company = ['foo']
示例13: test_find_all_id
def test_find_all_id(self):
from intercom.user import User
user = User.find(email=self.email)
# Iterate over all notes for a user via their email address
for note in Note.find_all(user_id=user.user_id):
self.assertTrue(note.id is not None)
user = note.user.load()
self.assertEqual(user.email, self.email)
示例14: it_presents_created_at_and_last_impression_at_as_datetime
def it_presents_created_at_and_last_impression_at_as_datetime(self):
now = datetime.utcnow()
now_ts = calendar.timegm(now.utctimetuple())
user = User.from_api(
{'created_at': now_ts, 'last_impression_at': now_ts})
self.assertIsInstance(user.created_at, datetime)
eq_(now.strftime('%c'), user.created_at.strftime('%c'))
self.assertIsInstance(user.last_impression_at, datetime)
eq_(now.strftime('%c'), user.last_impression_at.strftime('%c'))
示例15: it_can_convert
def it_can_convert(self): # noqa
lead = Lead.from_api({'user_id': 'contact_id'})
user = User.from_api({'id': 'user_id'})
with patch.object(Client, 'post', returns=get_user()) as mock_method: # noqa
self.client.leads.convert(lead, user)
mock_method.assert_called_once_with(
'/contacts/convert',
{
'contact': {'user_id': lead.user_id},
'user': {'id': user.id}
})