|
5 | 5 | :license: MIT, see LICENSE for more details. |
6 | 6 | """ |
7 | 7 | import json |
| 8 | +from unittest import mock |
8 | 9 |
|
9 | 10 | from SoftLayer import testing |
10 | 11 |
|
@@ -39,68 +40,44 @@ def test_list_endpoints(self): |
39 | 40 | 'public': 'https://dal05/auth/v1.0/'}]) |
40 | 41 |
|
41 | 42 | def test_create_credential(self): |
42 | | - accounts = self.set_mock('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'credentialCreate') |
43 | | - accounts.return_value = { |
44 | | - "accountId": "12345", |
45 | | - "createDate": "2019-04-05T13:25:25-06:00", |
46 | | - "id": 11111, |
47 | | - "password": "nwUEUsx6PiEoN0B1Xe9z9hUCy", |
48 | | - "username": "XfHhBNBPlPdl", |
49 | | - "type": { |
50 | | - "description": "A credential for generating S3 Compatible Signatures.", |
51 | | - "keyName": "S3_COMPATIBLE_SIGNATURE", |
52 | | - "name": "S3 Compatible Signature" |
53 | | - } |
54 | | - } |
55 | | - |
56 | 43 | result = self.run_command(['object-storage', 'credential', 'create', '100']) |
| 44 | + self.assert_no_fail(result) |
57 | 45 |
|
| 46 | + @mock.patch('SoftLayer.CLI.helpers.resolve_id') |
| 47 | + def test_create_credential_by_username(self, resolve_id_mock): |
| 48 | + resolve_id_mock.return_value = 100 |
| 49 | + result = self.run_command(['object-storage', 'credential', 'create', 'test']) |
58 | 50 | self.assert_no_fail(result) |
59 | | - self.assertEqual(json.loads(result.output), |
60 | | - [{'id': 11111, |
61 | | - 'password': 'nwUEUsx6PiEoN0B1Xe9z9hUCy', |
62 | | - 'type_name': 'S3 Compatible Signature', |
63 | | - 'username': 'XfHhBNBPlPdl'}] |
64 | | - ) |
65 | 51 |
|
66 | 52 | def test_delete_credential(self): |
67 | | - accounts = self.set_mock('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'credentialDelete') |
68 | | - accounts.return_value = True |
69 | | - |
70 | 53 | result = self.run_command(['object-storage', 'credential', 'delete', '-c', 100, '100']) |
71 | | - |
72 | 54 | self.assert_no_fail(result) |
73 | 55 | self.assertEqual(result.output, 'True\n') |
74 | 56 |
|
75 | | - def test_limit_credential(self): |
76 | | - accounts = self.set_mock('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getCredentialLimit') |
77 | | - accounts.return_value = 2 |
| 57 | + @mock.patch('SoftLayer.CLI.helpers.resolve_id') |
| 58 | + def test_delete_credential_by_username(self, resolve_id_mock): |
| 59 | + resolve_id_mock.return_value = 100 |
| 60 | + result = self.run_command(['object-storage', 'credential', 'delete', 'test']) |
| 61 | + self.assert_no_fail(result) |
78 | 62 |
|
| 63 | + def test_limit_credential(self): |
79 | 64 | result = self.run_command(['object-storage', 'credential', 'limit', '100']) |
80 | 65 |
|
81 | 66 | self.assert_no_fail(result) |
82 | | - self.assertEqual(json.loads(result.output), [{'limit': 2}]) |
| 67 | + self.assertIn('limit', result.output) |
83 | 68 |
|
84 | | - def test_list_credential(self): |
85 | | - accounts = self.set_mock('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getCredentials') |
86 | | - accounts.return_value = [{'id': 1103123, |
87 | | - 'password': 'nwUEUsx6PiEoN0B1Xe9z9hUCyXM', |
88 | | - 'type': {'name': 'S3 Compatible Signature'}, |
89 | | - 'username': 'XfHhBNBPlPdlWya'}, |
90 | | - {'id': 1103333, |
91 | | - 'password': 'nwUEUsx6PiEoN0B1Xe9z9', |
92 | | - 'type': {'name': 'S3 Compatible Signature'}, |
93 | | - 'username': 'XfHhBNBPlPd'}] |
| 69 | + @mock.patch('SoftLayer.CLI.helpers.resolve_id') |
| 70 | + def test_limit_credential_by_username(self, resolve_id_mock): |
| 71 | + resolve_id_mock.return_value = 100 |
| 72 | + result = self.run_command(['object-storage', 'credential', 'limit', 'test']) |
| 73 | + self.assert_no_fail(result) |
94 | 74 |
|
| 75 | + def test_list_credential(self): |
95 | 76 | result = self.run_command(['object-storage', 'credential', 'list', '100']) |
| 77 | + self.assert_no_fail(result) |
96 | 78 |
|
| 79 | + @mock.patch('SoftLayer.CLI.helpers.resolve_id') |
| 80 | + def test_list_credential_by_username(self, resolve_id_mock): |
| 81 | + resolve_id_mock.return_value = 100 |
| 82 | + result = self.run_command(['object-storage', 'credential', 'list', 'test']) |
97 | 83 | self.assert_no_fail(result) |
98 | | - self.assertEqual(json.loads(result.output), |
99 | | - [{'id': 1103123, |
100 | | - 'password': 'nwUEUsx6PiEoN0B1Xe9z9hUCyXM', |
101 | | - 'type_name': 'S3 Compatible Signature', |
102 | | - 'username': 'XfHhBNBPlPdlWya'}, |
103 | | - {'id': 1103333, |
104 | | - 'password': 'nwUEUsx6PiEoN0B1Xe9z9', |
105 | | - 'type_name': 'S3 Compatible Signature', |
106 | | - 'username': 'XfHhBNBPlPd'}]) |
0 commit comments