1
# Copyright (c) 2013 Rackspace, Inc.
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
16
from barbicanclient import verifications as vers
17
from barbicanclient.openstack.common import timeutils
18
from barbicanclient.test import test_client
21
class VerificationData(object):
23
self.created = str(timeutils.utcnow())
25
self.resource_type = 'image'
26
self.resource_ref = 'http://www.image.com/v1/images/1234'
27
self.resource_action = 'vm_attach'
28
self.impersonation_allowed = True
30
self.verification_dict = {'created': self.created,
31
'resource_type': self.resource_type,
32
'resource_ref': self.resource_ref,
33
'resource_action': self.resource_action,
34
'impersonation_allowed':
35
self.impersonation_allowed}
37
def get_dict(self, verification_ref):
38
verify = self.verification_dict
39
verify['verification_ref'] = verification_ref
43
class WhenTestingVerifications(test_client.BaseEntityResource):
46
self._setUp('verifications')
48
self.verify = VerificationData()
50
self.manager = vers.VerificationManager(self.api)
52
def test_should_entity_str(self):
53
verif_obj = vers.Verification(self.verify.get_dict(self.entity_href))
54
verif_obj.error_status_code = '500'
55
verif_obj.error_reason = 'Something is broken'
56
self.assertIn('resource_type: ' + self.verify.resource_type,
58
self.assertIn('error_status_code: 500', str(verif_obj))
60
def test_should_entity_repr(self):
61
verif = vers.Verification(self.verify.get_dict(self.entity_href))
62
self.assertIn('verification_ref=' + self.entity_href,
65
def test_should_create(self):
66
self.api.post.return_value = {'verification_ref': self.entity_href}
68
order_href = self.manager\
69
.create(resource_type=self.verify.resource_type,
70
resource_ref=self.verify.resource_ref,
71
resource_action=self.verify.resource_action)
73
self.assertEqual(self.entity_href, order_href)
75
# Verify the correct URL was used to make the call.
76
args, kwargs = self.api.post.call_args
78
self.assertEqual(self.entity, entity_resp)
80
# Verify that correct information was sent in the call.
82
self.assertEqual(self.verify.resource_type,
83
verify_req['resource_type'])
84
self.assertEqual(self.verify.resource_action,
85
verify_req['resource_action'])
86
self.assertEqual(self.verify.resource_ref,
87
verify_req['resource_ref'])
89
def test_should_get(self):
90
self.api.get.return_value = self.verify.get_dict(self.entity_href)
92
verify = self.manager.get(verification_ref=self.entity_href)
93
self.assertIsInstance(verify, vers.Verification)
94
self.assertEqual(self.entity_href, verify.verif_ref)
96
# Verify the correct URL was used to make the call.
97
args, kwargs = self.api.get.call_args
99
self.assertEqual(self.entity_href, url)
101
def test_should_delete(self):
102
self.manager.delete(verification_ref=self.entity_href)
104
# Verify the correct URL was used to make the call.
105
args, kwargs = self.api.delete.call_args
107
self.assertEqual(self.entity_href, url)
109
def test_should_get_list(self):
110
verify_resp = self.verify.get_dict(self.entity_href)
111
self.api.get.return_value = {"verifications":
112
[verify_resp for v in range(3)]}
114
verifies = self.manager.list(limit=10, offset=5)
115
self.assertTrue(len(verifies) == 3)
116
self.assertIsInstance(verifies[0], vers.Verification)
117
self.assertEqual(self.entity_href, verifies[0].verif_ref)
119
# Verify the correct URL was used to make the call.
120
args, kwargs = self.api.get.call_args
122
self.assertEqual(self.entity_base[:-1], url)
124
# Verify that correct information was sent in the call.
126
self.assertEqual(10, params['limit'])
127
self.assertEqual(5, params['offset'])
129
def test_should_fail_get_no_href(self):
130
self.assertRaises(ValueError, self.manager.get, None)
132
def test_should_fail_delete_no_href(self):
133
self.assertRaises(ValueError, self.manager.delete, None)