def test_list_snapshots(self): ''' Test parallels.list_snapshots ''' name = 'macvm' guid_str = textwrap.dedent(''' PARENT_SNAPSHOT_ID SNAPSHOT_ID {a5b8999f-5d95-4aff-82de-e515b0101b66} {a5b8999f-5d95-4aff-82de-e515b0101b66} *{a7345be5-ab66-478c-946e-a6c2caf14909} {a5b8999f-5d95-4aff-82de-e515b0101b66} {5da9faef-cb0e-466d-9b41-e5571b62ac2a} ''') # Validate listing all snapshots for the VM mock_prlctl = MagicMock(return_value=guid_str) with patch.object(parallels, 'prlctl', mock_prlctl): parallels.list_snapshots(name) mock_prlctl.assert_called_once_with('snapshot-list', [name], runas=None) # Validate listing all snapshots in tree mode mock_prlctl = MagicMock(return_value=guid_str) with patch.object(parallels, 'prlctl', mock_prlctl): parallels.list_snapshots(name, tree=True) mock_prlctl.assert_called_once_with('snapshot-list', [name, '--tree'], runas=None) # Validate listing a single snapshot snap_name = 'muon' mock_snap_name = MagicMock(return_value=snap_name) with patch.object(parallels, '_validate_snap_name', mock_snap_name): mock_prlctl = MagicMock(return_value=guid_str) with patch.object(parallels, 'prlctl', mock_prlctl): parallels.list_snapshots(name, snap_name) mock_prlctl.assert_called_once_with('snapshot-list', [name, '--id', snap_name], runas=None) # Validate listing snapshot ID and name pairs snap_names = ['electron', 'muon', 'tauon'] mock_snap_name = MagicMock(side_effect=snap_names) with patch.object(parallels, 'snapshot_id_to_name', mock_snap_name): mock_prlctl = MagicMock(return_value=guid_str) with patch.object(parallels, 'prlctl', mock_prlctl): ret = parallels.list_snapshots(name, names=True) for snap_name in snap_names: self.assertIn(snap_name, ret) mock_prlctl.assert_called_once_with('snapshot-list', [name], runas=None)
def test_list_snapshots(self): """ Test parallels.list_snapshots """ name = "macvm" guid_str = textwrap.dedent( """ PARENT_SNAPSHOT_ID SNAPSHOT_ID {a5b8999f-5d95-4aff-82de-e515b0101b66} {a5b8999f-5d95-4aff-82de-e515b0101b66} *{a7345be5-ab66-478c-946e-a6c2caf14909} {a5b8999f-5d95-4aff-82de-e515b0101b66} {5da9faef-cb0e-466d-9b41-e5571b62ac2a} """ ) # Validate listing all snapshots for the VM mock_prlctl = MagicMock(return_value=guid_str) with patch.object(parallels, "prlctl", mock_prlctl): parallels.list_snapshots(name) mock_prlctl.assert_called_once_with("snapshot-list", [name], runas=None) # Validate listing all snapshots in tree mode mock_prlctl = MagicMock(return_value=guid_str) with patch.object(parallels, "prlctl", mock_prlctl): parallels.list_snapshots(name, tree=True) mock_prlctl.assert_called_once_with( "snapshot-list", [name, "--tree"], runas=None ) # Validate listing a single snapshot snap_name = "muon" mock_snap_name = MagicMock(return_value=snap_name) with patch.object(parallels, "_validate_snap_name", mock_snap_name): mock_prlctl = MagicMock(return_value=guid_str) with patch.object(parallels, "prlctl", mock_prlctl): parallels.list_snapshots(name, snap_name) mock_prlctl.assert_called_once_with( "snapshot-list", [name, "--id", snap_name], runas=None ) # Validate listing snapshot ID and name pairs snap_names = ["electron", "muon", "tauon"] mock_snap_name = MagicMock(side_effect=snap_names) with patch.object(parallels, "snapshot_id_to_name", mock_snap_name): mock_prlctl = MagicMock(return_value=guid_str) with patch.object(parallels, "prlctl", mock_prlctl): ret = parallels.list_snapshots(name, names=True) for snap_name in snap_names: self.assertIn(snap_name, ret) mock_prlctl.assert_called_once_with("snapshot-list", [name], runas=None)