Add absolute limits to api call for rd cli

Implements: https://blueprints.launchpad.net/reddwarf/+spec/rate-limits
Change-Id: I525bbdb7e58c100a3fbd29493a06e3aee9417cc9
This commit is contained in:
daniel-a-nguyen 2013-03-06 15:36:00 -08:00
parent 8eee9613d8
commit b2cfa3d465
3 changed files with 59 additions and 39 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ build/*
html/*
python_reddwarfclient.egg*
rdserver.txt
python-reddwarfclient.iml

View File

@ -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)]

View File

@ -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)