Skip to content

Commit 230e20f

Browse files
committed
Update test to use new client style.
1 parent 94791e4 commit 230e20f

File tree

1 file changed

+29
-39
lines changed

1 file changed

+29
-39
lines changed

tests/integration/test_count.py

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,74 @@
11
# -*- coding: utf-8 -*-
2+
"""Integration test for Intercom Counts."""
23

34
import os
45
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
117
from nose.tools import eq_
128
from nose.tools import ok_
9+
from . import delete_company
10+
from . import delete_user
1311
from . import get_timestamp
1412
from . import get_or_create_company
1513
from . import get_or_create_user
16-
from . import delete
1714

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'))
2017

2118

2219
class CountTest(unittest.TestCase):
2320

2421
@classmethod
2522
def setup_class(cls):
2623
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)
2926

3027
@classmethod
3128
def teardown_class(cls):
32-
delete(cls.company)
33-
delete(cls.user)
29+
delete_company(intercom, cls.company)
30+
delete_user(intercom, cls.user)
3431

3532
def test_user_counts_for_each_tag(self):
3633
# 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']:
4138
if 'blue' in count:
4239
eq_(count['blue'], 1)
4340

4441
def test_user_counts_for_each_segment(self):
4542
# Get User Segment Count Object
46-
counts = Count.user_counts_for_each_segment
43+
counts = intercom.counts.for_type(type='user', count='segment')
4744
ok_(counts)
4845

4946
def test_company_counts_for_each_segment(self):
5047
# Get Company Segment Count Object
51-
counts = Count.company_counts_for_each_segment
48+
counts = intercom.counts.for_type(type='company', count='segment')
5249
ok_(counts)
5350

5451
def test_company_counts_for_each_tag(self):
5552
# 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}])
6256

6357
def test_company_counts_for_each_user(self):
6458
# Get Company User Count Object
6559
self.user.companies = [
6660
{"company_id": self.company.company_id}
6761
]
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']:
7165
if self.company.name in count:
7266
eq_(count[self.company.name], 1)
7367

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

Comments
 (0)