summaryrefslogtreecommitdiff
path: root/troveclient/tests
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-01-20 22:06:44 +0000
committerGerrit Code Review <review@openstack.org>2018-01-20 22:06:44 +0000
commitda0bbae4e140dcb7001069f62cba841426807909 (patch)
treed8f6903ed9129e960e8bc6cef05198724f6cdfe4 /troveclient/tests
parentf0f4aeeec65ef776071905ac51d4133aef748768 (diff)
parent9910a3f9138236e2f845a77a01b47f14949a60c8 (diff)
downloadpython-troveclient-da0bbae4e140dcb7001069f62cba841426807909.tar.gz
Merge "Add quota commands to OSC"
Diffstat (limited to 'troveclient/tests')
-rw-r--r--troveclient/tests/fakes.py24
-rw-r--r--troveclient/tests/osc/v1/fakes.py11
-rw-r--r--troveclient/tests/osc/v1/test_database_quota.py59
3 files changed, 94 insertions, 0 deletions
diff --git a/troveclient/tests/fakes.py b/troveclient/tests/fakes.py
index 48557b2..ac9c9e5 100644
--- a/troveclient/tests/fakes.py
+++ b/troveclient/tests/fakes.py
@@ -759,3 +759,27 @@ class FakeHTTPClient(base_client.HTTPClient):
"to_port": 3306,
"security_group_id": "2",
"cidr": "15.0.0.0/24", "id": 3}]})
+
+ def get_quotas(self, **kw):
+ return (200, {}, {"quotas": [
+ {
+ "reserved": 1,
+ "resource": "instances",
+ "limit": 10,
+ "in_use": 2
+ },
+ {
+ "reserved": 3,
+ "resource": "backups",
+ "limit": 50,
+ "in_use": 4
+ },
+ {
+ "reserved": 5,
+ "resource": "volumes",
+ "limit": 40,
+ "in_use": 6
+ }]})
+
+ def update_instances_quota(self, **kw):
+ return (200, {}, {"quotas": {"instances": 51}})
diff --git a/troveclient/tests/osc/v1/fakes.py b/troveclient/tests/osc/v1/fakes.py
index cfaf2f2..85a1207 100644
--- a/troveclient/tests/osc/v1/fakes.py
+++ b/troveclient/tests/osc/v1/fakes.py
@@ -23,6 +23,7 @@ from troveclient.v1 import datastores
from troveclient.v1 import flavors
from troveclient.v1 import instances
from troveclient.v1 import limits
+from troveclient.v1 import quota
from troveclient.v1 import users
@@ -157,3 +158,13 @@ class FakeRoot(object):
def delete_instance_1234_root(self):
return fakes.FakeHTTPClient().delete_instances_1234_root()[2]
+
+
+class FakeQuota(object):
+ fake_quotas = fakes.FakeHTTPClient().get_quotas()[2]['quotas']
+ fake_instances_quota = (fakes.FakeHTTPClient()
+ .update_instances_quota()[2]['quotas'])
+
+ def get_quotas(self):
+ return [quota.Quotas.resource_class(None, q)
+ for q in self.fake_quotas]
diff --git a/troveclient/tests/osc/v1/test_database_quota.py b/troveclient/tests/osc/v1/test_database_quota.py
new file mode 100644
index 0000000..d15c7ea
--- /dev/null
+++ b/troveclient/tests/osc/v1/test_database_quota.py
@@ -0,0 +1,59 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from troveclient.osc.v1 import database_quota
+from troveclient.tests.osc.v1 import fakes
+
+
+class TestQuota(fakes.TestDatabasev1):
+ fake_quota = fakes.FakeQuota()
+
+ def setUp(self):
+ super(TestQuota, self).setUp()
+ self.mock_client = self.app.client_manager.database
+ self.quota_client = self.app.client_manager.database.quota
+
+
+class TestQuotaShow(TestQuota):
+ columns = database_quota.ShowDatabaseQuota.columns
+ values = [('instances', 2, 1, 10),
+ ('backups', 4, 3, 50),
+ ('volumes', 6, 5, 40)]
+
+ def setUp(self):
+ super(TestQuotaShow, self).setUp()
+ self.cmd = database_quota.ShowDatabaseQuota(self.app, None)
+ self.data = self.fake_quota.get_quotas()
+ self.quota_client.show.return_value = self.data
+
+ def test_show_quotas(self):
+ args = ['tenant_id']
+ parsed_args = self.check_parser(self.cmd, args, [])
+ columns, data = self.cmd.take_action(parsed_args)
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.values, data)
+
+
+class TestQuotaUpdate(TestQuota):
+
+ def setUp(self):
+ super(TestQuotaUpdate, self).setUp()
+ self.cmd = database_quota.UpdateDatabaseQuota(self.app, None)
+ self.data = self.fake_quota.fake_instances_quota
+ self.quota_client.update.return_value = self.data
+
+ def test_update_quota(self):
+ args = ['tenant_id', 'instances', '51']
+ parsed_args = self.check_parser(self.cmd, args, [])
+ columns, data = self.cmd.take_action(parsed_args)
+ self.assertEqual(('instances',), columns)
+ self.assertEqual((51,), data)