summaryrefslogtreecommitdiffstats
path: root/tests/unit/extensions
diff options
context:
space:
mode:
authorRajaram Mallya <rajarammallya@gmail.com>2011-09-07 17:07:19 +0530
committerRajaram Mallya <rajarammallya@gmail.com>2011-09-07 17:07:19 +0530
commit2a529c6cb7cfed08a7afe8fc0f8249bc9bdb2621 (patch)
treecfd35e1300ccfba21740cb6aacd2f3bd607530bf /tests/unit/extensions
parent96b9a548521cefb7c1b7dd5229c89b8fec53de85 (diff)
Vinkesh/Rajaram|Added nova's extension framework into common and tests for it
Diffstat (limited to 'tests/unit/extensions')
-rw-r--r--tests/unit/extensions/__init__.py15
-rw-r--r--tests/unit/extensions/foxinsocks.py102
2 files changed, 117 insertions, 0 deletions
diff --git a/tests/unit/extensions/__init__.py b/tests/unit/extensions/__init__.py
new file mode 100644
index 0000000..848908a
--- /dev/null
+++ b/tests/unit/extensions/__init__.py
@@ -0,0 +1,15 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2011 OpenStack LLC
+#
+# 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.
diff --git a/tests/unit/extensions/foxinsocks.py b/tests/unit/extensions/foxinsocks.py
new file mode 100644
index 0000000..a0efd7e
--- /dev/null
+++ b/tests/unit/extensions/foxinsocks.py
@@ -0,0 +1,102 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2011 OpenStack LLC.
+# All Rights Reserved.
+#
+# 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
+
+from openstack.common import extensions
+from openstack.common import wsgi
+
+
+class FoxInSocksController(object):
+
+ def index(self, request):
+ return "Try to say this Mr. Knox, sir..."
+
+ def create_resource(self):
+ return wsgi.Resource(self)
+
+
+class Foxinsocks(object):
+
+ def __init__(self):
+ pass
+
+ def get_name(self):
+ return "Fox In Socks"
+
+ def get_alias(self):
+ return "FOXNSOX"
+
+ def get_description(self):
+ return "The Fox In Socks Extension"
+
+ def get_namespace(self):
+ return "http://www.fox.in.socks/api/ext/pie/v1.0"
+
+ def get_updated(self):
+ return "2011-01-22T13:25:27-06:00"
+
+ def get_resources(self):
+ resources = []
+ resource = extensions.ResourceExtension('foxnsocks',
+ FoxInSocksController())
+ resources.append(resource)
+ return resources
+
+ def get_actions(self):
+ return [extensions.ActionExtension('dummy_resources',
+ 'FOXNSOX:add_tweedle',
+ self._add_tweedle_handler),
+ extensions.ActionExtension('dummy_resources',
+ 'FOXNSOX:delete_tweedle',
+ self._delete_tweedle_handler)]
+
+ def get_request_extensions(self):
+ request_exts = []
+
+ def _goose_handler(req, res):
+ #NOTE: This only handles JSON responses.
+ # You can use content type header to test for XML.
+ data = json.loads(res.body)
+ data['FOXNSOX:googoose'] = req.GET.get('chewing')
+ res.body = json.dumps(data)
+ return res
+
+ req_ext1 = extensions.RequestExtension('GET', '/dummy_resources/:(id)',
+ _goose_handler)
+ request_exts.append(req_ext1)
+
+ def _bands_handler(req, res):
+ #NOTE: This only handles JSON responses.
+ # You can use content type header to test for XML.
+ data = json.loads(res.body)
+ data['FOXNSOX:big_bands'] = 'Pig Bands!'
+ res.body = json.dumps(data)
+ return res
+
+ req_ext2 = extensions.RequestExtension('GET', '/dummy_resources/:(id)',
+ _bands_handler)
+ request_exts.append(req_ext2)
+ return request_exts
+
+ def _add_tweedle_handler(self, input_dict, req, id):
+ return "Tweedle {0} Added.".format(
+ input_dict['FOXNSOX:add_tweedle']['name'])
+
+ def _delete_tweedle_handler(self, input_dict, req, id):
+ return "Tweedle {0} Deleted.".format(
+ input_dict['FOXNSOX:delete_tweedle']['name'])