|
1 | 1 | from unittest import TestCase |
| 2 | +from freezegun import freeze_time |
2 | 3 |
|
3 | 4 | import jsonpickle |
4 | 5 | from cloudshell.api.cloudshell_api import ResourceInfo |
@@ -36,6 +37,8 @@ def setUp(self): |
36 | 37 | remote_resource.uuid = 'this is full uuis of the remote resource' |
37 | 38 | self.connection_details = Mock() |
38 | 39 | self.context.resource = self.resource |
| 40 | + self.context.resource.app_context = Mock() |
| 41 | + self.context.remote_endpoints = Mock() |
39 | 42 | self.context.remote_endpoints = [self.resource] |
40 | 43 | self.command_orchestrator = CommandOrchestrator() |
41 | 44 | self.command_orchestrator.command_wrapper.execute_command_with_connection = Mock(return_value=True) |
@@ -131,7 +134,7 @@ def test_get_snapshots(self): |
131 | 134 | self.command_orchestrator.get_snapshots(self.context) |
132 | 135 | self.assertTrue(self.command_orchestrator.command_wrapper.execute_command_with_connection.called) |
133 | 136 |
|
134 | | - def test_orchestration_save(self): |
| 137 | + def test_orchestration_save_double_quotes_in_snapshot_name_should_be_stripped(self): |
135 | 138 | # Arrange |
136 | 139 | with patch(SAVE_SNAPSHOT) as save_snapshot_mock: |
137 | 140 | save_snapshot_mock.return_value = '"new_snapshot"' |
@@ -159,6 +162,30 @@ def test_orchestration_save(self): |
159 | 162 | self.assertEqual(saved_result_dict['saved_artifacts_info']['resource_name'], 'vcenter') |
160 | 163 | self.assertIsNotNone(saved_result_dict['saved_artifacts_info']['created_date']) |
161 | 164 |
|
| 165 | + @freeze_time("1984-12-31 11:12:13.4567") |
| 166 | + def test_orchestration_save_snapshot_name_should_contain_full_datetime(self): |
| 167 | + # Arrange |
| 168 | + with patch(SAVE_SNAPSHOT) as save_snapshot_mock: |
| 169 | + save_snapshot_mock.return_value = '"new_snapshot"' |
| 170 | + |
| 171 | + remote_command_context = create_autospec(ResourceRemoteCommandContext) |
| 172 | + remote_command_context.resource = create_autospec(ResourceContextDetails) |
| 173 | + remote_command_context.resource.fullname = 'vcenter' |
| 174 | + endpoint = create_autospec(ResourceContextDetails) |
| 175 | + endpoint.fullname = 'vm_111' |
| 176 | + endpoint.app_context = create_autospec(AppContext) |
| 177 | + endpoint.app_context.deployed_app_json = '{"vmdetails": {"uid": "vm_uuid1"}}' |
| 178 | + remote_command_context.remote_endpoints = [endpoint] |
| 179 | + |
| 180 | + # Act |
| 181 | + CommandOrchestrator().orchestration_save(context=remote_command_context, |
| 182 | + mode='shallow', |
| 183 | + custom_params=None) |
| 184 | + |
| 185 | + # Assert |
| 186 | + args, kwargs = save_snapshot_mock.call_args |
| 187 | + self.assertEqual(kwargs['snapshot_name'], "84_12_31 11_12_13_456700") |
| 188 | + |
162 | 189 | def test_orchestration_restore(self): |
163 | 190 | # Arrange |
164 | 191 | with patch(RESTORE_SNAPSHOT) as mock_restore_snapshot: |
|
0 commit comments