def test_snapshot_id_to_name(self): """ Test parallels.snapshot_id_to_name """ name = "macvm" snap_id = "a5b8999f-5d95-4aff-82de-e515b0101b66" # Invalid GUID raises error self.assertRaises( SaltInvocationError, parallels.snapshot_id_to_name, name, "{8-4-4-4-12}" ) # Empty return from prlctl raises error (name/snap_id mismatch?) mock_no_data = MagicMock(return_value="") with patch.object(parallels, "prlctl", mock_no_data): self.assertRaises( SaltInvocationError, parallels.snapshot_id_to_name, name, snap_id ) # Data returned from prlctl is invalid YAML mock_invalid_data = MagicMock(return_value="[string theory is falsifiable}") with patch.object(parallels, "prlctl", mock_invalid_data): snap_name = parallels.snapshot_id_to_name(name, snap_id) self.assertEqual(snap_name, "") # Data returned from prlctl does not render as a dictionary mock_unknown_data = MagicMock(return_value="['sfermions', 'bosinos']") with patch.object(parallels, "prlctl", mock_unknown_data): snap_name = parallels.snapshot_id_to_name(name, snap_id) self.assertEqual(snap_name, "") # Snapshot is unnamed mock_no_name = MagicMock(return_value="Name:") with patch.object(parallels, "prlctl", mock_no_name): snap_name = parallels.snapshot_id_to_name(name, snap_id) self.assertEqual(snap_name, "") # If strict, then raise an error when name is not found mock_no_name = MagicMock(return_value="Name:") with patch.object(parallels, "prlctl", mock_no_name): self.assertRaises( SaltInvocationError, parallels.snapshot_id_to_name, name, snap_id, strict=True, ) # Return name when found mock_yes_name = MagicMock(return_value="Name: top") with patch.object(parallels, "prlctl", mock_yes_name): snap_name = parallels.snapshot_id_to_name(name, snap_id) self.assertEqual(snap_name, "top")
def test_snapshot_id_to_name(self): ''' Test parallels.snapshot_id_to_name ''' name = 'macvm' snap_id = 'a5b8999f-5d95-4aff-82de-e515b0101b66' # Invalid GUID raises error self.assertRaises(SaltInvocationError, parallels.snapshot_id_to_name, name, '{8-4-4-4-12}') # Empty return from prlctl raises error (name/snap_id mismatch?) mock_no_data = MagicMock(return_value='') with patch.object(parallels, 'prlctl', mock_no_data): self.assertRaises(SaltInvocationError, parallels.snapshot_id_to_name, name, snap_id) # Data returned from prlctl is invalid YAML mock_invalid_data = MagicMock(return_value='[string theory is falsifiable}') with patch.object(parallels, 'prlctl', mock_invalid_data): snap_name = parallels.snapshot_id_to_name(name, snap_id) self.assertEqual(snap_name, '') # Data returned from prlctl does not render as a dictionary mock_unknown_data = MagicMock(return_value="['sfermions', 'bosinos']") with patch.object(parallels, 'prlctl', mock_unknown_data): snap_name = parallels.snapshot_id_to_name(name, snap_id) self.assertEqual(snap_name, '') # Snapshot is unnamed mock_no_name = MagicMock(return_value='Name:') with patch.object(parallels, 'prlctl', mock_no_name): snap_name = parallels.snapshot_id_to_name(name, snap_id) self.assertEqual(snap_name, '') # If strict, then raise an error when name is not found mock_no_name = MagicMock(return_value='Name:') with patch.object(parallels, 'prlctl', mock_no_name): self.assertRaises(SaltInvocationError, parallels.snapshot_id_to_name, name, snap_id, strict=True) # Return name when found mock_yes_name = MagicMock(return_value='Name: top') with patch.object(parallels, 'prlctl', mock_yes_name): snap_name = parallels.snapshot_id_to_name(name, snap_id) self.assertEqual(snap_name, 'top')