Skip to content

Commit 493b3da

Browse files
committed
Ensuring identity_hash only contains variables with valid values. intercom#100
1 parent 6b883d7 commit 493b3da

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

intercom/api_operations/save.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,7 @@ def identity_hash(self):
6363
identity_vars = getattr(self, 'identity_vars', [])
6464
parts = {}
6565
for var in identity_vars:
66-
parts[var] = getattr(self, var, None)
66+
id_var = getattr(self, var, None)
67+
if id_var: # only present id var if it is not blank or None
68+
parts[var] = id_var
6769
return parts

tests/unit/test_user.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,24 @@ def it_can_call_increment_on_the_same_key_twice_and_increment_by_2(self): # noq
423423
self.user.increment('mad')
424424
self.user.increment('mad')
425425
eq_(self.user.to_dict['custom_attributes']['mad'], 125)
426+
427+
@istest
428+
def it_can_save_after_increment(self): # noqa
429+
user = User(
430+
email=None, user_id="i-1224242",
431+
companies=[{'company_id': 6, 'name': 'Intercom'}])
432+
body = {
433+
'custom_attributes': {},
434+
'email': "",
435+
'user_id': 'i-1224242',
436+
'companies': [{
437+
'company_id': 6,
438+
'name': 'Intercom'
439+
}]
440+
}
441+
with patch.object(Intercom, 'post', return_value=body) as mock_method: # noqa
442+
user.increment('mad')
443+
eq_(user.to_dict['custom_attributes']['mad'], 1)
444+
user.save()
445+
ok_('email' not in user.identity_hash)
446+
ok_('user_id' in user.identity_hash)

0 commit comments

Comments
 (0)