Skip to content

Commit 4293857

Browse files
committed
Adding new company test to check for empty responses.
1 parent 7b47de7 commit 4293857

File tree

6 files changed

+61
-0
lines changed

6 files changed

+61
-0
lines changed

intercom/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import datetime
44
from json import JSONEncoder
55
from .errors import ArgumentError
6+
from .errors import HttpError
67
from .lib.setter_property import SetterProperty
78

89
import copy

intercom/api_operations/find.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from intercom import HttpError
12
from intercom import Intercom
23
from intercom import utils
34

@@ -11,4 +12,8 @@ def find(cls, **params):
1112
response = Intercom.get("/%s/%s" % (collection, params['id']))
1213
else:
1314
response = Intercom.get("/%s" % (collection), **params)
15+
16+
if response is None:
17+
raise HttpError('Http Error - No response entity returned')
18+
1419
return cls(**response)

intercom/api_operations/load.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from intercom import HttpError
12
from intercom import Intercom
23
from intercom import utils
34

@@ -12,4 +13,8 @@ def load(self):
1213
else:
1314
raise Exception(
1415
"Cannot load %s as it does not have a valid id." % (cls))
16+
17+
if response is None:
18+
raise HttpError('Http Error - No response entity returned')
19+
1520
return cls(**response)

intercom/collection_proxy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from intercom import HttpError
12
from intercom import Intercom
23

34

@@ -63,6 +64,9 @@ def get_page(self, url, params={}):
6364
raise StopIteration
6465

6566
response = Intercom.get(url, **params)
67+
if response is None:
68+
raise HttpError('Http Error - No response entity returned')
69+
6670
collection = response[self.collection]
6771
# if there are no resources in the response stop iterating
6872
if collection is None:

intercom/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
class ArgumentError(ValueError):
22
pass
3+
4+
5+
class HttpError(Exception):
6+
pass

tests/unit/company_spec.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import httpretty
2+
import json
3+
import re
4+
from describe import expect
5+
import intercom
6+
from intercom.company import Company
7+
8+
get = httpretty.GET
9+
r = re.compile
10+
11+
12+
class DescribeIntercomCompany2:
13+
14+
@httpretty.activate
15+
def it_raises_error_if_no_response_on_find(self):
16+
httpretty.register_uri(
17+
get, r(r'/companies$'), body=None, status=200)
18+
with expect.to_raise_error(intercom.HttpError):
19+
Company.find(company_id='4')
20+
21+
@httpretty.activate
22+
def it_raises_error_if_no_response_on_find_all(self):
23+
httpretty.register_uri(
24+
get, r(r'/companies$'), body=None, status=200)
25+
with expect.to_raise_error(intercom.HttpError):
26+
[x for x in Company.all()]
27+
28+
@httpretty.activate
29+
def it_raises_error_on_load(self):
30+
data = {
31+
'type': 'user',
32+
'id': 'aaaaaaaaaaaaaaaaaaaaaaaa',
33+
'company_id': '4',
34+
'name': 'MyCo'
35+
}
36+
httpretty.register_uri(
37+
get, r(r'/companies$'), body=json.dumps(data), status=200)
38+
company = Company.find(company_id='4')
39+
httpretty.register_uri(
40+
get, r(r'/companies/aaaaaaaaaaaaaaaaaaaaaaaa$'), body=None, status=200) # noqa
41+
with expect.to_raise_error(intercom.HttpError):
42+
company.load()

0 commit comments

Comments
 (0)