~ubuntu-branches/ubuntu/wily/heat/wily-proposed

« back to all changes in this revision

Viewing changes to contrib/heat_keystone/heat_keystone/tests/test_client.py

  • Committer: Package Import Robot
  • Author(s): James Page, Corey Bryant, James Page
  • Date: 2015-03-30 11:11:18 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20150330111118-2qpycylx6swu4yhj
Tags: 2015.1~b3-0ubuntu1
[ Corey Bryant ]
* New upstream milestone release for OpenStack kilo:
  - d/control: Align with upstream dependencies.
  - d/p/sudoers_patch.patch: Rebased.
  - d/p/fix-requirements.patch: Rebased.

[ James Page ]
* d/p/fixup-assert-regex.patch: Tweak test to use assertRegexpMatches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
3
#    not use this file except in compliance with the License. You may obtain
 
4
#    a copy of the License at
 
5
#
 
6
#         http://www.apache.org/licenses/LICENSE-2.0
 
7
#
 
8
#    Unless required by applicable law or agreed to in writing, software
 
9
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
10
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
11
#    License for the specific language governing permissions and limitations
 
12
#    under the License.
 
13
 
 
14
import mock
 
15
import testtools
 
16
 
 
17
from .. import client  # noqa
 
18
from .. import exceptions  # noqa
 
19
 
 
20
 
 
21
class KeystoneRoleConstraintTest(testtools.TestCase):
 
22
 
 
23
    def test_expected_exceptions(self):
 
24
        self.assertEqual((exceptions.KeystoneRoleNotFound,),
 
25
                         client.KeystoneRoleConstraint.expected_exceptions,
 
26
                         "KeystoneRoleConstraint expected exceptions error")
 
27
 
 
28
    def test_constrain(self):
 
29
        constrain = client.KeystoneRoleConstraint()
 
30
        client_mock = mock.MagicMock()
 
31
        client_plugin_mock = mock.MagicMock()
 
32
        client_plugin_mock.get_role_id.return_value = None
 
33
        client_mock.client_plugin.return_value = client_plugin_mock
 
34
 
 
35
        self.assertIsNone(constrain.validate_with_client(client_mock,
 
36
                                                         'role_1'))
 
37
 
 
38
        client_plugin_mock.get_role_id.assert_called_once_with('role_1')
 
39
 
 
40
 
 
41
class KeystoneProjectConstraintTest(testtools.TestCase):
 
42
 
 
43
    def test_expected_exceptions(self):
 
44
        self.assertEqual((exceptions.KeystoneProjectNotFound,),
 
45
                         client.KeystoneProjectConstraint.expected_exceptions,
 
46
                         "KeystoneProjectConstraint expected exceptions error")
 
47
 
 
48
    def test_constrain(self):
 
49
        constrain = client.KeystoneProjectConstraint()
 
50
        client_mock = mock.MagicMock()
 
51
        client_plugin_mock = mock.MagicMock()
 
52
        client_plugin_mock.get_project_id.return_value = None
 
53
        client_mock.client_plugin.return_value = client_plugin_mock
 
54
 
 
55
        self.assertIsNone(constrain.validate_with_client(client_mock,
 
56
                                                         'project_1'))
 
57
 
 
58
        client_plugin_mock.get_project_id.assert_called_once_with('project_1')
 
59
 
 
60
 
 
61
class KeystoneGroupConstraintTest(testtools.TestCase):
 
62
 
 
63
    def test_expected_exceptions(self):
 
64
        self.assertEqual((exceptions.KeystoneGroupNotFound,),
 
65
                         client.KeystoneGroupConstraint.expected_exceptions,
 
66
                         "KeystoneGroupConstraint expected exceptions error")
 
67
 
 
68
    def test_constrain(self):
 
69
        constrain = client.KeystoneGroupConstraint()
 
70
        client_mock = mock.MagicMock()
 
71
        client_plugin_mock = mock.MagicMock()
 
72
        client_plugin_mock.get_group_id.return_value = None
 
73
        client_mock.client_plugin.return_value = client_plugin_mock
 
74
 
 
75
        self.assertIsNone(constrain.validate_with_client(client_mock,
 
76
                                                         'group_1'))
 
77
 
 
78
        client_plugin_mock.get_group_id.assert_called_once_with('group_1')
 
79
 
 
80
 
 
81
class KeystoneDomainConstraintTest(testtools.TestCase):
 
82
 
 
83
    def test_expected_exceptions(self):
 
84
        self.assertEqual((exceptions.KeystoneDomainNotFound,),
 
85
                         client.KeystoneDomainConstraint.expected_exceptions,
 
86
                         "KeystoneDomainConstraint expected exceptions error")
 
87
 
 
88
    def test_constrain(self):
 
89
        constrain = client.KeystoneDomainConstraint()
 
90
        client_mock = mock.MagicMock()
 
91
        client_plugin_mock = mock.MagicMock()
 
92
        client_plugin_mock.get_domain_id.return_value = None
 
93
        client_mock.client_plugin.return_value = client_plugin_mock
 
94
 
 
95
        self.assertIsNone(constrain.validate_with_client(client_mock,
 
96
                                                         'domain_1'))
 
97
 
 
98
        client_plugin_mock.get_domain_id.assert_called_once_with('domain_1')
 
 
b'\\ No newline at end of file'