File: object_storage_tests.py

package info (click to toggle)
python-softlayer 6.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,508 kB
  • sloc: python: 57,195; makefile: 133; xml: 97; sh: 59
file content (132 lines) | stat: -rw-r--r-- 5,434 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""
    SoftLayer.tests.CLI.modules.object_storage_tests
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    :license: MIT, see LICENSE for more details.
"""
import json
from unittest import mock as mock

from SoftLayer import testing


class ObjectStorageTests(testing.TestCase):

    def test_list_accounts(self):
        result = self.run_command(['object-storage', 'accounts'])

        self.assert_no_fail(result)
        self.assertEqual(json.loads(result.output),
                         [{'apiType': 'S3', 'id': 12345, 'name': 'SLOS12345-1'},
                          {'apiType': 'Swift', 'id': 12346, 'name': 'SLOS12345-2'}]
                         )

    def test_list_endpoints(self):
        accounts = self.set_mock('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getEndpoints')
        accounts.return_value = [
            {
                'legacy': False,
                'region': 'us-geo',
                'type': 'public',
                'url': 's3.us.cloud-object-storage.appdomain.cloud'
            },
            {
                'legacy': False,
                'region': 'us-geo',
                'type': 'private',
                'url': 's3.private.us.cloud-object-storage.appdomain.cloud'
            },
            {
                'legacy': True,
                'location': 'dal06',
                'region': 'regional',
                'type': 'public',
                'url': 's3.dal.cloud-object-storage.appdomain.cloud'
            },
            {
                'legacy': True,
                'location': 'ams03',
                'region': 'singleSite',
                'type': 'private',
                'url': 's3.ams.cloud-object-storage.appdomain.cloud'
            },
        ]

        result = self.run_command(['object-storage', 'endpoints', '123'])

        self.assert_no_fail(result)
        self.assertEqual(json.loads(result.output),
                         [{'Legacy': False,
                           'EndPoint Type': 'Cross Region',
                           'Public/Private': 'Public',
                           'Location/Region': 'us-geo',
                           'Url': 's3.us.cloud-object-storage.appdomain.cloud'},
                          {'Legacy': False,
                           'EndPoint Type': 'Cross Region',
                           'Public/Private': 'Private',
                           'Location/Region': 'us-geo',
                           'Url': 's3.private.us.cloud-object-storage.appdomain.cloud'},
                          {'Legacy': True,
                           'EndPoint Type': 'Region',
                           'Public/Private': 'Public',
                           'Location/Region': 'dal06',
                           'Url': 's3.dal.cloud-object-storage.appdomain.cloud'},
                          {'Legacy': True,
                           'EndPoint Type': 'Single Site',
                           'Public/Private': 'Private',
                           'Location/Region': 'ams03',
                           'Url': 's3.ams.cloud-object-storage.appdomain.cloud'}
                          ])

    def test_create_credential(self):
        result = self.run_command(['object-storage', 'credential', 'create', '100'])
        self.assert_no_fail(result)

    @mock.patch('SoftLayer.CLI.helpers.resolve_id')
    def test_create_credential_by_username(self, resolve_id_mock):
        resolve_id_mock.return_value = 100
        result = self.run_command(['object-storage', 'credential', 'create', 'test'])
        self.assert_no_fail(result)

    def test_delete_credential(self):
        result = self.run_command(['object-storage', 'credential', 'delete', '-c', 100, '100'])
        self.assert_no_fail(result)
        self.assertEqual(result.output, 'true\n')

    @mock.patch('SoftLayer.CLI.helpers.resolve_id')
    def test_delete_credential_by_username(self, resolve_id_mock):
        resolve_id_mock.return_value = 100
        result = self.run_command(['object-storage', 'credential', 'delete', 'test'])
        self.assert_no_fail(result)

    def test_limit_credential(self):
        result = self.run_command(['object-storage', 'credential', 'limit', '100'])

        self.assert_no_fail(result)
        self.assertIn('limit', result.output)

    @mock.patch('SoftLayer.CLI.helpers.resolve_id')
    def test_limit_credential_by_username(self, resolve_id_mock):
        resolve_id_mock.return_value = 100
        result = self.run_command(['object-storage', 'credential', 'limit', 'test'])
        self.assert_no_fail(result)

    def test_list_credential(self):
        result = self.run_command(['object-storage', 'credential', 'list', '100'])
        self.assert_no_fail(result)

    @mock.patch('SoftLayer.CLI.helpers.resolve_id')
    def test_list_credential_by_username(self, resolve_id_mock):
        resolve_id_mock.return_value = 100
        result = self.run_command(['object-storage', 'credential', 'list', 'test'])
        self.assert_no_fail(result)

    def test_object_storage_cancel(self):
        result = self.run_command([
            '--really', 'object-storage', 'cancel', '1234'])

        self.assert_no_fail(result)
        self.assertEqual('Object storage with id 1234 has been marked'
                         ' for cancellation\n', result.output)
        self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem',
                                args=(False, True, None))