Skip to content

Commit

Permalink
up version, tests & history
Browse files Browse the repository at this point in the history
  • Loading branch information
nanorepublica committed Sep 30, 2015
1 parent 4cc650c commit 1dab5ee
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
5 changes: 4 additions & 1 deletion docs/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
History
=======

0.4 (2015/09/30)
0.4.4 (2015/09/30)
----------------

- Merged some changes from a fork, updated tests to match
- Refactored the api clients, restructured the resources to include all API endpoints
- Added Search resources
- Resources now work by passing an API_KEY through to them or settings the environment variable DUEDIL_API_KEY
- Resources need filling out and fixing together with related resources
- Skeletons of the International API is there & the lite API


0.3 (2015/02/27)
Expand Down
6 changes: 3 additions & 3 deletions duedil/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Resource(object):
path = None
client_class = LiteClient

def __init__(self, api_key, id, locale='uk', load=False, **kwargs):
def __init__(self, id, api_key=None, locale='uk', load=False, **kwargs):
if not self.attribute_names:
raise NotImplementedError(
"Resources must include a list of allowed attributes")
Expand Down Expand Up @@ -191,12 +191,12 @@ def load_related(self, key, klass=None):
for r in result['response']['data']:
r['locale'] = r.get('locale', self.locale)
related.append(
klass(self.client.api_key, **r) if klass else None
klass(api_key=self.client.api_key, **r) if klass else None
)
elif result:
response['locale'] = response.get('locale', self.locale)
if klass:
print(response)
related = klass(self.client.api_key, **response)
related = klass(api_key=self.client.api_key, **response)
setattr(self, internal_key, related)
return related
4 changes: 2 additions & 2 deletions duedil/resources/lite/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ class Company(six.with_metaclass(SearchableResourceMeta, Resource)):
# obj information about the company's returns
]

def __init__(self, client, company_number=None, **kwargs):
super(Company, self).__init__(client, id=company_number, **kwargs)
def __init__(self, api_key, company_number=None, **kwargs):
super(Company, self).__init__(api_key=api_key, id=company_number, **kwargs)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def run_tests(self):
sys.exit(errno)


version = '0.4.3'
version = '0.4.4'

setup(name='duedil',
version=version,
Expand Down
22 changes: 11 additions & 11 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,24 @@ class ResourceTestCase(unittest.TestCase):

def test_resource_no_allowed_attributes(self):
with self.assertRaises(NotImplementedError):
TestResource(API_KEY, 123)
TestResource(api_key=API_KEY, id=123)

def test_bad_endpoint(self):
with self.assertRaises(ValueError):
TestEndpointResource(API_KEY, 12345).endpoint
TestEndpointResource(api_key=API_KEY, id=12345).endpoint

@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'}})
res = TestAttrProResource(API_KEY, 12345, load=True)
res = TestAttrProResource(api_key=API_KEY, id=12345, load=True)
self.assertEqual(res.category, 'thing')

@requests_mock.mock()
def test_resource_set_attribute(self, m):
m.register_uri('GET', 'http://api.duedil.com/open/uk/test/12345.json',
json={'response': {'name': 'Duedil', 'id': 12345, 'category': None}})
res = TestAttrResource(API_KEY, 12345, name="Duedil")
res = TestAttrResource(api_key=API_KEY, id=12345, name="Duedil")

self.assertEqual(res.id, 12345)
self.assertEqual(res.name, 'Duedil')
Expand All @@ -114,7 +114,7 @@ def test_load_on_get(self, m):
m.register_uri('GET', 'http://duedil.io/v3/uk/resources/12345.json',
json={'response': {'name': 'Duedil', 'id': 12345}})

res = TestProResource(API_KEY, id=12345)
res = TestProResource(api_key=API_KEY, id=12345)
name = res.name
self.assertEqual(name, 'Duedil')
with self.assertRaises(AttributeError):
Expand All @@ -131,7 +131,7 @@ def test_load_related(self, m):
'name': 'Duedil',
'id': '67890'
}})
res = TestHasRelatedResources(API_KEY, id=12345)
res = TestHasRelatedResources(api_key=API_KEY, id=12345)
related = res.test_related
self.assertIsInstance(related, TestRelatedResource)

Expand All @@ -143,7 +143,7 @@ def test_load_related_string(self, m):
'name': 'Duedil',
'id': '67890'
}})
res = TestHasRelatedResources(API_KEY, id=12345)
res = TestHasRelatedResources(api_key=API_KEY, id=12345)
related = res.test_string
self.assertIsInstance(related, Company)

Expand All @@ -155,7 +155,7 @@ def test_load_related_loadable(self, m):
'name': 'Duedil',
'id': '67890'
}})
res = TestHasRelatedResources(API_KEY, id=12345)
res = TestHasRelatedResources(api_key=API_KEY, id=12345)
related = res.test_loadable
self.assertIsInstance(related, TestRelatedProResource)
self.assertIs(related.client.api_key, API_KEY)
Expand All @@ -169,7 +169,7 @@ def test_load_related_list(self, m):
'name': 'Duedil',
'id': '67890'
}]}})
res = TestHasRelatedResources(API_KEY, id=12345)
res = TestHasRelatedResources(api_key=API_KEY, id=12345)
related = res.test_related_list
self.assertIsInstance(related[0], TestRelatedListResource)

Expand All @@ -178,7 +178,7 @@ def test_load_related_list(self, m):
class LiteCompanyTestCase(unittest.TestCase):

def test_company_number(self):
company = LiteCompany(API_KEY, company_number=12345)
company = LiteCompany(api_key=API_KEY, company_number=12345)
self.assertEqual(company.id, 12345)

@requests_mock.mock()
Expand All @@ -187,7 +187,7 @@ def test_load_company_number(self, m):
json={'name': 'Duedil',
'company_number': "12345"})

company = LiteCompany(API_KEY, company_number=12345)
company = LiteCompany(api_key=API_KEY, company_number=12345)
self.assertEqual(company.name, 'Duedil')


Expand Down

0 comments on commit 1dab5ee

Please sign in to comment.