/usr/lib/python2.7/dist-packages/gnocchiclient/tests/functional/test_resource_type.py is in python-gnocchiclient 7.0.1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | # 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.
import json
import uuid
from gnocchiclient.tests.functional import base
class ResourceTypeClientTest(base.ClientTestBase):
RESOURCE_TYPE = str(uuid.uuid4())
RESOURCE_ID = str(uuid.uuid4())
def test_help(self):
self.gnocchi("help", params="resource list", has_output=False)
def test_resource_type_scenario(self):
# LIST
result = self.gnocchi('resource-type', params="list")
r = json.loads(result)
self.assertEqual([{'attributes': '', 'name': 'generic'}], r)
# CREATE
result = self.gnocchi(
u'resource-type',
params=u"create -a foo:string:true:max_length=16 "
"-a bar:number:no:max=32 %s" % self.RESOURCE_TYPE)
resource = json.loads(result)
self.assertEqual(self.RESOURCE_TYPE, resource["name"])
self.assertEqual(
"max_length=16, min_length=0, required=True, type=string",
resource["attributes/foo"])
# SHOW
result = self.gnocchi(
u'resource-type', params=u"show %s" % self.RESOURCE_TYPE)
resource = json.loads(result)
self.assertEqual(self.RESOURCE_TYPE, resource["name"])
self.assertEqual(
"max_length=16, min_length=0, required=True, type=string",
resource["attributes/foo"])
# PATCH
result = self.gnocchi(
u'resource-type',
params=u"update -r foo "
"-a new:number:yes:max=16:fill=8 %s" % self.RESOURCE_TYPE)
resource = json.loads(result)
self.assertEqual(self.RESOURCE_TYPE, resource["name"])
self.assertNotIn("attributes/foo", resource)
self.assertEqual(
"max=16, min=None, required=True, type=number",
resource["attributes/new"])
# SHOW
result = self.gnocchi(
u'resource-type', params=u"show %s" % self.RESOURCE_TYPE)
resource = json.loads(result)
self.assertEqual(self.RESOURCE_TYPE, resource["name"])
self.assertNotIn("attributes/foo", resource)
self.assertEqual(
"max=16, min=None, required=True, type=number",
resource["attributes/new"])
# Create a resource for this type
result = self.gnocchi(
u'resource', params=(u"create %s -t %s -a new:5") %
(self.RESOURCE_ID, self.RESOURCE_TYPE))
resource = json.loads(result)
self.assertEqual(self.RESOURCE_ID, resource["id"])
self.assertEqual(5.0, resource["new"])
# Delete the resource
self.gnocchi('resource', params="delete %s" % self.RESOURCE_ID,
has_output=False)
# DELETE
self.gnocchi('resource-type',
params="delete %s" % self.RESOURCE_TYPE,
has_output=False)
# DELETE AGAIN
result = self.gnocchi('resource-type',
params="delete %s" % self.RESOURCE_TYPE,
fail_ok=True, merge_stderr=True,
has_output=False)
self.assertEqual(
"Resource type %s does not exist (HTTP 404)\n"
% self.RESOURCE_TYPE,
result)
# SHOW AGAIN
result = self.gnocchi(u'resource-type',
params=u"show %s" % self.RESOURCE_TYPE,
fail_ok=True, merge_stderr=True)
self.assertEqual(
"Resource type %s does not exist (HTTP 404)\n"
% self.RESOURCE_TYPE,
result)
|