def test_get_pkg_id_from_pkginfo_no_file():
    """
    Test getting a package id from pkginfo file when it doesn't exist
    """
    expected = []
    mock = MagicMock(return_value="No such file")
    with patch.dict(macpackage.__salt__, {"cmd.run": mock}):
        out = macpackage._get_pkg_id_from_pkginfo("/tmp/dmg-X/PackageInfo")
        cmd = ("cat /tmp/dmg-X/PackageInfo | grep -Eo"
               " 'identifier=\"[a-zA-Z.0-9\\-]*\"' | cut -c 13- | tr -d '\"'")
        mock.assert_called_once_with(cmd, python_shell=True)
        assert out == expected
Exemple #2
0
 def test_get_pkg_id_from_pkginfo_no_file(self):
     '''
         Test getting a package id from pkginfo file when it doesn't exist
     '''
     expected = []
     mock = MagicMock(return_value='No such file')
     with patch.dict(macpackage.__salt__, {'cmd.run': mock}):
         out = macpackage._get_pkg_id_from_pkginfo('/tmp/dmg-X/PackageInfo')
         cmd = 'cat /tmp/dmg-X/PackageInfo | grep -Eo \'identifier="[a-zA-Z.0-9\\-]*"\' | ' \
               'cut -c 13- | tr -d \'"\''
         mock.assert_called_once_with(cmd, python_shell=True)
         self.assertEqual(out, expected)
def test_get_pkg_id_from_pkginfo():
    """
    Test getting a package id from pkginfo files
    """
    expected = ["com.apple.this", "com.apple.that"]
    mock = MagicMock(return_value="com.apple.this\ncom.apple.that")
    with patch.dict(macpackage.__salt__, {"cmd.run": mock}):
        out = macpackage._get_pkg_id_from_pkginfo("/tmp/dmg-X/PackageInfo")
        cmd = ("cat /tmp/dmg-X/PackageInfo | grep -Eo"
               " 'identifier=\"[a-zA-Z.0-9\\-]*\"' | cut -c 13- | tr -d '\"'")
        mock.assert_called_once_with(cmd, python_shell=True)
        assert out == expected