Exemplo n.º 1
0
    def test__validate_snap_name(self):
        '''
        Test parallels._validate_snap_name
        '''
        name = 'macvm'
        snap_id = 'a5b8999f-5d95-4aff-82de-e515b0101b66'

        # Validate a GUID passthrough
        self.assertEqual(parallels._validate_snap_name(name, snap_id), snap_id)

        # Validate an unicode name
        mock_snap_symb = MagicMock(return_value=snap_id)
        with patch.object(parallels, 'snapshot_name_to_id', mock_snap_symb):
            self.assertEqual(parallels._validate_snap_name(name, u'π'), snap_id)
            mock_snap_symb.assert_called_once_with(name, u'π', strict=True, runas=None)

        # Validate an ascii name
        mock_snap_name = MagicMock(return_value=snap_id)
        with patch.object(parallels, 'snapshot_name_to_id', mock_snap_name):
            self.assertEqual(parallels._validate_snap_name(name, 'pion'), snap_id)
            mock_snap_name.assert_called_once_with(name, 'pion', strict=True, runas=None)

        # Validate a numerical name
        mock_snap_numb = MagicMock(return_value=snap_id)
        with patch.object(parallels, 'snapshot_name_to_id', mock_snap_numb):
            self.assertEqual(parallels._validate_snap_name(name, '3.14159'), snap_id)
            mock_snap_numb.assert_called_once_with(name, u'3.14159', strict=True, runas=None)

        # Validate not strict (think neutrino oscillation)
        mock_snap_non_strict = MagicMock(return_value=snap_id)
        with patch.object(parallels, 'snapshot_name_to_id', mock_snap_non_strict):
            self.assertEqual(parallels._validate_snap_name(name, u'e_ν', strict=False), snap_id)
            mock_snap_non_strict.assert_called_once_with(name, u'e_ν', strict=False, runas=None)
Exemplo n.º 2
0
    def test__validate_snap_name(self):
        '''
        Test parallels._validate_snap_name
        '''
        name = 'macvm'
        snap_id = 'a5b8999f-5d95-4aff-82de-e515b0101b66'

        # Validate a GUID passthrough
        self.assertEqual(parallels._validate_snap_name(name, snap_id), snap_id)

        # Validate an unicode name
        mock_snap_symb = MagicMock(return_value=snap_id)
        with patch.object(parallels, 'snapshot_name_to_id', mock_snap_symb):
            self.assertEqual(parallels._validate_snap_name(name, u'π'), snap_id)
            mock_snap_symb.assert_called_once_with(name, u'π', strict=True, runas=None)

        # Validate an ascii name
        mock_snap_name = MagicMock(return_value=snap_id)
        with patch.object(parallels, 'snapshot_name_to_id', mock_snap_name):
            self.assertEqual(parallels._validate_snap_name(name, 'pion'), snap_id)
            mock_snap_name.assert_called_once_with(name, 'pion', strict=True, runas=None)

        # Validate a numerical name
        mock_snap_numb = MagicMock(return_value=snap_id)
        with patch.object(parallels, 'snapshot_name_to_id', mock_snap_numb):
            self.assertEqual(parallels._validate_snap_name(name, '3.14159'), snap_id)
            mock_snap_numb.assert_called_once_with(name, u'3.14159', strict=True, runas=None)

        # Validate not strict (think neutrino oscillation)
        mock_snap_non_strict = MagicMock(return_value=snap_id)
        with patch.object(parallels, 'snapshot_name_to_id', mock_snap_non_strict):
            self.assertEqual(parallels._validate_snap_name(name, u'e_ν', strict=False), snap_id)
            mock_snap_non_strict.assert_called_once_with(name, u'e_ν', strict=False, runas=None)
Exemplo n.º 3
0
    def test__validate_snap_name(self):
        """
        Test parallels._validate_snap_name
        """
        name = "macvm"
        snap_id = "a5b8999f-5d95-4aff-82de-e515b0101b66"

        # Validate a GUID passthrough
        self.assertEqual(parallels._validate_snap_name(name, snap_id), snap_id)

        # Validate an unicode name
        mock_snap_symb = MagicMock(return_value=snap_id)
        with patch.object(parallels, "snapshot_name_to_id", mock_snap_symb):
            self.assertEqual(parallels._validate_snap_name(name, "π"), snap_id)
            mock_snap_symb.assert_called_once_with(name,
                                                   "π",
                                                   strict=True,
                                                   runas=None)

        # Validate an ascii name
        mock_snap_name = MagicMock(return_value=snap_id)
        with patch.object(parallels, "snapshot_name_to_id", mock_snap_name):
            self.assertEqual(parallels._validate_snap_name(name, "pion"),
                             snap_id)
            mock_snap_name.assert_called_once_with(name,
                                                   "pion",
                                                   strict=True,
                                                   runas=None)

        # Validate a numerical name
        mock_snap_numb = MagicMock(return_value=snap_id)
        with patch.object(parallels, "snapshot_name_to_id", mock_snap_numb):
            self.assertEqual(parallels._validate_snap_name(name, "3.14159"),
                             snap_id)
            mock_snap_numb.assert_called_once_with(name,
                                                   "3.14159",
                                                   strict=True,
                                                   runas=None)

        # Validate not strict (think neutrino oscillation)
        mock_snap_non_strict = MagicMock(return_value=snap_id)
        with patch.object(parallels, "snapshot_name_to_id",
                          mock_snap_non_strict):
            self.assertEqual(
                parallels._validate_snap_name(name, "e_ν", strict=False),
                snap_id)
            mock_snap_non_strict.assert_called_once_with(name,
                                                         "e_ν",
                                                         strict=False,
                                                         runas=None)