def test_get_registered_limit_empty(self): self.mock_conn.registered_limits.return_value = iter([]) utils = limit._EnforcerUtils() reg_limit = utils._get_registered_limit("foo") self.assertIsNone(reg_limit)
def test_get_endpoint(self): fake_endpoint = endpoint.Endpoint() self.mock_conn.get_endpoint.return_value = fake_endpoint utils = limit._EnforcerUtils() self.assertEqual(fake_endpoint, utils._endpoint) self.mock_conn.get_endpoint.assert_called_once_with(None)
def test_get_registered_limit(self): foo = registered_limit.RegisteredLimit() foo.resource_name = "foo" self.mock_conn.registered_limits.return_value = iter([foo]) utils = limit._EnforcerUtils() reg_limit = utils._get_registered_limit("foo") self.assertEqual(foo, reg_limit)
def test_get_project_limits(self): fake_endpoint = endpoint.Endpoint() fake_endpoint.service_id = "service_id" fake_endpoint.region_id = "region_id" self.mock_conn.get_endpoint.return_value = fake_endpoint project_id = uuid.uuid4().hex # a is a project limit, b, c and d don't have one empty_iterator = iter([]) a = klimit.Limit() a.resource_name = "a" a.resource_limit = 1 a_iterator = iter([a]) self.mock_conn.limits.side_effect = [ a_iterator, empty_iterator, empty_iterator, empty_iterator ] # b has a limit, but c and d doesn't, a isn't ever checked b = registered_limit.RegisteredLimit() b.resource_name = "b" b.default_limit = 2 b_iterator = iter([b]) self.mock_conn.registered_limits.side_effect = [ b_iterator, empty_iterator, empty_iterator ] utils = limit._EnforcerUtils() limits = utils.get_project_limits(project_id, ["a", "b"]) self.assertEqual([('a', 1), ('b', 2)], limits) e = self.assertRaises(exception.ProjectOverLimit, utils.get_project_limits, project_id, ["c", "d"]) expected = ("Project %s is over a limit for " "[Resource c is over limit of 0 due to current usage 0 " "and delta 0, " "Resource d is over limit of 0 due to current usage 0 " "and delta 0]") self.assertEqual(expected % project_id, str(e)) self.assertEqual(project_id, e.project_id) self.assertEqual(2, len(e.over_limit_info_list)) over_c = e.over_limit_info_list[0] self.assertEqual("c", over_c.resource_name) over_d = e.over_limit_info_list[1] self.assertEqual("d", over_d.resource_name) self.assertEqual(0, over_d.limit) self.assertEqual(0, over_d.current_usage) self.assertEqual(0, over_d.delta)