Exemple #1
0
class CommandHandler(metaclass=Singleton):
    """CommandHandler"""
    def __init__(self, origin, callback_subscribe):
        self.origin = origin
        self.callback_subscribe = callback_subscribe
        self.progress_publisher = ProgressPublisher()
        self.progress_publisher.subscribe(self.origin, self.callback_subscribe)
        self.snap_service = SnapService(
            progress_publisher=self.progress_publisher)

    def install_package(self, name):
        # TODO Curated package
        self.snap_service.install_package(name=name)
        # TODO APT

    def remove_package(self, name):
        # TODO Curated package
        self.snap_service.remove_package(name=name)
        # TODO APT

    def list_installed_packages(self):
        list_of_packages = {}
        list_of_packages.update(
            {"curated":
             None})  # TODO Change None for implementation for curated
        list_of_packages.update(
            {"snap": self.snap_service.get_installed_package()})
        list_of_packages.update(
            {"apt": None})  # TODO  Change None for implementation for apt
Exemple #2
0
 def __init__(self, origin, callback_subscribe):
     self.origin = origin
     self.callback_subscribe = callback_subscribe
     self.progress_publisher = ProgressPublisher()
     self.progress_publisher.subscribe(self.origin, self.callback_subscribe)
     self.snap_service = SnapService(
         progress_publisher=self.progress_publisher)
Exemple #3
0
 def test_retrieve_installed_package(self):
     snap_service = SnapService(progress_publisher=None)
     list_installed_packages = snap_service.list_installed_packages()
     assert isinstance(list_installed_packages, list)
     for package in list_installed_packages:
         self.assert_package_information_dict(package=package)
         assert package.get("is_installed", False)
Exemple #4
0
 def testInstallNewPackage(self):
     """testInstallNewPackage"""
     snap_service = SnapService(progress_publisher=None)
     snap_service.remove_package(name="bw")
     result = snap_service.install_package(name="bw")
     self.assertEqual(result.get("action"), "install")
     self.assertEqual(result.get("message"), "success")
     self.assertEqual(result.get("name"), "bw")
Exemple #5
0
 def testRemoveTwicePackage(self):
     """testRemoveTwicePackage"""
     snap_service = SnapService(progress_publisher=None)
     snap_service.remove_package(name="bw")
     result = snap_service.remove_package(name="bw")
     self.assertEqual(result.get("code"), 15)
     self.assertEqual(result.get("message"), 'snap "bw" is not installed')
     self.assertEqual(result.get("args"), ('snap "bw" is not installed',))
     self.assertEqual(result.get("domain"), "snapd-error-quark")
Exemple #6
0
 def testRemovePackage(self):
     """testRemovePackage"""
     with patch.object(Snapd.Client, "new", return_value=Mock()) as snap_client_mock:
         publisher_mock = Mock()
         snap_service = SnapService(progress_publisher=publisher_mock)
         snap_client_mock.assert_called_once()
         snap_service.remove_package(name="bw")
         snap_client = snap_service.snap_client
         snap_client.remove_sync.assert_called_once_with(name="bw",
                                                         progress_callback=snap_service.progress_callback)
Exemple #7
0
 def testInstallPackage(self):
     """testInstallPackage"""
     with patch.object(Snapd.Client, "new", return_value=Mock()) as snap_client_mock:
         publisher_mock = Mock()
         snap_service = SnapService(progress_publisher=publisher_mock)
         snap_client_mock.assert_called_once()
         snap_service.install_package(name="bw")
         snap_client = snap_service.snap_client
         snap_client.install2_sync.assert_called_once_with(flags=0,
                                                           name="bw",
                                                           channel="stable",
                                                           progress_callback=snap_service.progress_callback)
Exemple #8
0
 def test_install_new_package(self):
     """testInstallNewPackage"""
     snap_service = SnapService(progress_publisher=None)
     snap_service.remove_package(name=self.APPLICATION_TO_INSTALL_REMOVE)
     self.assert_no_installation_date(
         package_service=snap_service,
         expected_package_name=self.APPLICATION_TO_INSTALL_REMOVE)
     result = snap_service.install_package(
         name=self.APPLICATION_TO_INSTALL_REMOVE)
     self.assert_installation_date(
         package_service=snap_service,
         expected_package_name=self.APPLICATION_TO_INSTALL_REMOVE)
     assert result.get("action") == "install"
     assert result.get("message") == "success"
     assert isinstance(result.get("arguments"), tuple)
 def __init__(self, callback_subscribe, origin="console"):
     self._list_package_thread = Thread()
     self.callback_subscribe = callback_subscribe
     self.progress_publisher = ProgressPublisher()
     self.progress_publisher.subscribe(origin, self.callback_subscribe)
     self._package_type_services = {
         self._SNAP_DICT_KEY: {
             self._SERVICE_DICT_KEY:
             SnapService(progress_publisher=self.progress_publisher),
             self._ACTION_QUEUE_DICT_KEY:
             self._SNAP_QUEUE,
             self._WORKER_DICT_KEY:
             Thread(target=self._run_service_queue,
                    args=(self._SNAP_QUEUE, )),
         },
         self._APT_DICT_KEY: {
             self._SERVICE_DICT_KEY:
             PackageKitService(progress_publisher=self.progress_publisher),
             self._ACTION_QUEUE_DICT_KEY:
             self._APT_QUEUE,
             self._WORKER_DICT_KEY:
             Thread(target=self._run_service_queue,
                    args=(self._APT_QUEUE, )),
         }
     }
Exemple #10
0
 def test_remove_package_twice(self):
     """testRemoveTwicePackage"""
     snap_service = SnapService(progress_publisher=None)
     snap_service.remove_package(name=self.APPLICATION_TO_INSTALL_REMOVE)
     self.assert_no_installation_date(
         package_service=snap_service,
         expected_package_name=self.APPLICATION_TO_INSTALL_REMOVE)
     result = snap_service.remove_package(
         name=self.APPLICATION_TO_INSTALL_REMOVE)
     self.assert_no_installation_date(
         package_service=snap_service,
         expected_package_name=self.APPLICATION_TO_INSTALL_REMOVE)
     assert result.get("code") == 15
     assert result.get(
         "message"
     ) == f'snap "{self.APPLICATION_TO_INSTALL_REMOVE}" is not installed'
     assert result.get("args") == (
         f'snap "{self.APPLICATION_TO_INSTALL_REMOVE}" is not installed', )
     assert result.get("domain") == "snapd-error-quark"
Exemple #11
0
 def test_retrieve_package_information(self):
     snap_service = SnapService(progress_publisher=None)
     package_info = snap_service.retrieve_package_information_by_name(
         name=self.APPLICATION_TO_INSTALL_REMOVE)
     for package in package_info:
         self.assert_package_information_dict(package=package)
Exemple #12
0
 def testRetrieveInformationPackage(self):
     snap_service = SnapService(progress_publisher=None)
     package_info = snap_service.retrieve_package_information_by_name(name="bw")
Exemple #13
0
 def testRetrieveInstalledPackage(self):
     snap_service = SnapService(progress_publisher=None)
     list_installed_packages = snap_service.get_installed_package()
     self.assertIsInstance(list_installed_packages, list)
     for package in list_installed_packages:
         self.validatePackageInformationDict(package=package)