"Fossies" - the Fresh Open Source Software Archive

Member "tacker-2.0.0/tacker/tests/unit/extensions/foxinsocks.py" (16 Oct 2019, 3640 Bytes) of package /linux/misc/openstack/tacker-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "foxinsocks.py": 0.9.0_vs_1.0.0.

    1 # Copyright 2011 OpenStack Foundation.
    2 # All Rights Reserved.
    3 #
    4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    5 #    not use this file except in compliance with the License. You may obtain
    6 #    a copy of the License at
    7 #
    8 #         http://www.apache.org/licenses/LICENSE-2.0
    9 #
   10 #    Unless required by applicable law or agreed to in writing, software
   11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   13 #    License for the specific language governing permissions and limitations
   14 #    under the License.
   15 
   16 import abc
   17 
   18 from oslo_serialization import jsonutils
   19 
   20 from tacker.api import extensions
   21 from tacker import wsgi
   22 
   23 
   24 class FoxInSocksController(wsgi.Controller):
   25 
   26     def index(self, request):
   27         return "Try to say this Mr. Knox, sir..."
   28 
   29 
   30 class FoxInSocksPluginInterface(extensions.PluginInterface):
   31 
   32     @abc.abstractmethod
   33     def method_to_support_foxnsox_extension(self):
   34         pass
   35 
   36 
   37 class Foxinsocks(object):
   38 
   39     def __init__(self):
   40         pass
   41 
   42     def get_plugin_interface(self):
   43         return FoxInSocksPluginInterface
   44 
   45     def get_name(self):
   46         return "Fox In Socks"
   47 
   48     def get_alias(self):
   49         return "FOXNSOX"
   50 
   51     def get_description(self):
   52         return "The Fox In Socks Extension"
   53 
   54     def get_namespace(self):
   55         return "http://www.fox.in.socks/api/ext/pie/v1.0"
   56 
   57     def get_updated(self):
   58         return "2011-01-22T13:25:27-06:00"
   59 
   60     def get_resources(self):
   61         resources = []
   62         resource = extensions.ResourceExtension('foxnsocks',
   63                                                 FoxInSocksController())
   64         resources.append(resource)
   65         return resources
   66 
   67     def get_actions(self):
   68         return [extensions.ActionExtension('dummy_resources',
   69                                            'FOXNSOX:add_tweedle',
   70                                            self._add_tweedle_handler),
   71                 extensions.ActionExtension('dummy_resources',
   72                                            'FOXNSOX:delete_tweedle',
   73                                            self._delete_tweedle_handler)]
   74 
   75     def get_request_extensions(self):
   76         request_exts = []
   77 
   78         def _goose_handler(req, res):
   79             # NOTE: This only handles JSON responses.
   80             # You can use content type header to test for XML.
   81             data = jsonutils.loads(res.body)
   82             data['FOXNSOX:googoose'] = req.GET.get('chewing')
   83             res.body = jsonutils.dump_as_bytes(data)
   84             return res
   85 
   86         req_ext1 = extensions.RequestExtension('GET', '/dummy_resources/:(id)',
   87                                                _goose_handler)
   88         request_exts.append(req_ext1)
   89 
   90         def _bands_handler(req, res):
   91             # NOTE: This only handles JSON responses.
   92             # You can use content type header to test for XML.
   93             data = jsonutils.loads(res.body)
   94             data['FOXNSOX:big_bands'] = 'Pig Bands!'
   95             res.body = jsonutils.dump_as_bytes(data)
   96             return res
   97 
   98         req_ext2 = extensions.RequestExtension('GET', '/dummy_resources/:(id)',
   99                                                _bands_handler)
  100         request_exts.append(req_ext2)
  101         return request_exts
  102 
  103     def _add_tweedle_handler(self, input_dict, req, id):
  104         return "Tweedle {0} Added.".format(
  105             input_dict['FOXNSOX:add_tweedle']['name'])
  106 
  107     def _delete_tweedle_handler(self, input_dict, req, id):
  108         return "Tweedle {0} Deleted.".format(
  109             input_dict['FOXNSOX:delete_tweedle']['name'])