Skip to content

Commit

Permalink
Checking for Company before dict in setter (as Company is a dict subc…
Browse files Browse the repository at this point in the history
…lass).
  • Loading branch information
jkeyes committed Nov 26, 2013
1 parent a498f97 commit 67a857e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions intercom/user.py
Expand Up @@ -317,10 +317,10 @@ def company(self, company):
>>> user.company = {'id':6, 'name': 'Intercom', 'created_at': 103201}
"""
if isinstance(company, dict):
self['companies'] = [Company(**company)]
elif isinstance(company, Company):
if isinstance(company, Company):
self['companies'] = [company]
elif isinstance(company, dict):
self['companies'] = [Company(**company)]
else:
raise ValueError("company must be set as a dict or Company object")

Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_user.py
Expand Up @@ -162,6 +162,13 @@ def test_company_properties():
@raises(ValueError)
def test_user_company():
user = User()
# use a Company object
user.company = Company({
'id': 1,
'name': 'Intercom',
'created_at': datetime.fromtimestamp(1331764344)
})

# use a dict object
user.company = {
'id': 1,
Expand Down

0 comments on commit 67a857e

Please sign in to comment.