|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | + |
| 13 | +import mock |
| 14 | +import six |
| 15 | +import testtools |
| 16 | + |
| 17 | +from openstack.compute.v2 import limits_absolute |
| 18 | + |
| 19 | +IDENTIFIER = 'IDENTIFIER' |
| 20 | +EXAMPLE = { |
| 21 | + 'name': 'maxImageMeta', |
| 22 | + 'value': '2', |
| 23 | +} |
| 24 | +FAKE_RESPONSES = { |
| 25 | + "limits": { |
| 26 | + "absolute": { |
| 27 | + "maxImageMeta": 128, |
| 28 | + "maxPersonality": 5, |
| 29 | + "maxPersonalitySize": 10240, |
| 30 | + "maxSecurityGroupRules": 20, |
| 31 | + "maxSecurityGroups": 10, |
| 32 | + "maxServerMeta": 128, |
| 33 | + "maxTotalCores": 20, |
| 34 | + "maxTotalFloatingIps": 10, |
| 35 | + "maxTotalInstances": 10, |
| 36 | + "maxTotalKeypairs": 100, |
| 37 | + "maxTotalRAMSize": 51200, |
| 38 | + } |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | + |
| 43 | +class TestLimitsAbsolute(testtools.TestCase): |
| 44 | + |
| 45 | + def test_basic(self): |
| 46 | + sot = limits_absolute.LimitsAbsolute() |
| 47 | + self.assertEqual('limits_absolute', sot.resource_key) |
| 48 | + self.assertEqual('limits_absolutes', sot.resources_key) |
| 49 | + self.assertEqual('/limits', sot.base_path) |
| 50 | + self.assertEqual('compute', sot.service.service_type) |
| 51 | + self.assertFalse(sot.allow_create) |
| 52 | + self.assertFalse(sot.allow_retrieve) |
| 53 | + self.assertFalse(sot.allow_update) |
| 54 | + self.assertFalse(sot.allow_delete) |
| 55 | + self.assertTrue(sot.allow_list) |
| 56 | + |
| 57 | + def test_make_it(self): |
| 58 | + sot = limits_absolute.LimitsAbsolute(EXAMPLE) |
| 59 | + self.assertEqual(EXAMPLE['name'], sot.name) |
| 60 | + self.assertEqual(EXAMPLE['value'], sot.value) |
| 61 | + |
| 62 | + def test_list(self): |
| 63 | + resp = mock.Mock() |
| 64 | + resp.body = FAKE_RESPONSES |
| 65 | + sess = mock.Mock() |
| 66 | + sess.get = mock.MagicMock() |
| 67 | + sess.get.return_value = resp |
| 68 | + sot = limits_absolute.LimitsAbsolute() |
| 69 | + |
| 70 | + resp = sot.list(sess) |
| 71 | + |
| 72 | + url = '/limits' |
| 73 | + sess.get.assert_called_with(url, service=sot.service, params={}) |
| 74 | + absolute = FAKE_RESPONSES['limits']['absolute'] |
| 75 | + cnt = 0 |
| 76 | + for key, value in six.iteritems(absolute): |
| 77 | + self.assertEqual(key, resp[cnt].name) |
| 78 | + self.assertEqual(value, resp[cnt].value) |
| 79 | + cnt = cnt + 1 |
0 commit comments