diff --git a/.gitignore b/.gitignore index 9c70b99..40e494b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ build/* html/* python_reddwarfclient.egg* rdserver.txt +python-reddwarfclient.iml \ No newline at end of file diff --git a/reddwarfclient/limits.py b/reddwarfclient/limits.py index 6179312..ea4b446 100644 --- a/reddwarfclient/limits.py +++ b/reddwarfclient/limits.py @@ -16,6 +16,11 @@ from reddwarfclient import base import exceptions +RESPONSE_KEY = "limits" +ABSOLUTE = "absolute" +RATE = "rate" +LIMIT = 'limit' + class Limits(base.ManagerWithFind): """ @@ -27,7 +32,6 @@ class Limits(base.ManagerWithFind): """ Retrieve the limits """ - RESPONSE_KEY = "limits" URL = "/limits" resp, body = self.api.client.get(URL) @@ -37,5 +41,14 @@ class Limits(base.ManagerWithFind): if not body: raise Exception("Call to " + URL + " did not return a body.") - rates = body[RESPONSE_KEY]['rate'][0]['limit'] + absolute_rates = self._get_absolute_rates(body) + rates = self._get_rates(body) + return absolute_rates + rates + + def _get_rates(self, body): + rates = body[RESPONSE_KEY][RATE][0].get(LIMIT, {}) return [self.resource_class(self, res) for res in rates] + + def _get_absolute_rates(self, body): + absolute_rates = body[RESPONSE_KEY].get(ABSOLUTE, {}) + return [self.resource_class(self, absolute_rates)] diff --git a/tests/test_limits.py b/tests/test_limits.py index d1e55cd..ee26f74 100644 --- a/tests/test_limits.py +++ b/tests/test_limits.py @@ -2,12 +2,11 @@ from testtools import TestCase from mock import Mock from reddwarfclient import limits -""" -This class tests the calling code for the Limits API -""" - class LimitsTest(TestCase): + """ + This class tests the calling code for the Limits API + """ def setUp(self): super(LimitsTest, self).setUp() @@ -22,38 +21,43 @@ class LimitsTest(TestCase): resp = Mock() resp.status = 200 - body = {RESPONSE_KEY: {'rate': [ - {'limit': [ - { - "next-available": "2013-02-26T00:00:13Z", - "remaining": 100, - "unit": "MINUTE", - "value": 100, - "verb": "POST" + body = {RESPONSE_KEY: { + "absolute": { + "maxTotalInstances": 55, + "maxTotalVolumes": 100 }, - { - "next-available": "2013-02-26T00:00:13Z", - "remaining": 100, - "unit": "MINUTE", - "value": 100, - "verb": "PUT" - }, - { - "next-available": "2013-02-26T00:00:13Z", - "remaining": 100, - "unit": "MINUTE", - "value": 100, - "verb": "DELETE" - }, - { - "next-available": "2013-02-26T00:00:13Z", - "remaining": 99, - "unit": "MINUTE", - "value": 100, - "verb": "GET" - } - ] - }]}} + 'rate': [ + {'limit': [ + { + "next-available": "2013-02-26T00:00:13Z", + "remaining": 100, + "unit": "MINUTE", + "value": 100, + "verb": "POST" + }, + { + "next-available": "2013-02-26T00:00:13Z", + "remaining": 100, + "unit": "MINUTE", + "value": 100, + "verb": "PUT" + }, + { + "next-available": "2013-02-26T00:00:13Z", + "remaining": 100, + "unit": "MINUTE", + "value": 100, + "verb": "DELETE" + }, + { + "next-available": "2013-02-26T00:00:13Z", + "remaining": 99, + "unit": "MINUTE", + "value": 100, + "verb": "GET" + } + ] + }]}} response = (resp, body) mock_get = Mock(return_value=response) @@ -71,9 +75,11 @@ class LimitsTest(TestCase): resp = Mock() resp.status = status_code - body = {RESPONSE_KEY: {'rate': [ + body = {RESPONSE_KEY: { + 'absolute': {}, + 'rate': [ {'limit': [] - }]}} + }]}} response = (resp, body) mock_get = Mock(return_value=response)