How to use test_get_registered_limits method in tempest

Best Python code snippet using tempest_python

test_limit.py

Source:test_limit.py Github

copy

Full Screen

...159 self.assertRaises(ValueError,160 enforcer.calculate_usage,161 'project', ['a', 123, 'b'])162 @mock.patch.object(limit._EnforcerUtils, "get_registered_limits")163 def test_get_registered_limits(self, mock_get_limits):164 mock_get_limits.return_value = [("a", 1), ("b", 0), ("c", 2)]165 enforcer = limit.Enforcer(lambda: None)166 limits = enforcer.get_registered_limits(["a", "b", "c"])167 mock_get_limits.assert_called_once_with(["a", "b", "c"])168 self.assertEqual(mock_get_limits.return_value, limits)169 @mock.patch.object(limit._EnforcerUtils, "get_project_limits")170 def test_get_project_limits(self, mock_get_limits):171 project_id = uuid.uuid4().hex172 mock_get_limits.return_value = [("a", 1), ("b", 0), ("c", 2)]173 enforcer = limit.Enforcer(lambda: None)174 limits = enforcer.get_project_limits(project_id, ["a", "b", "c"])175 mock_get_limits.assert_called_once_with(project_id, ["a", "b", "c"])176 self.assertEqual(mock_get_limits.return_value, limits)177class TestFlatEnforcer(base.BaseTestCase):178 def setUp(self):179 super(TestFlatEnforcer, self).setUp()180 self.mock_conn = mock.MagicMock()181 limit._SDK_CONNECTION = self.mock_conn182 @mock.patch.object(limit._EnforcerUtils, "get_registered_limits")183 def test_get_registered_limits(self, mock_get_limits):184 mock_get_limits.return_value = [("a", 1), ("b", 0), ("c", 2)]185 enforcer = limit._FlatEnforcer(lambda: None)186 limits = enforcer.get_registered_limits(["a", "b", "c"])187 mock_get_limits.assert_called_once_with(["a", "b", "c"])188 self.assertEqual(mock_get_limits.return_value, limits)189 @mock.patch.object(limit._EnforcerUtils, "get_project_limits")190 def test_get_project_limits(self, mock_get_limits):191 project_id = uuid.uuid4().hex192 mock_get_limits.return_value = [("a", 1), ("b", 0), ("c", 2)]193 enforcer = limit._FlatEnforcer(lambda: None)194 limits = enforcer.get_project_limits(project_id, ["a", "b", "c"])195 mock_get_limits.assert_called_once_with(project_id, ["a", "b", "c"])196 self.assertEqual(mock_get_limits.return_value, limits)197 @mock.patch.object(limit._EnforcerUtils, "get_project_limits")198 def test_enforce(self, mock_get_limits):199 mock_usage = mock.MagicMock()200 project_id = uuid.uuid4().hex201 deltas = {"a": 1, "b": 1}202 mock_get_limits.return_value = [("a", 1), ("b", 2)]203 mock_usage.return_value = {"a": 0, "b": 1}204 enforcer = limit._FlatEnforcer(mock_usage)205 enforcer.enforce(project_id, deltas)206 self.mock_conn.get_endpoint.assert_called_once_with(None)207 mock_get_limits.assert_called_once_with(project_id, ["a", "b"])208 mock_usage.assert_called_once_with(project_id, ["a", "b"])209 @mock.patch.object(limit._EnforcerUtils, "get_project_limits")210 def test_enforce_raises_on_over(self, mock_get_limits):211 mock_usage = mock.MagicMock()212 project_id = uuid.uuid4().hex213 deltas = {"a": 2, "b": 1}214 mock_get_limits.return_value = [("a", 1), ("b", 2)]215 mock_usage.return_value = {"a": 0, "b": 1}216 enforcer = limit._FlatEnforcer(mock_usage)217 e = self.assertRaises(exception.ProjectOverLimit, enforcer.enforce,218 project_id, deltas)219 expected = ("Project %s is over a limit for "220 "[Resource a is over limit of 1 due to current usage 0 "221 "and delta 2]")222 self.assertEqual(expected % project_id, str(e))223 self.assertEqual(project_id, e.project_id)224 self.assertEqual(1, len(e.over_limit_info_list))225 over_a = e.over_limit_info_list[0]226 self.assertEqual("a", over_a.resource_name)227 self.assertEqual(1, over_a.limit)228 self.assertEqual(0, over_a.current_usage)229 self.assertEqual(2, over_a.delta)230 @mock.patch.object(limit._EnforcerUtils, "_get_project_limit")231 @mock.patch.object(limit._EnforcerUtils, "_get_registered_limit")232 def test_enforce_raises_on_missing_limit(self, mock_get_reglimit,233 mock_get_limit):234 def mock_usage(*a):235 return {'a': 1, 'b': 1}236 project_id = uuid.uuid4().hex237 deltas = {"a": 0, "b": 0}238 mock_get_reglimit.return_value = None239 mock_get_limit.return_value = None240 enforcer = limit._FlatEnforcer(mock_usage)241 self.assertRaises(exception.ProjectOverLimit, enforcer.enforce,242 project_id, deltas)243 self.assertRaises(exception.ProjectOverLimit, enforcer.enforce,244 None, deltas)245class TestEnforcerUtils(base.BaseTestCase):246 def setUp(self):247 super(TestEnforcerUtils, self).setUp()248 self.mock_conn = mock.MagicMock()249 limit._SDK_CONNECTION = self.mock_conn250 def test_get_endpoint(self):251 fake_endpoint = endpoint.Endpoint()252 self.mock_conn.get_endpoint.return_value = fake_endpoint253 utils = limit._EnforcerUtils()254 self.assertEqual(fake_endpoint, utils._endpoint)255 self.mock_conn.get_endpoint.assert_called_once_with(None)256 def test_get_registered_limit_empty(self):257 self.mock_conn.registered_limits.return_value = iter([])258 utils = limit._EnforcerUtils()259 reg_limit = utils._get_registered_limit("foo")260 self.assertIsNone(reg_limit)261 def test_get_registered_limit(self):262 foo = registered_limit.RegisteredLimit()263 foo.resource_name = "foo"264 self.mock_conn.registered_limits.return_value = iter([foo])265 utils = limit._EnforcerUtils()266 reg_limit = utils._get_registered_limit("foo")267 self.assertEqual(foo, reg_limit)268 def test_get_registered_limits(self):269 fake_endpoint = endpoint.Endpoint()270 fake_endpoint.service_id = "service_id"271 fake_endpoint.region_id = "region_id"272 self.mock_conn.get_endpoint.return_value = fake_endpoint273 # a and c have limits, b doesn't have one274 empty_iterator = iter([])275 a = registered_limit.RegisteredLimit()276 a.resource_name = "a"277 a.default_limit = 1278 a_iterator = iter([a])279 c = registered_limit.RegisteredLimit()280 c.resource_name = "c"281 c.default_limit = 2282 c_iterator = iter([c])...

Full Screen

Full Screen

test_limit_client.py

Source:test_limit_client.py Github

copy

Full Screen

...19 super(TestLimitsClient, self).setUp()20 self.client = limits_client.LimitsClient(21 fake_auth_provider.FakeAuthProvider(),22 'identity', 'regionOne')23 def test_get_registered_limits(self):24 fake_result = {'foo': 'bar'}25 self.check_service_client_function(26 self.client.get_registered_limits,27 'tempest.lib.common.rest_client.RestClient.get',28 fake_result,29 False,30 status=200)31 def test_create_limit(self):32 fake_result = {'foo': 'bar'}33 self.check_service_client_function(34 self.client.create_limit,35 'tempest.lib.common.rest_client.RestClient.post',36 fake_result,37 False,...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful