File: test_share_group_snapshot.py

package info (click to toggle)
python-openstacksdk 4.4.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,352 kB
  • sloc: python: 122,960; sh: 153; makefile: 23
file content (106 lines) | stat: -rw-r--r-- 4,070 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from unittest import mock

from keystoneauth1 import adapter

from openstack.shared_file_system.v2 import share_group_snapshot
from openstack.tests.unit import base

IDENTIFIER = '38152b6d-e1b5-465f-91bc-20bca4676a2a'
EXAMPLE = {
    "id": IDENTIFIER,
    "name": "snapshot_1",
    "created_at": "2021-10-24T19:36:49.555325",
    "status": "available",
    "description": "first snapshot of sg-1",
    "project_id": "7343d2f7770b4eb6a7bc33f44dcee1e0",
    "share_group_id": "fb41512f-7c49-4304-afb1-66573c7feb14",
}


class TestShareGroupSnapshot(base.TestCase):
    def test_basic(self):
        share_group_snapshots = share_group_snapshot.ShareGroupSnapshot()
        self.assertEqual(
            'share_group_snapshot', share_group_snapshots.resource_key
        )
        self.assertEqual(
            'share_group_snapshots', share_group_snapshots.resources_key
        )
        self.assertEqual(
            '/share-group-snapshots', share_group_snapshots.base_path
        )
        self.assertTrue(share_group_snapshots.allow_create)
        self.assertTrue(share_group_snapshots.allow_fetch)
        self.assertTrue(share_group_snapshots.allow_commit)
        self.assertTrue(share_group_snapshots.allow_delete)
        self.assertTrue(share_group_snapshots.allow_list)
        self.assertFalse(share_group_snapshots.allow_head)

    def test_make_share_groups(self):
        share_group_snapshots = share_group_snapshot.ShareGroupSnapshot(
            **EXAMPLE
        )
        self.assertEqual(EXAMPLE['id'], share_group_snapshots.id)
        self.assertEqual(EXAMPLE['name'], share_group_snapshots.name)
        self.assertEqual(
            EXAMPLE['created_at'], share_group_snapshots.created_at
        )
        self.assertEqual(EXAMPLE['status'], share_group_snapshots.status)
        self.assertEqual(
            EXAMPLE['description'], share_group_snapshots.description
        )
        self.assertEqual(
            EXAMPLE['project_id'], share_group_snapshots.project_id
        )
        self.assertEqual(
            EXAMPLE['share_group_id'], share_group_snapshots.share_group_id
        )


class TestShareGroupSnapshotActions(TestShareGroupSnapshot):
    def setUp(self):
        super(TestShareGroupSnapshot, self).setUp()
        self.resp = mock.Mock()
        self.resp.body = None
        self.resp.status_code = 200
        self.resp.json = mock.Mock(return_value=self.resp.body)
        self.sess = mock.Mock(spec=adapter.Adapter)
        self.sess.default_microversion = '3.0'
        self.sess.post = mock.Mock(return_value=self.resp)
        self.sess._get_connection = mock.Mock(return_value=self.cloud)

    def test_reset_status(self):
        sot = share_group_snapshot.ShareGroupSnapshot(**EXAMPLE)
        self.assertIsNone(sot.reset_status(self.sess, 'available'))
        url = f'share-group-snapshots/{IDENTIFIER}/action'
        body = {"reset_status": {"status": 'available'}}
        headers = {'Accept': ''}
        self.sess.post.assert_called_with(
            url,
            json=body,
            headers=headers,
            microversion=self.sess.default_microversion,
        )

    def test_get_members(self):
        sot = share_group_snapshot.ShareGroupSnapshot(**EXAMPLE)
        sot.get_members(self.sess)
        url = f'share-group-snapshots/{IDENTIFIER}/members'
        headers = {'Accept': ''}
        self.sess.get.assert_called_with(
            url,
            headers=headers,
            microversion=self.sess.default_microversion,
        )