~tylesmit/neutron/quantum-packages-bk

« back to all changes in this revision

Viewing changes to server/lib/quantum/tests/unit/extensions/foxinsocks.py

  • Committer: Tyler Smith
  • Date: 2011-08-18 18:31:56 UTC
  • Revision ID: tylesmit@cisco.com-20110818183156-8uydj2zha71luaye
Adding support for running tests.  Note that test_extensions has 5 failing tests which I'm working to resolve.

Show diffs side-by-side

added added

removed removed

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