diff --git a/duedil/resources/__init__.py b/duedil/resources/__init__.py index 7912f63..1922a4b 100644 --- a/duedil/resources/__init__.py +++ b/duedil/resources/__init__.py @@ -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 diff --git a/tests/test_resource.py b/tests/test_resource.py index 38bf2ed..559e9fa 100644 --- a/tests/test_resource.py +++ b/tests/test_resource.py @@ -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') @@ -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): @@ -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',