~ubuntu-branches/ubuntu/vivid/neutron/vivid

« back to all changes in this revision

Viewing changes to neutron/tests/unit/test_api_api_common.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2015-04-15 13:59:07 UTC
  • mfrom: (1.1.22)
  • Revision ID: package-import@ubuntu.com-20150415135907-z10fr18evag1ozq3
Tags: 1:2015.1~rc1-0ubuntu1
* New upstream milestone release:
  - debian/control: Update dependencies. 
  - debian/patches/disable-udev-tests.patch: Dropped no longer needed.
  - debian/patches/fixup-driver-test-execution.patch: Dropped no longer needed.
  - debian/patches/skip-iptest.patch: Skip failing test
  - debian/neutron-plugin-openvswitch-agent.install: Added neutron-ovsvapp-agent binary.
  - debian/neutron-plugin-cisco.install: Added neutron-cisco-apic-service-agent and 
    neutron-cisco-apic-host-agent

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2013 Intel Corporation.
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
 
from testtools import matchers
17
 
from webob import exc
18
 
 
19
 
from neutron.api import api_common as common
20
 
from neutron.tests import base
21
 
 
22
 
 
23
 
class FakeController(common.NeutronController):
24
 
    _resource_name = 'fake'
25
 
 
26
 
 
27
 
class APICommonTestCase(base.BaseTestCase):
28
 
    def setUp(self):
29
 
        super(APICommonTestCase, self).setUp()
30
 
        self.controller = FakeController(None)
31
 
 
32
 
    def test_prepare_request_body(self):
33
 
        body = {
34
 
            'fake': {
35
 
                'name': 'terminator',
36
 
                'model': 'T-800',
37
 
            }
38
 
        }
39
 
        params = [
40
 
            {'param-name': 'name',
41
 
             'required': True},
42
 
            {'param-name': 'model',
43
 
             'required': True},
44
 
            {'param-name': 'quote',
45
 
             'required': False,
46
 
             'default-value': "i'll be back"},
47
 
        ]
48
 
        expect = {
49
 
            'fake': {
50
 
                'name': 'terminator',
51
 
                'model': 'T-800',
52
 
                'quote': "i'll be back",
53
 
            }
54
 
        }
55
 
        actual = self.controller._prepare_request_body(body, params)
56
 
        self.assertThat(expect, matchers.Equals(actual))
57
 
 
58
 
    def test_prepare_request_body_none(self):
59
 
        body = None
60
 
        params = [
61
 
            {'param-name': 'quote',
62
 
             'required': False,
63
 
             'default-value': "I'll be back"},
64
 
        ]
65
 
        expect = {
66
 
            'fake': {
67
 
                'quote': "I'll be back",
68
 
            }
69
 
        }
70
 
        actual = self.controller._prepare_request_body(body, params)
71
 
        self.assertThat(expect, matchers.Equals(actual))
72
 
 
73
 
    def test_prepare_request_body_keyerror(self):
74
 
        body = {'t2': {}}
75
 
        params = []
76
 
        self.assertRaises(exc.HTTPBadRequest,
77
 
                          self.controller._prepare_request_body,
78
 
                          body,
79
 
                          params)
80
 
 
81
 
    def test_prepare_request_param_value_none(self):
82
 
        body = {
83
 
            'fake': {
84
 
                'name': None,
85
 
            }
86
 
        }
87
 
        params = [
88
 
            {'param-name': 'name',
89
 
             'required': True},
90
 
        ]
91
 
        self.assertRaises(exc.HTTPBadRequest,
92
 
                          self.controller._prepare_request_body,
93
 
                          body,
94
 
                          params)