|
1 | | -# -*- coding: utf-8 -*- |
| 1 | +# -*- coding: utf-8 -*- # noqa |
2 | 2 |
|
3 | 3 | import intercom |
4 | 4 | import unittest |
|
9 | 9 | from mock import patch |
10 | 10 | from nose.tools import assert_raises |
11 | 11 | from nose.tools import eq_ |
| 12 | +from nose.tools import ok_ |
12 | 13 | from nose.tools import istest |
| 14 | +from tests.unit import page_of_companies |
13 | 15 |
|
14 | 16 |
|
15 | | -class CompanyTest(unittest.TestCase): |
| 17 | +class CompanyTest(unittest.TestCase): # noqa |
16 | 18 |
|
17 | | - def setUp(self): |
| 19 | + def setUp(self): # noqa |
18 | 20 | self.client = Client() |
19 | 21 |
|
20 | 22 | @istest |
21 | | - def it_raises_error_if_no_response_on_find(self): |
| 23 | + def it_raises_error_if_no_response_on_find(self): # noqa |
22 | 24 | with patch.object(Client, 'get', return_value=None) as mock_method: |
23 | 25 | with assert_raises(intercom.HttpError): |
24 | 26 | self.client.companies.find(company_id='4') |
25 | 27 | mock_method.assert_called_once_with('/companies', {'company_id': '4'}) |
26 | 28 |
|
27 | 29 | @istest |
28 | | - def it_raises_error_if_no_response_on_find_all(self): |
| 30 | + def it_raises_error_if_no_response_on_find_all(self): # noqa |
29 | 31 | with patch.object(Client, 'get', return_value=None) as mock_method: |
30 | 32 | with assert_raises(intercom.HttpError): |
31 | 33 | [x for x in self.client.companies.all()] |
32 | 34 | mock_method.assert_called_once_with('/companies', {}) |
33 | 35 |
|
34 | 36 | @istest |
35 | | - def it_raises_error_on_load(self): |
| 37 | + def it_raises_error_on_load(self): # noqa |
36 | 38 | company = Company() |
37 | 39 | company.id = '4' |
38 | 40 | side_effect = [None] |
39 | | - with patch.object(Client, 'get', side_effect=side_effect) as mock_method: # noqa |
| 41 | + with patch.object(Client, 'get', side_effect=side_effect) as mock_method: |
40 | 42 | with assert_raises(intercom.HttpError): |
41 | 43 | self.client.companies.load(company) |
42 | 44 | eq_([call('/companies/4', {})], mock_method.mock_calls) |
| 45 | + |
| 46 | + @istest |
| 47 | + def it_gets_companies_by_tag(self): # noqa |
| 48 | + with patch.object(Client, 'get', return_value=page_of_companies(False)) as mock_method: |
| 49 | + companies = self.client.companies.by_tag(124) |
| 50 | + for company in companies: |
| 51 | + ok_(hasattr(company, 'company_id')) |
| 52 | + eq_([call('/companies?tag_id=124', {})], mock_method.mock_calls) |
0 commit comments