Skip to content

Commit 419ece1

Browse files
Zuulopenstack-gerrit
Zuul
authored andcommitted
Merge "tests: Add tests for v2 volume transfer module"
2 parents bbe9c96 + 13098d8 commit 419ece1

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
from unittest import mock
14+
15+
from keystoneauth1 import adapter
16+
17+
from openstack.block_storage.v2 import transfer
18+
from openstack.tests.unit import base
19+
20+
21+
FAKE_ID = "09d18b36-9e8d-4438-a4da-3f5eff5e1130"
22+
FAKE_VOL_ID = "390de1bc-19d1-41e7-ba67-c492bb36cae5"
23+
FAKE_VOL_NAME = "test-volume"
24+
FAKE_TRANSFER = "7d048960-7c3f-4bf0-952f-4312fdea1dec"
25+
FAKE_AUTH_KEY = "95bc670c0068821d"
26+
27+
TRANSFER = {
28+
"auth_key": FAKE_AUTH_KEY,
29+
"created_at": "2023-06-27T08:47:23.035010",
30+
"id": FAKE_ID,
31+
"name": FAKE_VOL_NAME,
32+
"volume_id": FAKE_VOL_ID,
33+
}
34+
35+
36+
class TestTransfer(base.TestCase):
37+
def setUp(self):
38+
super().setUp()
39+
self.resp = mock.Mock()
40+
self.resp.body = {'transfer': TRANSFER}
41+
self.resp.json = mock.Mock(return_value=self.resp.body)
42+
self.resp.headers = {}
43+
self.resp.status_code = 202
44+
45+
self.sess = mock.Mock(spec=adapter.Adapter)
46+
self.sess.post = mock.Mock(return_value=self.resp)
47+
self.sess.default_microversion = "3.55"
48+
49+
def test_basic(self):
50+
sot = transfer.Transfer(TRANSFER)
51+
self.assertEqual("transfer", sot.resource_key)
52+
self.assertEqual("transfers", sot.resources_key)
53+
self.assertEqual("/os-volume-transfer", sot.base_path)
54+
self.assertTrue(sot.allow_create)
55+
56+
self.assertDictEqual(
57+
{
58+
"limit": "limit",
59+
"marker": "marker",
60+
},
61+
sot._query_mapping._mapping,
62+
)
63+
64+
def test_create(self):
65+
sot = transfer.Transfer(**TRANSFER)
66+
self.assertEqual(TRANSFER["auth_key"], sot.auth_key)
67+
self.assertEqual(TRANSFER["created_at"], sot.created_at)
68+
self.assertEqual(TRANSFER["id"], sot.id)
69+
self.assertEqual(TRANSFER["name"], sot.name)
70+
self.assertEqual(TRANSFER["volume_id"], sot.volume_id)
71+
72+
def test_accept(self):
73+
sot = transfer.Transfer()
74+
sot.id = FAKE_TRANSFER
75+
76+
sot.accept(self.sess, auth_key=FAKE_AUTH_KEY)
77+
self.sess.post.assert_called_with(
78+
f'os-volume-transfer/{FAKE_TRANSFER}/accept',
79+
json={
80+
'accept': {
81+
'auth_key': FAKE_AUTH_KEY,
82+
}
83+
},
84+
)

0 commit comments

Comments
 (0)