예제 #1
0
 def it_saves_a_user_with_companies(self):
     user = User(email="*****@*****.**",
                 user_id="i-1224242",
                 companies=[{
                     'company_id': 6,
                     'name': 'Intercom'
                 }])
     body = {
         'email': '*****@*****.**',
         'user_id': 'i-1224242',
         'companies': [{
             'company_id': 6,
             'name': 'Intercom'
         }]
     }
     with patch.object(Intercom, 'post', return_value=body) as mock_method:
         user.save()
         eq_(user.email, '*****@*****.**')
         eq_(len(user.companies), 1)
         mock_method.assert_called_once_with('/users',
                                             email="*****@*****.**",
                                             user_id="i-1224242",
                                             companies=[{
                                                 'company_id': 6,
                                                 'name': 'Intercom'
                                             }],
                                             custom_attributes={})
예제 #2
0
 def setUp(self):  # noqa
     now = time.mktime(datetime.utcnow().timetuple())
     self.user = User(email="*****@*****.**",
                      user_id="12345",
                      created_at=now,
                      name="Jim Bob")
     self.created_time = now - 300
예제 #3
0
 def it_can_save_a_user_with_a_none_email(self):
     user = User(email=None,
                 user_id="i-1224242",
                 companies=[{
                     'company_id': 6,
                     'name': 'Intercom'
                 }])
     body = {
         'custom_attributes': {},
         'email': None,
         'user_id': 'i-1224242',
         'companies': [{
             'company_id': 6,
             'name': 'Intercom'
         }]
     }
     with patch.object(Intercom, 'post', return_value=body) as mock_method:
         user.save()
         ok_(user.email is None)
         eq_(user.user_id, 'i-1224242')
         mock_method.assert_called_once_with('/users',
                                             email=None,
                                             user_id="i-1224242",
                                             companies=[{
                                                 'company_id': 6,
                                                 'name': 'Intercom'
                                             }],
                                             custom_attributes={})
예제 #4
0
    def it_allows_easy_setting_of_custom_data(self):
        now = datetime.utcnow()
        now_ts = time.mktime(now.timetuple())

        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)
예제 #5
0
 def it_to_dict_itself(self):
     created_at = datetime.utcnow()
     user = User(email="*****@*****.**",
                 user_id="12345",
                 created_at=created_at,
                 name="Jim Bob")
     as_dict = user.to_dict
     eq_(as_dict["email"], "*****@*****.**")
     eq_(as_dict["user_id"], "12345")
     eq_(as_dict["created_at"], time.mktime(created_at.timetuple()))
     eq_(as_dict["name"], "Jim Bob")
예제 #6
0
 def setUp(self):  # noqa
     created_at = datetime.utcnow()
     params = {
         'email': '*****@*****.**',
         'user_id': 'i-1224242',
         'custom_attributes': {
             'mad': 123,
             'another': 432,
             'other': time.mktime(created_at.timetuple()),
             'thing': 'yay'
         }
     }
     self.user = User(**params)
예제 #7
0
    def it_rejects_nested_data_structures_in_custom_attributes(self):
        user = User()
        with assert_raises(ValueError):
            user.custom_attributes["thing"] = [1]

        with assert_raises(ValueError):
            user.custom_attributes["thing"] = {1: 2}

        with assert_raises(ValueError):
            user.custom_attributes = {1: {2: 3}}

        user = User.from_api(get_user())
        with assert_raises(ValueError):
            user.custom_attributes["thing"] = [1]
예제 #8
0
 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)
예제 #9
0
 def it_gets_sets_rw_keys(self):
     created_at = datetime.utcnow()
     payload = {
         'email': '*****@*****.**',
         'user_id': 'abc123',
         'name': 'Bob Smith',
         'last_seen_ip': '1.2.3.4',
         'last_seen_user_agent': 'ie6',
         'created_at': time.mktime(created_at.timetuple())
     }
     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])
예제 #10
0
    def it_saves_a_user_always_sends_custom_attributes(self):
        user = User(email="*****@*****.**", user_id="i-1224242")

        body = {
            'email': '*****@*****.**',
            'user_id': 'i-1224242',
            'custom_attributes': {}
        }

        with patch.object(Intercom, 'post', return_value=body) as mock_method:
            user.save()
            eq_(user.email, '*****@*****.**')
            eq_(user.custom_attributes, {})
            mock_method.assert_called_once_with('/users',
                                                email="*****@*****.**",
                                                user_id="i-1224242",
                                                custom_attributes={})
예제 #11
0
 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(Intercom, 'post',
                       return_value=body) as mock_method:  # noqa
         user.increment('mad')
         eq_(user.to_dict['custom_attributes']['mad'], 1)
         user.save()
         ok_('email' not in user.identity_hash)
         ok_('user_id' in user.identity_hash)
예제 #12
0
 def it_throws_an_attribute_error_on_trying_to_access_an_attribute_that_has_not_been_set(
         self):  # noqa
     with assert_raises(AttributeError):
         user = User()
         user.foo_property
예제 #13
0
 def it_deletes_a_user(self):
     user = User(id="1")
     with patch.object(Intercom, 'delete', return_value={}) as mock_method:
         user = user.delete()
         eq_(user.id, "1")
         mock_method.assert_called_once_with('/users/1/')