From e1374fac393e62f5ee414cdc22ad46a9b75a522e Mon Sep 17 00:00:00 2001 From: John Keyes Date: Tue, 24 Oct 2017 22:47:06 +0000 Subject: [PATCH] Adding waiting_since as a timestamp field. Also returning False for update_last_request_at field as it is a boolean. --- intercom/traits/api_resource.py | 15 ++++++++++++--- tests/unit/__init__.py | 1 + tests/unit/test_notification.py | 6 ++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/intercom/traits/api_resource.py b/intercom/traits/api_resource.py index af929846..f215c835 100644 --- a/intercom/traits/api_resource.py +++ b/intercom/traits/api_resource.py @@ -14,7 +14,10 @@ def type_field(attribute): def timestamp_field(attribute): - return attribute.endswith('_at') + # update_last_request_at is a boolean field, we must ignore that + if attribute == 'update_last_request_at': + return False + return attribute.endswith('_at') or attribute == 'waiting_since' def custom_attribute_field(attribute): @@ -97,10 +100,16 @@ def submittable_attribute(self, name, value): def __getattribute__(self, attribute): value = super(Resource, self).__getattribute__(attribute) + # ignore attributes we know about + if '_' == attribute[0] or attribute in self.__class__.__dict__: + return value + + # check for timestamp fields if timestamp_field(attribute): return to_datetime_value(value) - else: - return value + + # just return the value + return value def __setattr__(self, attribute, value): if typed_value(value) and not custom_attribute_field(attribute): diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index a85c92f6..f0fe37d1 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -348,6 +348,7 @@ def page_of_companies(include_next_link=False): "id": "123456789", "created_at": "1410335293", "updated_at": "1410335293", + "waiting_since": "1512020127", "user": { "type": "user", "id": "540f1de7112d3d1d51001637", diff --git a/tests/unit/test_notification.py b/tests/unit/test_notification.py index 35759aad..f2f40c9f 100644 --- a/tests/unit/test_notification.py +++ b/tests/unit/test_notification.py @@ -66,6 +66,12 @@ def it_returns_inner_conversation_parts_for_conversation(self): eq_(1, len(conversation_parts)) eq_('conversation_part', conversation_parts[0].resource_type) + @istest + def it_returns_datetimes_for_conversations(self): + payload = Notification(**test_conversation_notification) + eq_(2014, payload.data.item.created_at.year) + eq_(2017, payload.data.item.waiting_since.year) + @istest def it_returns_inner_user_object_with_nil_tags(self): user_notification = {