Skip to content

Commit 512bdc9

Browse files
committed
Adding Notes test (and fixing load).
1 parent 910a1f9 commit 512bdc9

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

intercom/api_operations/load.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
class Load(object):
66

7-
@classmethod
8-
def load(cls, **params):
7+
def load(self):
8+
cls = self.__class__
99
collection = utils.resource_class_to_collection_name(cls)
10-
if 'id' in params:
11-
response = Intercom.get("/%s/%s" % (collection, params['id']))
10+
if hasattr(self, 'id'):
11+
response = Intercom.get("/%s/%s" % (collection, self.id))
1212
else:
1313
raise Exception(
1414
"Cannot load %s as it does not have a valid id." % (cls))

intercom/note.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from intercom.user import Resource
2+
from intercom.api_operations.find_all import FindAll
23
from intercom.api_operations.find import Find
34
from intercom.api_operations.save import Save
45
from intercom.api_operations.load import Load
56

67

7-
class Note(Resource, Find, Load, Save):
8+
class Note(Resource, Find, FindAll, Load, Save):
89
pass

intercom/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def resource_class_to_name(cls):
3333

3434

3535
def create_class_instance(class_name):
36+
from intercom.api_operations.load import Load
3637
from intercom.traits.api_resource import Resource
3738

3839
if class_name in CLASS_REGISTRY:
@@ -43,7 +44,7 @@ def __new__(mcs, name, bases, attributes):
4344
return super(Meta, mcs).__new__(
4445
mcs, str(class_name), bases, attributes)
4546

46-
class DynamicClass(Resource):
47+
class DynamicClass(Resource, Load):
4748
__metaclass__ = Meta
4849

4950
dyncls = DynamicClass()

tests/integration/test_notes.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
import unittest
5+
from intercom import Intercom
6+
from intercom.note import Note
7+
8+
Intercom.app_id = os.environ.get('INTERCOM_APP_ID')
9+
Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY')
10+
11+
12+
class NoteTest(unittest.TestCase):
13+
email = "ada@example.com"
14+
15+
def test_create_note(self):
16+
# Create a note for a user
17+
note = Note.create(
18+
body="<p>Text for the note</p>",
19+
email=self.email)
20+
self.assertIsNotNone(note.id)
21+
22+
def test_find_note(self):
23+
# Find a note by id
24+
orig_note = Note.create(
25+
body="<p>Text for the note</p>",
26+
email=self.email)
27+
note = Note.find(id=orig_note.id)
28+
self.assertEqual(note.body, orig_note.body)
29+
30+
def test_find_all_email(self):
31+
# Iterate over all notes for a user via their email address
32+
for note in Note.find_all(email=self.email):
33+
self.assertTrue(note.id is not None)
34+
user = note.user.load()
35+
self.assertEqual(user.email, self.email)
36+
37+
def test_find_all_id(self):
38+
from intercom.user import User
39+
user = User.find(email=self.email)
40+
41+
# Iterate over all notes for a user via their email address
42+
for note in Note.find_all(user_id=user.user_id):
43+
self.assertTrue(note.id is not None)
44+
user = note.user.load()
45+
self.assertEqual(user.email, self.email)

0 commit comments

Comments
 (0)