358769ef93772eb96fd24d9de7fc8ea13acf789c
[openstack-build/neutron-build.git] / neutron / tests / unit / extension_stubs.py
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 neutron.api import extensions
19 from neutron import wsgi
20
21
22 class StubExtension(extensions.ExtensionDescriptor):
23
24     def __init__(self, alias="stub_extension"):
25         self.alias = alias
26
27     def get_name(self):
28         return "Stub Extension"
29
30     def get_alias(self):
31         return self.alias
32
33     def get_description(self):
34         return ""
35
36     def get_updated(self):
37         return ""
38
39
40 class StubPlugin(object):
41
42     def __init__(self, supported_extensions=None):
43         supported_extensions = supported_extensions or []
44         self.supported_extension_aliases = supported_extensions
45
46
47 class ExtensionExpectingPluginInterface(StubExtension):
48     """Expect plugin to implement all methods in StubPluginInterface.
49
50     This extension expects plugin to implement all the methods defined
51     in StubPluginInterface.
52     """
53
54     def get_plugin_interface(self):
55         return StubPluginInterface
56
57
58 class StubPluginInterface(extensions.PluginInterface):
59
60     @abc.abstractmethod
61     def get_foo(self, bar=None):
62         pass
63
64
65 class StubBaseAppController(wsgi.Controller):
66
67     def index(self, request):
68         return "base app index"
69
70     def show(self, request, id):
71         return {'fort': 'knox'}
72
73     def update(self, request, id):
74         return {'uneditable': 'original_value'}