def test_snapshot_name_to_id(self): """ Test parallels.snapshot_name_to_id """ name = "macvm" snap_ids = [ "a5b8999f-5d95-4aff-82de-e515b0101b66", "a7345be5-ab66-478c-946e-a6c2caf14909", ] snap_id = snap_ids[0] guid_str = textwrap.dedent( """ PARENT_SNAPSHOT_ID SNAPSHOT_ID {a5b8999f-5d95-4aff-82de-e515b0101b66} {a5b8999f-5d95-4aff-82de-e515b0101b66} *{a7345be5-ab66-478c-946e-a6c2caf14909} """ ) mock_guids = MagicMock(return_value=guid_str) # Raise error when no IDs found for snapshot name with patch.object(parallels, "prlctl", mock_guids): mock_no_names = MagicMock(return_value=[]) with patch.object(parallels, "snapshot_id_to_name", mock_no_names): self.assertRaises( SaltInvocationError, parallels.snapshot_name_to_id, name, "graviton" ) # Validate singly-valued name with patch.object(parallels, "prlctl", mock_guids): mock_one_name = MagicMock(side_effect=[u"", u"ν_e"]) with patch.object(parallels, "snapshot_id_to_name", mock_one_name): self.assertEqual( parallels.snapshot_name_to_id(name, u"ν_e"), snap_ids[1] ) # Validate multiply-valued name with patch.object(parallels, "prlctl", mock_guids): mock_many_names = MagicMock(side_effect=[u"J/Ψ", u"J/Ψ"]) with patch.object(parallels, "snapshot_id_to_name", mock_many_names): self.assertEqual( sorted(parallels.snapshot_name_to_id(name, u"J/Ψ")), sorted(snap_ids), ) # Raise error for multiply-valued name with patch.object(parallels, "prlctl", mock_guids): mock_many_names = MagicMock(side_effect=[u"J/Ψ", u"J/Ψ"]) with patch.object(parallels, "snapshot_id_to_name", mock_many_names): self.assertRaises( SaltInvocationError, parallels.snapshot_name_to_id, name, u"J/Ψ", strict=True, )
def test_snapshot_name_to_id(self): ''' Test parallels.snapshot_name_to_id ''' name = 'macvm' snap_ids = [ 'a5b8999f-5d95-4aff-82de-e515b0101b66', 'a7345be5-ab66-478c-946e-a6c2caf14909' ] snap_id = snap_ids[0] guid_str = textwrap.dedent(''' PARENT_SNAPSHOT_ID SNAPSHOT_ID {a5b8999f-5d95-4aff-82de-e515b0101b66} {a5b8999f-5d95-4aff-82de-e515b0101b66} *{a7345be5-ab66-478c-946e-a6c2caf14909} ''') mock_guids = MagicMock(return_value=guid_str) # Raise error when no IDs found for snapshot name with patch.object(parallels, 'prlctl', mock_guids): mock_no_names = MagicMock(return_value=[]) with patch.object(parallels, 'snapshot_id_to_name', mock_no_names): self.assertRaises(SaltInvocationError, parallels.snapshot_name_to_id, name, 'graviton') # Validate singly-valued name with patch.object(parallels, 'prlctl', mock_guids): mock_one_name = MagicMock(side_effect=[u'', u'ν_e']) with patch.object(parallels, 'snapshot_id_to_name', mock_one_name): self.assertEqual(parallels.snapshot_name_to_id(name, u'ν_e'), snap_id) # Validate multiply-valued name with patch.object(parallels, 'prlctl', mock_guids): mock_many_names = MagicMock(side_effect=[u'J/Ψ', u'J/Ψ']) with patch.object(parallels, 'snapshot_id_to_name', mock_many_names): self.assertEqual( sorted(parallels.snapshot_name_to_id(name, u'J/Ψ')), sorted(snap_ids)) # Raise error for multiply-valued name with patch.object(parallels, 'prlctl', mock_guids): mock_many_names = MagicMock(side_effect=[u'J/Ψ', u'J/Ψ']) with patch.object(parallels, 'snapshot_id_to_name', mock_many_names): self.assertRaises(SaltInvocationError, parallels.snapshot_name_to_id, name, u'J/Ψ', strict=True)
def test_snapshot_name_to_id(self): ''' Test parallels.snapshot_name_to_id ''' name = 'macvm' snap_ids = ['a5b8999f-5d95-4aff-82de-e515b0101b66', 'a7345be5-ab66-478c-946e-a6c2caf14909'] snap_id = snap_ids[0] guid_str = textwrap.dedent(''' PARENT_SNAPSHOT_ID SNAPSHOT_ID {a5b8999f-5d95-4aff-82de-e515b0101b66} {a5b8999f-5d95-4aff-82de-e515b0101b66} *{a7345be5-ab66-478c-946e-a6c2caf14909} ''') mock_guids = MagicMock(return_value=guid_str) # Raise error when no IDs found for snapshot name with patch.object(parallels, 'prlctl', mock_guids): mock_no_names = MagicMock(return_value=[]) with patch.object(parallels, 'snapshot_id_to_name', mock_no_names): self.assertRaises(SaltInvocationError, parallels.snapshot_name_to_id, name, 'graviton') # Validate singly-valued name with patch.object(parallels, 'prlctl', mock_guids): mock_one_name = MagicMock(side_effect=[u'', u'ν_e']) with patch.object(parallels, 'snapshot_id_to_name', mock_one_name): self.assertEqual(parallels.snapshot_name_to_id(name, u'ν_e'), snap_ids[1]) # Validate multiply-valued name with patch.object(parallels, 'prlctl', mock_guids): mock_many_names = MagicMock(side_effect=[u'J/Ψ', u'J/Ψ']) with patch.object(parallels, 'snapshot_id_to_name', mock_many_names): self.assertEqual(sorted(parallels.snapshot_name_to_id(name, u'J/Ψ')), sorted(snap_ids)) # Raise error for multiply-valued name with patch.object(parallels, 'prlctl', mock_guids): mock_many_names = MagicMock(side_effect=[u'J/Ψ', u'J/Ψ']) with patch.object(parallels, 'snapshot_id_to_name', mock_many_names): self.assertRaises(SaltInvocationError, parallels.snapshot_name_to_id, name, u'J/Ψ', strict=True)