Skip to content

Commit f53c23c

Browse files
committed
Adding Notifcation support. (intercom#31)
1 parent 8dffe43 commit f53c23c

File tree

3 files changed

+167
-3
lines changed

3 files changed

+167
-3
lines changed

intercom/notification.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# coding=utf-8
2+
3+
from intercom.user import Resource
4+
5+
6+
class Notification(Resource):
7+
8+
@property
9+
def model(self):
10+
return self.data.item
11+
12+
@property
13+
def model_type(self):
14+
return self.model.__class__
15+
16+
@property
17+
def load(self):
18+
return self.model.load

tests/unit/__init__.py

Lines changed: 111 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# coding=utf-8
2-
#
3-
# License: http://jkeyes.mit-license.org/
4-
#
52

63
import json
74
import os
@@ -174,3 +171,114 @@ def page_of_users(include_next_link=False):
174171
},
175172
"notes": []
176173
}
174+
175+
test_user_notification = {
176+
"type": "notification_event",
177+
"id": "notif_123456-56465-546546",
178+
"topic": "user.created",
179+
"app_id": "aaaaaa",
180+
"data": {
181+
"type": "notification_event_data",
182+
"item": {
183+
"type": "user",
184+
"id": "aaaaaaaaaaaaaaaaaaaaaaaa",
185+
"user_id": None,
186+
"email": "joe@example.com",
187+
"name": "Joe Schmoe",
188+
"avatar": {
189+
"type": "avatar",
190+
"image_url": None
191+
},
192+
"app_id": "aaaaa",
193+
"companies": {
194+
"type": "company.list",
195+
"companies": []
196+
},
197+
"location_data": {
198+
},
199+
"last_request_at": None,
200+
"created_at": "1401970114",
201+
"remote_created_at": None,
202+
"updated_at": "1401970114",
203+
"session_count": 0,
204+
"social_profiles": {
205+
"type": "social_profile.list",
206+
"social_profiles": []
207+
},
208+
"unsubscribed_from_emails": False,
209+
"user_agent_data": None,
210+
"tags": {
211+
"type": "tag.list",
212+
"tags": []
213+
},
214+
"segments": {
215+
"type": "segment.list",
216+
"segments": []
217+
},
218+
"custom_attributes": {
219+
}
220+
}
221+
},
222+
"delivery_status": None,
223+
"delivery_attempts": 1,
224+
"delivered_at": 0,
225+
"first_sent_at": 1410188629,
226+
"created_at": 1410188628,
227+
"links": {},
228+
"self": None
229+
}
230+
231+
test_conversation_notification = {
232+
"type": "notification_event",
233+
"id": "notif_123456-56465-546546",
234+
"topic": "conversation.user.created",
235+
"app_id": "aaaaa",
236+
"data": {
237+
"type": "notification_event_data",
238+
"item": {
239+
"type": "conversation",
240+
"id": "123456789",
241+
"created_at": "1410335293",
242+
"updated_at": "1410335293",
243+
"user": {
244+
"type": "user",
245+
"id": "540f1de7112d3d1d51001637",
246+
"name": "Kill Bill",
247+
"email": "bill@bill.bill"
248+
},
249+
"assignee": {
250+
"type": "nobody_admin",
251+
"id": None
252+
},
253+
"conversation_message": {
254+
"type": "conversation_message",
255+
"id": "321546",
256+
"subject": "",
257+
"body": "<p>An important message</p>",
258+
"author": {
259+
"type": "user",
260+
"id": "aaaaaaaaaaaaaaaaaaaaaa",
261+
"name": "Kill Bill",
262+
"email": "bill@bill.bill"
263+
},
264+
"attachments": []
265+
},
266+
"conversation_parts": {
267+
"type": "conversation_part.list",
268+
"conversation_parts": []
269+
},
270+
"open": None,
271+
"read": True,
272+
"links": {
273+
"conversation_web": "https://app.intercom.io/a/apps/aaaaaa/inbox/all/conversations/123456789"
274+
}
275+
}
276+
},
277+
"delivery_status": None,
278+
"delivery_attempts": 1,
279+
"delivered_at": 0,
280+
"first_sent_at": 1410335293,
281+
"created_at": 1410335293,
282+
"links": {},
283+
"self": None
284+
}

tests/unit/notification_spec.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from describe import expect
2+
from intercom.notification import Notification
3+
from intercom.utils import create_class_instance
4+
from tests.unit import test_user_notification
5+
from tests.unit import test_conversation_notification
6+
7+
8+
class DescribeIntercomNotification:
9+
10+
def it_converts_notification_hash_to_object(self):
11+
payload = Notification(**test_user_notification)
12+
expect(payload).to.be_instance_of(Notification)
13+
14+
def it_returns_correct_model_type_for_user(self):
15+
payload = Notification(**test_user_notification)
16+
User = create_class_instance('User')
17+
18+
expect(payload.model).to.be_instance_of(User.__class__)
19+
expect(payload.model_type) == User.__class__
20+
21+
def it_returns_correct_user_notification_topic(self):
22+
payload = Notification(**test_user_notification)
23+
expect(payload.topic) == "user.created"
24+
25+
def it_returns_instance_of_conversation(self):
26+
Conversation = create_class_instance('Conversation')
27+
payload = Notification(**test_conversation_notification)
28+
expect(payload.model).to.be_instance_of(Conversation.__class__)
29+
expect(payload.model_type) == Conversation.__class__
30+
31+
def it_returns_correct_conversation_notification_topic(self):
32+
payload = Notification(**test_conversation_notification)
33+
expect(payload.topic) == "conversation.user.created"
34+
35+
def it_returns_inner_user_object_for_conversation(self):
36+
User = create_class_instance('User')
37+
payload = Notification(**test_conversation_notification)
38+
expect(payload.model.user).to.be_instance_of(User.__class__)

0 commit comments

Comments
 (0)