Exemple #1
0
 def test_app_info_returns_empty_dict_when_no_such_app_exists(self):
     with unittest.mock.patch(
             'libertine.service.apt.apt.Cache') as MockCache:
         MockCache.return_value = {}
         self.assertEqual(apt.AptCache('palpatine').app_info("vim"), {})
         MockCache.assert_called_once_with(
             rootdir=utils.get_libertine_container_rootfs_path('palpatine'))
Exemple #2
0
    def __init__(self, container_id, config, monitor, client, callback):
        self._id = container_id
        self._config = config
        self._monitor = monitor
        self._client = client
        self._callback = callback

        self._lock = Lock()
        self._tasks = []

        if utils.is_snap_environment():
            utils.get_logger().warning(utils._("Using AptCache not currently supported in snap environment"))
            self._cache = None
        else:
            self._cache = apt.AptCache(self.id)
Exemple #3
0
    def test_loads_cache_only_once(self):
        with unittest.mock.patch(
                'libertine.service.apt.apt.Cache') as MockCache:
            MockCache.return_value = {
                "vim":
                build_mock_app("vim", "vi improved", "vim.com",
                               "who even uses raw vi"),
                "gimp":
                build_mock_app("gimp", "foss photoshop", "gimp.com",
                               "visual text editor"),
            }

            cache = apt.AptCache('palpatine')
            cache.app_info("vim")
            cache.app_info("vim")

            assert MockCache.call_count == 1
Exemple #4
0
    def test_loads_cache_only_once(self):
        with unittest.mock.patch(
                'libertine.service.apt.apt.Cache') as MockCache:
            MockCache.return_value = {
                "vim":
                build_mock_app("vim", "vi improved", "vim.com",
                               "who even uses raw vi"),
                "gimp":
                build_mock_app("gimp", "foss photoshop", "gimp.com",
                               "visual text editor"),
            }

            cache = apt.AptCache('palpatine')
            cache.app_info("vim")
            cache.app_info("vim")

            MockCache.assert_called_once_with(
                rootdir=utils.get_libertine_container_rootfs_path('palpatine'))
Exemple #5
0
 def test_app_info_returns_values_for_app(self):
     with unittest.mock.patch(
             'libertine.service.apt.apt.Cache') as MockCache:
         MockCache.return_value = {
             "vim":
             build_mock_app("vim", "vi improved", "vim.com",
                            "who even uses raw vi"),
             "gimp":
             build_mock_app("gimp", "foss photoshop", "gimp.com",
                            "visual text editor"),
         }
         self.assertEqual(
             apt.AptCache('palpatine').app_info("vim"), {
                 'name': 'vim',
                 'id': 'vim',
                 'package': 'vim',
                 'summary': 'vi improved',
                 'description': 'who even uses raw vi',
                 'website': 'vim.com'
             })
         assert MockCache.call_count == 1
Exemple #6
0
    def test_search_returns_matching_results(self):
        with unittest.mock.patch(
                'libertine.service.apt.apt.Cache') as MockCache:
            MockCache.return_value = {
                "vim":
                build_mock_app("vim", "vi improved", "vim.com",
                               "who even uses raw vi"),
                "gedit":
                build_mock_app("gedit", "text editor", "gedit.com",
                               "visual text editor"),
                "gimp":
                build_mock_app("gimp", "foss photoshop", "gimp.com",
                               "edit bitmap images"),
                "vim-common":
                build_mock_app("vim-common", "common vim stuff", "vim.common",
                               "dependencies")
            }

            results = apt.AptCache('palpatine').search('vim')

            self.assertEqual(len(results), 2)
            results = sorted(results, key=lambda xx: xx['id'])
            self.assertEqual(results[0]['description'], 'who even uses raw vi')
            self.assertEqual(results[0]['name'], 'vim')
            self.assertEqual(results[0]['id'], 'vim')
            self.assertEqual(results[0]['summary'], 'vi improved')
            self.assertEqual(results[0]['website'], 'vim.com')
            self.assertEqual(results[0]['package'], 'vim')

            self.assertEqual(results[1]['description'], 'dependencies')
            self.assertEqual(results[1]['name'], 'vim-common')
            self.assertEqual(results[1]['id'], 'vim-common')
            self.assertEqual(results[1]['summary'], 'common vim stuff')
            self.assertEqual(results[1]['website'], 'vim.common')
            self.assertEqual(results[1]['package'], 'vim-common')

            MockCache.assert_called_once_with(
                rootdir=utils.get_libertine_container_rootfs_path('palpatine'))
Exemple #7
0
    def test_loads_cache_from_container_directory(self):
        with unittest.mock.patch(
                'libertine.service.apt.apt.Cache') as MockCache:
            MockCache.return_value = {
                "vim":
                build_mock_app("vim", "vi improved", "vim.com",
                               "who even uses raw vi"),
                "gimp":
                build_mock_app("gimp", "foss photoshop", "gimp.com",
                               "visual text editor"),
            }

            self.assertEqual(
                apt.AptCache('palpatine').app_info("vim"), {
                    'name': 'vim',
                    'id': 'vim',
                    'package': 'vim',
                    'summary': 'vi improved',
                    'description': 'who even uses raw vi',
                    'website': 'vim.com'
                })

            MockCache.assert_called_once_with(
                rootdir=utils.get_libertine_container_rootfs_path('palpatine'))
Exemple #8
0
 def test_search_returns_empty_when_no_matching_results(self):
     with unittest.mock.patch(
             'libertine.service.apt.apt.Cache') as MockCache:
         MockCache.return_value.keys.return_value = []
         self.assertEqual(apt.AptCache('palpatine').search('vim'), [])
Exemple #9
0
 def test_app_info_returns_empty_dict_when_no_such_app_exists(self):
     with unittest.mock.patch(
             'libertine.service.apt.apt.Cache') as MockCache:
         MockCache.return_value = {}
         self.assertEqual(apt.AptCache('palpatine').app_info("vim"), {})
         assert MockCache.call_count == 1