2013-02-25 21:18:51 -08:00
|
|
|
from testtools import TestCase
|
|
|
|
from mock import Mock
|
2013-09-26 22:26:02 -07:00
|
|
|
from troveclient.v1 import limits
|
2013-02-25 21:18:51 -08:00
|
|
|
|
|
|
|
|
|
|
|
class LimitsTest(TestCase):
|
2013-03-06 15:36:00 -08:00
|
|
|
"""
|
|
|
|
This class tests the calling code for the Limits API
|
|
|
|
"""
|
2013-02-25 21:18:51 -08:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(LimitsTest, self).setUp()
|
|
|
|
self.limits = limits.Limits(Mock())
|
|
|
|
self.limits.api.client = Mock()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(LimitsTest, self).tearDown()
|
|
|
|
|
2013-03-12 16:15:04 -07:00
|
|
|
def test_list(self):
|
2013-02-25 21:18:51 -08:00
|
|
|
resp = Mock()
|
2013-09-26 22:26:02 -07:00
|
|
|
resp.status_code = 200
|
2013-03-12 16:15:04 -07:00
|
|
|
body = {"limits":
|
|
|
|
[
|
|
|
|
{'maxTotalInstances': 55,
|
|
|
|
'verb': 'ABSOLUTE',
|
|
|
|
'maxTotalVolumes': 100},
|
|
|
|
{'regex': '.*',
|
|
|
|
'nextAvailable': '2011-07-21T18:17:06Z',
|
|
|
|
'uri': '*',
|
|
|
|
'value': 10,
|
|
|
|
'verb': 'POST',
|
|
|
|
'remaining': 2, 'unit': 'MINUTE'},
|
|
|
|
{'regex': '.*',
|
|
|
|
'nextAvailable': '2011-07-21T18:17:06Z',
|
|
|
|
'uri': '*',
|
|
|
|
'value': 10,
|
|
|
|
'verb': 'PUT',
|
|
|
|
'remaining': 2,
|
|
|
|
'unit': 'MINUTE'},
|
|
|
|
{'regex': '.*',
|
|
|
|
'nextAvailable': '2011-07-21T18:17:06Z',
|
|
|
|
'uri': '*',
|
|
|
|
'value': 10,
|
|
|
|
'verb': 'DELETE',
|
|
|
|
'remaining': 2,
|
|
|
|
'unit': 'MINUTE'},
|
|
|
|
{'regex': '.*',
|
|
|
|
'nextAvailable': '2011-07-21T18:17:06Z',
|
|
|
|
'uri': '*',
|
|
|
|
'value': 10,
|
|
|
|
'verb': 'GET',
|
|
|
|
'remaining': 2, 'unit': 'MINUTE'}]}
|
2013-02-25 21:18:51 -08:00
|
|
|
response = (resp, body)
|
|
|
|
|
|
|
|
mock_get = Mock(return_value=response)
|
|
|
|
self.limits.api.client.get = mock_get
|
2013-03-12 16:15:04 -07:00
|
|
|
self.assertIsNotNone(self.limits.list())
|
2013-02-25 21:18:51 -08:00
|
|
|
mock_get.assert_called_once_with("/limits")
|
|
|
|
|
2013-03-12 16:15:04 -07:00
|
|
|
def test_list_errors(self):
|
2013-02-25 21:18:51 -08:00
|
|
|
status_list = [400, 401, 403, 404, 408, 409, 413, 500, 501]
|
|
|
|
for status_code in status_list:
|
|
|
|
self._check_error_response(status_code)
|
|
|
|
|
|
|
|
def _check_error_response(self, status_code):
|
|
|
|
RESPONSE_KEY = "limits"
|
|
|
|
|
|
|
|
resp = Mock()
|
2013-09-26 22:26:02 -07:00
|
|
|
resp.status_code = status_code
|
2013-03-06 15:36:00 -08:00
|
|
|
body = {RESPONSE_KEY: {
|
|
|
|
'absolute': {},
|
|
|
|
'rate': [
|
2013-02-25 21:18:51 -08:00
|
|
|
{'limit': []
|
2013-03-06 15:36:00 -08:00
|
|
|
}]}}
|
2013-02-25 21:18:51 -08:00
|
|
|
response = (resp, body)
|
|
|
|
|
|
|
|
mock_get = Mock(return_value=response)
|
|
|
|
self.limits.api.client.get = mock_get
|
2013-03-12 16:15:04 -07:00
|
|
|
self.assertRaises(Exception, self.limits.list)
|