Skip to content

Commit 1f4fb5c

Browse files
committed
Adding Tag tests (not complete).
1 parent 672f418 commit 1f4fb5c

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

tests/integration/test_tags.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
import unittest
5+
from intercom import Intercom
6+
from intercom.tag import Tag
7+
from intercom.user import User
8+
9+
Intercom.app_id = os.environ.get('INTERCOM_APP_ID')
10+
Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY')
11+
12+
13+
class TagTest(unittest.TestCase):
14+
email = "ada@example.com"
15+
16+
@classmethod
17+
def setup_class(cls):
18+
# get user
19+
cls.user = User.find(email=cls.email)
20+
if not hasattr(cls.user, 'user_id'):
21+
# Create a user
22+
cls.user = User.create(
23+
email=cls.email,
24+
user_id="ada",
25+
name="Ada Lovelace")
26+
cls.user.companies = [
27+
{"company_id": 6, "name": "Intercom"},
28+
{"company_id": 9, "name": "Test Company"}
29+
]
30+
cls.user.save()
31+
32+
def test_tag_users(self):
33+
# Tag users
34+
tag = Tag.tag_users("blue", [self.user.id])
35+
self.assertEqual(tag.name, "blue")
36+
37+
def test_untag_users(self):
38+
# Untag users
39+
tag = Tag.untag_users("blue", [self.user.id])
40+
self.assertEqual(tag.name, "blue")
41+
42+
def test_all(self):
43+
# Iterate over all tags
44+
for tag in Tag.all():
45+
self.assertIsNotNone(tag.id)
46+
47+
# def test_all_for_user_by_id(self):
48+
# # Iterate over all tags for user
49+
# tags = Tag.find_all_for_user(id=self.user.id)
50+
# for tag in tags:
51+
# self.assertIsNotNone(tag.id)
52+
53+
# def test_all_for_user_by_email(self):
54+
# # Iterate over all tags for user
55+
# tags = Tag.find_all_for_user(email=self.user.email)
56+
# for tag in tags:
57+
# self.assertIsNotNone(tag.id)
58+
59+
# def test_all_for_user_by_user_id(self):
60+
# # Iterate over all tags for user
61+
# tags = Tag.find_all_for_user(user_id=self.user.user_id)
62+
# for tag in tags:
63+
# self.assertIsNotNone(tag.id)
64+
65+
def test_tag_companies(self):
66+
# Tag companies
67+
tag = Tag.tag_companies("red", [self.user.companies[0].id])
68+
self.assertEqual(tag.name, "red")
69+
70+
def test_untag_companies(self):
71+
# Untag companies
72+
tag = Tag.untag_companies("blue", [self.user.companies[0].id])
73+
self.assertEqual(tag.name, "blue")
74+
75+
# # Iterate over all tags for company
76+
# Tag.find_all_for_company(id='43357e2c3c77661e25000026')
77+
# Tag.find_all_for_company(company_id='6')

0 commit comments

Comments
 (0)