Skip to content

Commit

Permalink
PR comments PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
nanorepublica committed Jun 9, 2017
1 parent 87d3c39 commit dd0e40e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
3 changes: 2 additions & 1 deletion duedil/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def __getitem__(self, key):
raise KeyError(key)

def __iter__(self):
attributes = self.attribute_names if 'id' in self.attribute_names else self.attribute_names + ['id']
attributes = (self.attribute_names if 'id' in self.attribute_names
else self.attribute_names + ['id'])
for prop in attributes:
if hasattr(self, prop):
yield prop
Expand Down
28 changes: 16 additions & 12 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_bad_endpoint(self):
@requests_mock.mock()
def test_load_resource(self, m):
m.register_uri('GET', 'http://duedil.io/v3/uk/test/12345.json',
json={"response":{'name': 'Duedil', 'id': 12345, 'category': 'thing'}})
json={"response": {'name': 'Duedil', 'id': 12345, 'category': 'thing'}})
res = TestAttrProResource(api_key=API_KEY, id=12345, load=True)
self.assertEqual(res.category, 'thing')

Expand All @@ -116,10 +116,11 @@ def test_resource_set_attribute(self, m):
@requests_mock.mock()
def test_get_attribute(self, m):
m.register_uri('GET', 'http://duedil.io/v3/uk/test/12345.json',
json={"response": {'name': 'Duedil',
'id': 12345,
'category': 'thing',
'turnover': 1000}
json={"response": {
'name': 'Duedil',
'id': 12345,
'category': 'thing',
'turnover': 1000}
})
res = TestAttrProResource(api_key=API_KEY, id=12345)
with self.assertRaises(AttributeError):
Expand All @@ -128,22 +129,25 @@ def test_get_attribute(self, m):
res['does_not_exist']
self.assertEqual(res.category, 'thing')
self.assertEqual(res['turnover'], 1000)

@requests_mock.mock()
def test_get_attribute(self, m):
def test_get_items(self, m):
m.register_uri('GET', 'http://duedil.io/v3/uk/test/12345.json',
json={"response": {'name': 'Duedil',
'id': 12345,
'category': 'thing'}
json={"response": {
'name': 'Duedil',
'id': 12345,
'category': 'thing'}
})
res = TestAttrProResource(api_key=API_KEY, id=12345)
items = res.items()
self.assertEqual(list(items), [('name', 'Duedil'), ('id', 12345), ('category', 'thing'), ('turnover', None)])
self.assertEqual(list(items), [('name', 'Duedil'),
('id', 12345),
('category', 'thing'),
('turnover', None)])


class ProResourceTestCase(unittest.TestCase):


@requests_mock.mock()
def test_load_on_get(self, m):
m.register_uri('GET', 'http://duedil.io/v3/uk/resources/12345.json',
Expand Down

0 comments on commit dd0e40e

Please sign in to comment.