|
4 | 4 | import unittest
|
5 | 5 | from intercom import Intercom
|
6 | 6 | from intercom import Tag
|
| 7 | +from intercom import User |
| 8 | +from intercom import Company |
7 | 9 | from . import delete
|
8 | 10 | from . import get_or_create_company
|
9 | 11 | from . import get_or_create_user
|
@@ -32,47 +34,68 @@ def teardown_class(cls):
|
32 | 34 |
|
33 | 35 | def test_tag_users(self):
|
34 | 36 | # Tag users
|
35 |
| - tag = Tag.tag_users("blue", [self.user.id]) |
36 |
| - self.assertEqual(tag.name, "blue") |
| 37 | + tag = Tag.tag_users('blue', [self.user.id]) |
| 38 | + self.assertEqual(tag.name, 'blue') |
| 39 | + user = User.find(email=self.user.email) |
| 40 | + self.assertEqual(1, len(user.tags)) |
37 | 41 |
|
38 | 42 | def test_untag_users(self):
|
39 | 43 | # Untag users
|
40 |
| - tag = Tag.untag_users("blue", [self.user.id]) |
41 |
| - self.assertEqual(tag.name, "blue") |
| 44 | + tag = Tag.untag_users('blue', [self.user.id]) |
| 45 | + self.assertEqual(tag.name, 'blue') |
| 46 | + user = User.find(email=self.user.email) |
| 47 | + self.assertEqual(0, len(user.tags)) |
42 | 48 |
|
43 | 49 | def test_all(self):
|
44 | 50 | # Iterate over all tags
|
45 | 51 | for tag in Tag.all():
|
46 | 52 | self.assertIsNotNone(tag.id)
|
47 | 53 |
|
48 |
| - # def test_all_for_user_by_id(self): |
49 |
| - # # Iterate over all tags for user |
50 |
| - # tags = Tag.find_all_for_user(id=self.user.id) |
51 |
| - # for tag in tags: |
52 |
| - # self.assertIsNotNone(tag.id) |
| 54 | + def test_all_for_user_by_id(self): |
| 55 | + # Iterate over all tags for user |
| 56 | + tags = Tag.find_all_for_user(id=self.user.id) |
| 57 | + for tag in tags: |
| 58 | + self.assertIsNotNone(tag.id) |
53 | 59 |
|
54 |
| - # def test_all_for_user_by_email(self): |
55 |
| - # # Iterate over all tags for user |
56 |
| - # tags = Tag.find_all_for_user(email=self.user.email) |
57 |
| - # for tag in tags: |
58 |
| - # self.assertIsNotNone(tag.id) |
| 60 | + def test_all_for_user_by_email(self): |
| 61 | + # Iterate over all tags for user |
| 62 | + tags = Tag.find_all_for_user(email=self.user.email) |
| 63 | + for tag in tags: |
| 64 | + self.assertIsNotNone(tag.id) |
59 | 65 |
|
60 |
| - # def test_all_for_user_by_user_id(self): |
61 |
| - # # Iterate over all tags for user |
62 |
| - # tags = Tag.find_all_for_user(user_id=self.user.user_id) |
63 |
| - # for tag in tags: |
64 |
| - # self.assertIsNotNone(tag.id) |
| 66 | + def test_all_for_user_by_user_id(self): |
| 67 | + # Iterate over all tags for user |
| 68 | + tags = Tag.find_all_for_user(user_id=self.user.user_id) |
| 69 | + for tag in tags: |
| 70 | + self.assertIsNotNone(tag.id) |
65 | 71 |
|
66 | 72 | def test_tag_companies(self):
|
67 | 73 | # Tag companies
|
68 | 74 | tag = Tag.tag_companies("red", [self.user.companies[0].id])
|
69 | 75 | self.assertEqual(tag.name, "red")
|
| 76 | + company = Company.find(id=self.user.companies[0].id) |
| 77 | + self.assertEqual(1, len(company.tags)) |
70 | 78 |
|
71 | 79 | def test_untag_companies(self):
|
72 | 80 | # Untag companies
|
73 |
| - tag = Tag.untag_companies("blue", [self.user.companies[0].id]) |
74 |
| - self.assertEqual(tag.name, "blue") |
| 81 | + tag = Tag.untag_companies("red", [self.user.companies[0].id]) |
| 82 | + self.assertEqual(tag.name, "red") |
| 83 | + company = Company.find(id=self.user.companies[0].id) |
| 84 | + self.assertEqual(0, len(company.tags)) |
| 85 | + |
| 86 | + # Iterate over all tags for company |
| 87 | + def test_all_for_company_by_id(self): |
| 88 | + # Iterate over all tags for user |
| 89 | + red_tag = Tag.tag_companies("red", [self.company.id]) |
| 90 | + tags = Tag.find_all_for_company(id=self.company.id) |
| 91 | + for tag in tags: |
| 92 | + self.assertEqual(red_tag.id, tag.id) |
| 93 | + Tag.untag_companies("red", [self.company.id]) |
75 | 94 |
|
76 |
| - # # Iterate over all tags for company |
77 |
| - # Tag.find_all_for_company(id='43357e2c3c77661e25000026') |
78 |
| - # Tag.find_all_for_company(company_id='6') |
| 95 | + def test_all_for_company_by_company_id(self): |
| 96 | + # Iterate over all tags for user |
| 97 | + red_tag = Tag.tag_companies("red", [self.company.id]) |
| 98 | + tags = Tag.find_all_for_company(company_id=self.company.id) |
| 99 | + for tag in tags: |
| 100 | + self.assertEqual(red_tag.id, tag.id) |
| 101 | + Tag.untag_companies("red", [self.company.id]) |
0 commit comments