|
1 | 1 | # -*- coding: utf-8 -*-
|
| 2 | +"""Integration test for Intercom Counts.""" |
2 | 3 |
|
3 | 4 | import os
|
4 | 5 | import unittest
|
5 |
| -from intercom import Intercom |
6 |
| -from intercom import Company |
7 |
| -from intercom import Count |
8 |
| -from intercom import Segment |
9 |
| -from intercom import Tag |
10 |
| -from intercom import User |
| 6 | +from intercom.client import Client |
11 | 7 | from nose.tools import eq_
|
12 | 8 | from nose.tools import ok_
|
| 9 | +from . import delete_company |
| 10 | +from . import delete_user |
13 | 11 | from . import get_timestamp
|
14 | 12 | from . import get_or_create_company
|
15 | 13 | from . import get_or_create_user
|
16 |
| -from . import delete |
17 | 14 |
|
18 |
| -Intercom.app_id = os.environ.get('INTERCOM_APP_ID') |
19 |
| -Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY') |
| 15 | +intercom = Client( |
| 16 | + os.environ.get('INTERCOM_PERSONAL_ACCESS_TOKEN')) |
20 | 17 |
|
21 | 18 |
|
22 | 19 | class CountTest(unittest.TestCase):
|
23 | 20 |
|
24 | 21 | @classmethod
|
25 | 22 | def setup_class(cls):
|
26 | 23 | nowstamp = get_timestamp()
|
27 |
| - cls.company = get_or_create_company(nowstamp) |
28 |
| - cls.user = get_or_create_user(nowstamp) |
| 24 | + cls.company = get_or_create_company(intercom, nowstamp) |
| 25 | + cls.user = get_or_create_user(intercom, nowstamp) |
29 | 26 |
|
30 | 27 | @classmethod
|
31 | 28 | def teardown_class(cls):
|
32 |
| - delete(cls.company) |
33 |
| - delete(cls.user) |
| 29 | + delete_company(intercom, cls.company) |
| 30 | + delete_user(intercom, cls.user) |
34 | 31 |
|
35 | 32 | def test_user_counts_for_each_tag(self):
|
36 | 33 | # Get User Tag Count Object
|
37 |
| - Tag.tag_users('blue', [self.user.id]) |
38 |
| - counts = Count.user_counts_for_each_tag |
39 |
| - Tag.untag_users('blue', [self.user.id]) |
40 |
| - for count in counts: |
| 34 | + intercom.tags.tag(name='blue', users=[{'id': self.user.id}]) |
| 35 | + counts = intercom.counts.for_type(type='user', count='tag') |
| 36 | + intercom.tags.untag(name='blue', users=[{'id': self.user.id}]) |
| 37 | + for count in counts.user['tag']: |
41 | 38 | if 'blue' in count:
|
42 | 39 | eq_(count['blue'], 1)
|
43 | 40 |
|
44 | 41 | def test_user_counts_for_each_segment(self):
|
45 | 42 | # Get User Segment Count Object
|
46 |
| - counts = Count.user_counts_for_each_segment |
| 43 | + counts = intercom.counts.for_type(type='user', count='segment') |
47 | 44 | ok_(counts)
|
48 | 45 |
|
49 | 46 | def test_company_counts_for_each_segment(self):
|
50 | 47 | # Get Company Segment Count Object
|
51 |
| - counts = Count.company_counts_for_each_segment |
| 48 | + counts = intercom.counts.for_type(type='company', count='segment') |
52 | 49 | ok_(counts)
|
53 | 50 |
|
54 | 51 | def test_company_counts_for_each_tag(self):
|
55 | 52 | # Get Company Tag Count Object
|
56 |
| - Tag.tag_companies('blue', [self.company.id]) |
57 |
| - counts = Count.company_counts_for_each_tag |
58 |
| - Tag.untag_companies('blue', [self.company.id]) |
59 |
| - # for count in counts: |
60 |
| - # if 'blue' in count: |
61 |
| - # eq_(count['blue'], 1) |
| 53 | + intercom.tags.tag(name='blue', companies=[{'id': self.company.id}]) |
| 54 | + intercom.counts.for_type(type='company', count='tag') |
| 55 | + intercom.tags.untag(name='blue', companies=[{'id': self.company.id}]) |
62 | 56 |
|
63 | 57 | def test_company_counts_for_each_user(self):
|
64 | 58 | # Get Company User Count Object
|
65 | 59 | self.user.companies = [
|
66 | 60 | {"company_id": self.company.company_id}
|
67 | 61 | ]
|
68 |
| - self.user.save() |
69 |
| - counts = Count.company_counts_for_each_user |
70 |
| - for count in counts: |
| 62 | + intercom.users.save(self.user) |
| 63 | + counts = intercom.counts.for_type(type='company', count='user') |
| 64 | + for count in counts.company['user']: |
71 | 65 | if self.company.name in count:
|
72 | 66 | eq_(count[self.company.name], 1)
|
73 | 67 |
|
74 |
| - def test_total_company_count(self): |
75 |
| - ok_(Company.count() >= 0) |
76 |
| - |
77 |
| - def test_total_user_count(self): |
78 |
| - ok_(User.count() >= 0) |
79 |
| - |
80 |
| - def test_total_segment_count(self): |
81 |
| - ok_(Segment.count() >= 0) |
82 |
| - |
83 |
| - def test_total_tag_count(self): |
84 |
| - ok_(Tag.count() >= 0) |
| 68 | + def test_global(self): |
| 69 | + counts = intercom.counts.for_app() |
| 70 | + ok_(counts.company >= 0) |
| 71 | + ok_(counts.tag >= 0) |
| 72 | + ok_(counts.segment >= 0) |
| 73 | + ok_(counts.user >= 0) |
| 74 | + ok_(counts.lead >= 0) |
0 commit comments