|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +import os |
| 4 | +import time |
| 5 | +import unittest |
| 6 | +from datetime import datetime |
| 7 | +from intercom import Intercom |
| 8 | +from intercom.segment import Segment |
| 9 | + |
| 10 | +Intercom.app_id = os.environ.get('INTERCOM_APP_ID') |
| 11 | +Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY') |
| 12 | + |
| 13 | + |
| 14 | +class SegmentTest(unittest.TestCase): |
| 15 | + email = "ada@example.com" |
| 16 | + |
| 17 | + @classmethod |
| 18 | + def setup_class(cls): |
| 19 | + # get user |
| 20 | + cls.segment_id = "5425e77db351e072bb000017" |
| 21 | + |
| 22 | + def test_find_segment(self): |
| 23 | + # Find a segment |
| 24 | + segment = Segment.find(id=self.segment_id) |
| 25 | + self.assertEqual(segment.id, self.segment_id) |
| 26 | + |
| 27 | + def test_save_segment(self): |
| 28 | + # Update a segment |
| 29 | + segment = Segment.find(id=self.segment_id) |
| 30 | + now = datetime.utcnow() |
| 31 | + updated_name = 'Updated %s' % (time.mktime(now.timetuple())) |
| 32 | + segment.name = updated_name |
| 33 | + segment.save() |
| 34 | + segment = Segment.find(id=self.segment_id) |
| 35 | + self.assertEqual(segment.name, updated_name) |
| 36 | + |
| 37 | + def test_iterate(self): |
| 38 | + # Iterate over all segments |
| 39 | + for segment in Segment.all(): |
| 40 | + self.assertTrue(segment.id is not None) |
| 41 | + |
| 42 | + |
| 43 | + # def test_tag_users(self): |
| 44 | + # # Tag users |
| 45 | + # tag = Tag.tag_users("blue", [self.user.id]) |
| 46 | + # self.assertEqual(tag.name, "blue") |
| 47 | + |
| 48 | + # def test_untag_users(self): |
| 49 | + # # Untag users |
| 50 | + # tag = Tag.untag_users("blue", [self.user.id]) |
| 51 | + # self.assertEqual(tag.name, "blue") |
| 52 | + |
| 53 | + # def test_all(self): |
| 54 | + # # Iterate over all tags |
| 55 | + # for tag in Tag.all(): |
| 56 | + # self.assertIsNotNone(tag.id) |
| 57 | + |
| 58 | + # # def test_all_for_user_by_id(self): |
| 59 | + # # # Iterate over all tags for user |
| 60 | + # # tags = Tag.find_all_for_user(id=self.user.id) |
| 61 | + # # for tag in tags: |
| 62 | + # # self.assertIsNotNone(tag.id) |
| 63 | + |
| 64 | + # # def test_all_for_user_by_email(self): |
| 65 | + # # # Iterate over all tags for user |
| 66 | + # # tags = Tag.find_all_for_user(email=self.user.email) |
| 67 | + # # for tag in tags: |
| 68 | + # # self.assertIsNotNone(tag.id) |
| 69 | + |
| 70 | + # # def test_all_for_user_by_user_id(self): |
| 71 | + # # # Iterate over all tags for user |
| 72 | + # # tags = Tag.find_all_for_user(user_id=self.user.user_id) |
| 73 | + # # for tag in tags: |
| 74 | + # # self.assertIsNotNone(tag.id) |
| 75 | + |
| 76 | + # def test_tag_companies(self): |
| 77 | + # # Tag companies |
| 78 | + # tag = Tag.tag_companies("red", [self.user.companies[0].id]) |
| 79 | + # self.assertEqual(tag.name, "red") |
| 80 | + |
| 81 | + # def test_untag_companies(self): |
| 82 | + # # Untag companies |
| 83 | + # tag = Tag.untag_companies("blue", [self.user.companies[0].id]) |
| 84 | + # self.assertEqual(tag.name, "blue") |
| 85 | + |
| 86 | + # # # Iterate over all tags for company |
| 87 | + # # Tag.find_all_for_company(id='43357e2c3c77661e25000026') |
| 88 | + # # Tag.find_all_for_company(company_id='6') |
0 commit comments