当前位置: 首页>>代码示例>>Python>>正文


Python User.to_dict方法代码示例

本文整理汇总了Python中intercom.user.User.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python User.to_dict方法的具体用法?Python User.to_dict怎么用?Python User.to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在intercom.user.User的用法示例。


在下文中一共展示了User.to_dict方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: it_gets_sets_rw_keys

# 需要导入模块: from intercom.user import User [as 别名]
# 或者: from intercom.user.User import to_dict [as 别名]
 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])
开发者ID:jkeyes,项目名称:python-intercom,代码行数:18,代码来源:test_user.py

示例2: it_allows_easy_setting_of_multiple_companies

# 需要导入模块: from intercom.user import User [as 别名]
# 或者: from intercom.user.User import to_dict [as 别名]
 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)
开发者ID:jkeyes,项目名称:python-intercom,代码行数:10,代码来源:test_user.py

示例3: it_to_dict_itself

# 需要导入模块: from intercom.user import User [as 别名]
# 或者: from intercom.user.User import to_dict [as 别名]
 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")
开发者ID:jkeyes,项目名称:python-intercom,代码行数:12,代码来源:test_user.py

示例4: it_allows_easy_setting_of_custom_data

# 需要导入模块: from intercom.user import User [as 别名]
# 或者: from intercom.user.User import to_dict [as 别名]
    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)
开发者ID:jkeyes,项目名称:python-intercom,代码行数:12,代码来源:test_user.py

示例5: it_can_save_after_increment

# 需要导入模块: from intercom.user import User [as 别名]
# 或者: from intercom.user.User import to_dict [as 别名]
 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)
开发者ID:jkeyes,项目名称:python-intercom,代码行数:19,代码来源:test_user.py

示例6: DescribeIncrementingCustomAttributeFields

# 需要导入模块: from intercom.user import User [as 别名]
# 或者: from intercom.user.User import to_dict [as 别名]
class DescribeIncrementingCustomAttributeFields(unittest.TestCase):

    def setUp(self):  # noqa
        self.client = Client()

        created_at = datetime.utcnow()
        params = {
            'email': '[email protected]',
            'user_id': 'i-1224242',
            'custom_attributes': {
                'mad': 123,
                'another': 432,
                'other': time.mktime(created_at.timetuple()),
                'thing': 'yay',
                'logins': None,
            }
        }
        self.user = User(**params)

    @istest
    def it_increments_up_by_1_with_no_args(self):
        self.user.increment('mad')
        eq_(self.user.to_dict()['custom_attributes']['mad'], 124)

    @istest
    def it_increments_up_by_given_value(self):
        self.user.increment('mad', 4)
        eq_(self.user.to_dict()['custom_attributes']['mad'], 127)

    @istest
    def it_increments_down_by_given_value(self):
        self.user.increment('mad', -1)
        eq_(self.user.to_dict()['custom_attributes']['mad'], 122)

    @istest
    def it_can_increment_new_custom_data_fields(self):
        self.user.increment('new_field', 3)
        eq_(self.user.to_dict()['custom_attributes']['new_field'], 3)

    @istest
    def it_can_increment_none_values(self):
        self.user.increment('logins')
        eq_(self.user.to_dict()['custom_attributes']['logins'], 1)

    @istest
    def it_can_call_increment_on_the_same_key_twice_and_increment_by_2(self):  # noqa
        self.user.increment('mad')
        self.user.increment('mad')
        eq_(self.user.to_dict()['custom_attributes']['mad'], 125)

    @istest
    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)
开发者ID:jkeyes,项目名称:python-intercom,代码行数:70,代码来源:test_user.py


注:本文中的intercom.user.User.to_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。