Beispiel #1
0
    def test_get_pkg_id_with_files(self, pkg_id_pkginfo_mock):
        '''
            Test getting a the id for a package
        '''
        expected = ['com.apple.this']
        cmd_mock = MagicMock(side_effect=[
            '/path/to/PackageInfo\n/path/to/some/other/fake/PackageInfo',
            '',
            ''
        ])
        pkg_id_pkginfo_mock.side_effect = [['com.apple.this'], []]
        temp_mock = MagicMock(return_value='/tmp/dmg-ABCDEF')
        remove_mock = MagicMock()

        with patch.dict(macpackage.__salt__, {'cmd.run': cmd_mock,
                                              'temp.dir': temp_mock,
                                              'file.remove': remove_mock}):
            out = macpackage.get_pkg_id('/path/to/file.pkg')

            temp_mock.assert_called_once_with(prefix='pkg-')
            cmd_calls = [
                call('xar -t -f /path/to/file.pkg | grep PackageInfo', python_shell=True, output_loglevel='quiet'),
                call('xar -x -f /path/to/file.pkg /path/to/PackageInfo /path/to/some/other/fake/PackageInfo',
                     cwd='/tmp/dmg-ABCDEF', output_loglevel='quiet')
            ]
            cmd_mock.assert_has_calls(cmd_calls)

            pkg_id_pkginfo_calls = [
                call('/path/to/PackageInfo'),
                call('/path/to/some/other/fake/PackageInfo')
            ]
            pkg_id_pkginfo_mock.assert_has_calls(pkg_id_pkginfo_calls)
            remove_mock.assert_called_once_with('/tmp/dmg-ABCDEF')

            self.assertEqual(out, expected)
Beispiel #2
0
    def test_get_pkg_id_with_files(self, pkg_id_pkginfo_mock):
        '''
            Test getting a the id for a package
        '''
        expected = ['com.apple.this']
        cmd_mock = MagicMock(side_effect=[
            '/path/to/PackageInfo\n/path/to/some/other/fake/PackageInfo',
            '',
            ''
        ])
        pkg_id_pkginfo_mock.side_effect = [['com.apple.this'], []]
        temp_mock = MagicMock(return_value='/tmp/dmg-ABCDEF')
        remove_mock = MagicMock()

        with patch.dict(macpackage.__salt__, {'cmd.run': cmd_mock,
                                              'temp.dir': temp_mock,
                                              'file.remove': remove_mock}):
            out = macpackage.get_pkg_id('/path/to/file.pkg')

            temp_mock.assert_called_once_with(prefix='pkg-')
            cmd_calls = [
                call('xar -t -f /path/to/file.pkg | grep PackageInfo', python_shell=True, output_loglevel='quiet'),
                call('xar -x -f /path/to/file.pkg /path/to/PackageInfo /path/to/some/other/fake/PackageInfo',
                     cwd='/tmp/dmg-ABCDEF', output_loglevel='quiet')
            ]
            cmd_mock.assert_has_calls(cmd_calls)

            pkg_id_pkginfo_calls = [
                call('/path/to/PackageInfo'),
                call('/path/to/some/other/fake/PackageInfo')
            ]
            pkg_id_pkginfo_mock.assert_has_calls(pkg_id_pkginfo_calls)
            remove_mock.assert_called_once_with('/tmp/dmg-ABCDEF')

            self.assertEqual(out, expected)
Beispiel #3
0
    def test_get_pkg_id_with_dir(self, pkg_id_dir_mock):
        '''
            Test getting a the id for a package with a directory
        '''
        expected = ['com.apple.this']
        pkg_id_dir_mock.return_value = ['com.apple.this']
        cmd_mock = MagicMock(return_value='Error opening /path/to/file.pkg')
        temp_mock = MagicMock(return_value='/tmp/dmg-ABCDEF')
        remove_mock = MagicMock()

        with patch.dict(macpackage.__salt__, {
                'cmd.run': cmd_mock,
                'temp.dir': temp_mock,
                'file.remove': remove_mock
        }):
            out = macpackage.get_pkg_id('/path/to/file.pkg')

            temp_mock.assert_called_once_with(prefix='pkg-')
            cmd_mock.assert_called_once_with(
                'xar -t -f /path/to/file.pkg | grep PackageInfo',
                python_shell=True,
                output_loglevel='quiet')
            pkg_id_dir_mock.assert_called_once_with('/path/to/file.pkg')
            remove_mock.assert_called_once_with('/tmp/dmg-ABCDEF')

            self.assertEqual(out, expected)
Beispiel #4
0
    def test_get_pkg_id_with_dir(self, pkg_id_dir_mock):
        '''
            Test getting a the id for a package with a directory
        '''
        expected = ['com.apple.this']
        pkg_id_dir_mock.return_value = ['com.apple.this']
        cmd_mock = MagicMock(return_value='Error opening /path/to/file.pkg')
        temp_mock = MagicMock(return_value='/tmp/dmg-ABCDEF')
        remove_mock = MagicMock()

        with patch.dict(macpackage.__salt__, {'cmd.run': cmd_mock,
                                              'temp.dir': temp_mock,
                                              'file.remove': remove_mock}):
            out = macpackage.get_pkg_id('/path/to/file.pkg')

            temp_mock.assert_called_once_with(prefix='pkg-')
            cmd_mock.assert_called_once_with('xar -t -f /path/to/file.pkg | grep PackageInfo',
                                             python_shell=True, output_loglevel='quiet')
            pkg_id_dir_mock.assert_called_once_with('/path/to/file.pkg')
            remove_mock.assert_called_once_with('/tmp/dmg-ABCDEF')

            self.assertEqual(out, expected)