def test_limit_index_empty(self, quotas_mock): limit_controller = LimitsController() req = MagicMock() req.environ = {'trove.context': self.context} view = limit_controller.index(req, "test_tenant_id") expected = {'limits': [{'verb': 'ABSOLUTE'}]} self.assertEqual(expected, view._data)
def test_limit_index_empty(self, quotas_mock): limit_controller = LimitsController() req = MagicMock() req.environ = {} view = limit_controller.index(req, "test_tenant_id") expected = {'limits': [{'verb': 'ABSOLUTE'}]} self.assertEqual(expected, view._data)
def test_limit_index_empty(self): limit_controller = LimitsController() req = mock() req.environ = {} when(QUOTAS).get_all_quotas_by_tenant(any()).thenReturn({}) view = limit_controller.index(req, "test_tenant_id") expected = {'limits': [{'verb': 'ABSOLUTE'}]} self.assertEqual(expected, view._data)
def test_limit_index_empty(self): limit_controller = LimitsController() req = MagicMock() req.environ = {} QUOTAS.get_all_quotas_by_tenant = MagicMock(return_value={}) view = limit_controller.index(req, "test_tenant_id") expected = {'limits': [{'verb': 'ABSOLUTE'}]} self.assertEqual(expected, view._data)
def test_limit_index(self): tenant_id = "test_tenant_id" limit_controller = LimitsController() limits = [{ "URI": "*", "regex": ".*", "value": 10, "verb": "POST", "remaining": 2, "unit": "MINUTE", "resetTime": 1311272226 }, { "URI": "*", "regex": ".*", "value": 10, "verb": "PUT", "remaining": 2, "unit": "MINUTE", "resetTime": 1311272226 }, { "URI": "*", "regex": ".*", "value": 10, "verb": "DELETE", "remaining": 2, "unit": "MINUTE", "resetTime": 1311272226 }, { "URI": "*", "regex": ".*", "value": 10, "verb": "GET", "remaining": 2, "unit": "MINUTE", "resetTime": 1311272226 }] abs_limits = { "instances": Quota(tenant_id=tenant_id, resource="instances", hard_limit=100), "backups": Quota(tenant_id=tenant_id, resource="backups", hard_limit=40), "volumes": Quota(tenant_id=tenant_id, resource="volumes", hard_limit=55) } req = MagicMock() req.environ = {"trove.limits": limits} QUOTAS.get_all_quotas_by_tenant = MagicMock(return_value=abs_limits) view = limit_controller.index(req, tenant_id) expected = { 'limits': [{ 'max_instances': 100, 'max_backups': 40, 'verb': 'ABSOLUTE', 'max_volumes': 55 }, { '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' }] } self.assertEqual(expected, view._data)
def _limits_router(self, mapper): limits_resource = LimitsController().create_resource() mapper.connect("/{tenant_id}/limits", controller=limits_resource, action="index", conditions={'method': ['GET']})
def test_limit_index(self): tenant_id = "test_tenant_id" limit_controller = LimitsController() limits = [ { "URI": "*", "regex": ".*", "value": 10, "verb": "POST", "remaining": 2, "unit": "MINUTE", "resetTime": 1311272226 }, { "URI": "*", "regex": ".*", "value": 10, "verb": "PUT", "remaining": 2, "unit": "MINUTE", "resetTime": 1311272226 }, { "URI": "*", "regex": ".*", "value": 10, "verb": "DELETE", "remaining": 2, "unit": "MINUTE", "resetTime": 1311272226 }, { "URI": "*", "regex": ".*", "value": 10, "verb": "GET", "remaining": 2, "unit": "MINUTE", "resetTime": 1311272226 } ] abs_limits = {"instances": Quota(tenant_id=tenant_id, resource="instances", hard_limit=100), "backups": Quota(tenant_id=tenant_id, resource="backups", hard_limit=40), "volumes": Quota(tenant_id=tenant_id, resource="volumes", hard_limit=55)} req = MagicMock() req.environ = {"trove.limits": limits} QUOTAS.get_all_quotas_by_tenant = MagicMock(return_value=abs_limits) view = limit_controller.index(req, tenant_id) expected = { 'limits': [ { 'max_instances': 100, 'max_backups': 40, 'verb': 'ABSOLUTE', 'max_volumes': 55 }, { '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' } ] } self.assertEqual(expected, view._data)
def _limits_router(self, mapper): limits_resource = LimitsController().create_resource() path = "/{tenant_id}/limits" mapper.resource("limits", path, controller=limits_resource)
def test_limit_index(self): tenant_id = "test_tenant_id" limit_controller = LimitsController() limits = [ { "URI": "*", "regex": ".*", "value": 10, "verb": "POST", "remaining": 2, "unit": "MINUTE", "resetTime": 1311272226, }, { "URI": "*", "regex": ".*", "value": 10, "verb": "PUT", "remaining": 2, "unit": "MINUTE", "resetTime": 1311272226, }, { "URI": "*", "regex": ".*", "value": 10, "verb": "DELETE", "remaining": 2, "unit": "MINUTE", "resetTime": 1311272226, }, { "URI": "*", "regex": ".*", "value": 10, "verb": "GET", "remaining": 2, "unit": "MINUTE", "resetTime": 1311272226, }, ] abs_limits = { "instances": Quota(tenant_id=tenant_id, resource="instances", hard_limit=100), "backups": Quota(tenant_id=tenant_id, resource="backups", hard_limit=40), "volumes": Quota(tenant_id=tenant_id, resource="volumes", hard_limit=55), } req = mock() req.environ = {"trove.limits": limits} when(QUOTAS).get_all_quotas_by_tenant(tenant_id).thenReturn(abs_limits) view = limit_controller.index(req, tenant_id) expected = { "limits": [ {"max_instances": 100, "max_backups": 40, "verb": "ABSOLUTE", "max_volumes": 55}, { "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", }, ] } self.assertEqual(expected, view._data)