Exemplo n.º 1
0
def test_installAndRemovePackage():
    mock_application = MagicMock()
    mock_registry = MagicMock()
    mock_registry.isActivePlugin = MagicMock(return_value = False)
    mock_application.getPluginRegistry = MagicMock(return_value = mock_registry)
    manager = PackageManager(mock_application)
    manager.installedPackagesChanged = MagicMock()
    manager.installPackage(test_package_path)
    assert manager.installedPackagesChanged.emit.call_count == 1
    assert manager.isPackageInstalled("UnitTestPackage")

    info = manager.getInstalledPackageInfo("UnitTestPackage")
    assert info["author"]["author_id"] == "nallath"
    assert info["display_name"] == "UnitTestPackage"

    # We don't want the package to be purged. We need that package for the other tests!
    with patch("os.remove", MagicMock()):
        manager._installPackage({"package_info": info, "filename": test_package_path})

    assert "UnitTestPackage" in manager.getAllInstalledPackageIDs()
    assert manager.isUserInstalledPackage("UnitTestPackage")
    assert manager.getAllInstalledPackagesInfo()["plugin"][0]["display_name"] == "UnitTestPackage"
    manager.initialize()
    # Now to remove the package again!
    manager.removePackage("UnitTestPackage")
    assert manager.installedPackagesChanged.emit.call_count == 2
Exemplo n.º 2
0
def test_installAndRemovePackage():
    mock_application = MagicMock()
    mock_registry = MagicMock()
    mock_registry.isActivePlugin = MagicMock(return_value=False)
    mock_application.getPluginRegistry = MagicMock(return_value=mock_registry)
    manager = PackageManager(mock_application)
    manager.installedPackagesChanged = MagicMock()
    package_id = manager.installPackage(test_package_path)
    assert manager.installedPackagesChanged.emit.call_count == 1
    assert manager.isPackageInstalled("UnitTestPackage")
    assert package_id == "UnitTestPackage"

    info = manager.getInstalledPackageInfo("UnitTestPackage")
    assert info["author"]["author_id"] == "nallath"
    assert info["display_name"] == "UnitTestPackage"

    # We don't want the package to be purged. We need that package for the other tests!
    with patch("os.remove", MagicMock()):
        manager._installPackage({
            "package_info": info,
            "filename": test_package_path
        })

    assert "UnitTestPackage" in manager.getAllInstalledPackageIDs()
    assert manager.isUserInstalledPackage("UnitTestPackage")
    assert manager.getAllInstalledPackagesInfo(
    )["plugin"][0]["display_name"] == "UnitTestPackage"
    manager.initialize()
    # Now to remove the package again!
    manager.removePackage("UnitTestPackage")
    assert manager.installedPackagesChanged.emit.call_count == 2
Exemplo n.º 3
0
def test_emptyInit():
    manager = PackageManager(MagicMock())

    assert not manager.getAllInstalledPackageIDs()
    assert not manager.getAllInstalledPackagesInfo()

    manager.installedPackagesChanged = MagicMock()
    manager.removePackage("packageThatDoesNotExist")
    assert manager.installedPackagesChanged.emit.call_count == 0

    assert manager.getBundledPackageInfo("packageThatDoesNotExist") is None

    with pytest.raises(FileNotFoundError):
        assert manager.getPackageLicense("FileThatDoesntExist.package") == {}

    assert manager.getPackageFiles("packageThatDoesNotExist") == []

    assert manager.getPackageContainerIds("packageThatDoesNotExist") == []
Exemplo n.º 4
0
def test_emptyInit():
    manager = PackageManager(MagicMock())

    assert not manager.getAllInstalledPackageIDs()
    assert not manager.getAllInstalledPackagesInfo()

    manager.installedPackagesChanged = MagicMock()
    manager.removePackage("packageThatDoesNotExist")
    assert manager.installedPackagesChanged.emit.call_count == 0

    assert manager.getBundledPackageInfo("packageThatDoesNotExist") is None

    with pytest.raises(FileNotFoundError):
        assert manager.getPackageLicense("FileThatDoesntExist.package") == {}

    assert manager.getPackageFiles("packageThatDoesNotExist") == []

    assert manager.getPackageContainerIds("packageThatDoesNotExist") == []