Esempio n. 1
0
 def __init__(self, path=None):
     """
     :param path: The absolute path to a directory containing
         content source descriptor files.
     :type path: str
     """
     self.sources = ContentSource.load_all(path)
Esempio n. 2
0
    def test_load_all(self, fake_valid, fake_enabled, fake_parser,
                      fake_listdir):
        conf_d = '/fake/conf_d'
        files = ['one.conf', 'other']
        fake_listdir.return_value = files

        fake_valid.side_effect = [d[1]['valid'] for d in DESCRIPTOR]

        fake_enabled.__get__ = Mock(
            side_effect=[d[1]['enabled'] for d in DESCRIPTOR])

        parser = Mock()
        parser.items.side_effect = [d[1].items() for d in DESCRIPTOR]
        parser.sections.return_value = dict(DESCRIPTOR)
        fake_parser.return_value = parser

        # test

        sources = ContentSource.load_all(conf_d)

        # validation

        fake_listdir.assert_called_with(conf_d)
        fake_parser.assert_called_with()
        fake_parser().read.assert_called_with(os.path.join(conf_d, files[0]))

        self.assertEqual(len(sources), 2)
        self.assertTrue(DESCRIPTOR[1][0] in sources)
        self.assertTrue(DESCRIPTOR[3][0] in sources)
Esempio n. 3
0
 def __init__(self, path=None):
     """
     :param path: The absolute path to a directory containing
         content source descriptor files.
     :type path: str
     """
     self.sources = ContentSource.load_all(path)
Esempio n. 4
0
    def test_load_all(self, fake_valid, fake_enabled, fake_parser, fake_listdir, fake_isfile):
        conf_d = '/fake/conf_d'
        files = ['one.conf', 'other']
        fake_listdir.return_value = files

        fake_valid.side_effect = [
            True,  # s-0
                   # s-1 not enabled
            True,  # s-2
            False  # s-3
        ]

        fake_isfile.side_effect = [True, False]

        fake_enabled.__get__ = Mock(side_effect=[d[1]['enabled'] for d in DESCRIPTOR])

        parser = Mock()
        parser.items.side_effect = [d[1].items() for d in DESCRIPTOR]
        parser.sections.return_value = [d[0] for d in DESCRIPTOR]
        fake_parser.return_value = parser

        # test

        sources = ContentSource.load_all(conf_d)

        # validation

        fake_listdir.assert_called_with(conf_d)
        fake_parser.assert_called_with()
        fake_parser().read.assert_called_with(os.path.join(conf_d, files[0]))

        self.assertEqual(len(sources), 2)
        self.assertTrue(DESCRIPTOR[0][0] in sources)
        self.assertTrue(DESCRIPTOR[2][0] in sources)
Esempio n. 5
0
    def test_load_all(self, fake_valid, fake_enabled, fake_parser, fake_listdir, fake_isfile):
        conf_d = '/fake/conf_d'
        files = ['one.conf', 'two.conf.swp', 'dir.conf']
        fake_listdir.return_value = files

        fake_valid.side_effect = [
            True,  # s-0
                   # s-1 not enabled
            True,  # s-2
            False  # s-3
        ]

        fake_isfile.side_effect = [True, False]

        fake_enabled.__get__ = Mock(side_effect=[d[1]['enabled'] for d in DESCRIPTOR])

        parser = Mock()
        parser.items.side_effect = [d[1].items() for d in DESCRIPTOR]
        parser.sections.return_value = [d[0] for d in DESCRIPTOR]
        fake_parser.return_value = parser

        # test

        sources = ContentSource.load_all(conf_d)

        # validation

        fake_listdir.assert_called_with(conf_d)
        fake_parser.assert_called_with()
        fake_parser().read.assert_called_with(os.path.join(conf_d, files[0]))

        self.assertEqual(len(sources), 2)
        self.assertTrue(DESCRIPTOR[0][0] in sources)
        self.assertTrue(DESCRIPTOR[2][0] in sources)
Esempio n. 6
0
 def test_urls(self):
     sources = ContentSource.load_all(self.tmp_dir)
     underground = sources[UNDERGROUND]
     urls = underground.urls
     self.assertEqual(len(urls), 4)
     self.assertEqual(urls[0], 'file:///underground/fedora/18/x86_64/')
     self.assertEqual(urls[1], 'file:///underground/fedora/18/i386/')
     self.assertEqual(urls[2], 'file:///underground/fedora/19/x86_64/')
     self.assertEqual(urls[3], 'file:///underground/fedora/19/i386/')
Esempio n. 7
0
 def __init__(self, path=None, threaded=True):
     """
     :param path:     The absolute path to a directory containing
                      content source descriptor files.
     :type  path:     str
     :param threaded: Whether or not to use the threaded download method.
     :type  threaded: bool
     """
     self.sources = ContentSource.load_all(path)
     self.threaded = threaded
Esempio n. 8
0
 def __init__(self, path=None, threaded=True):
     """
     :param path:     The absolute path to a directory containing
                      content source descriptor files.
     :type  path:     str
     :param threaded: Whether or not to use the threaded download method.
     :type  threaded: bool
     """
     self.sources = ContentSource.load_all(path)
     self.threaded = threaded
Esempio n. 9
0
    def test_load_all_unreadable(self, mock_warn, mock_read, mock_listdir, mock_isfile):
        conf_d = '/mock/conf_d/'
        mock_listdir.return_value = ['somefile.conf']
        # this return value indicates that the read did not succeed
        mock_read.return_value = []

        sources = ContentSource.load_all(conf_d)

        # make sure no sources are returned, and a message was logged with the path
        self.assertEqual(len(sources), 0)
        self.assertEqual(mock_warn.call_count, 1)
        self.assertEqual(os.path.join(conf_d, 'somefile.conf'), mock_warn.call_args[0][1])
Esempio n. 10
0
    def test_refresh(self, mock_plugin):
        container = ContentContainer(path=self.tmp_dir)

        # test
        report = container.refresh(force=True)

        # validation
        plugin = mock_plugin.return_value[0]
        self.assertEqual(plugin.refresh.call_count, 5)
        self.assertEqual(len(report), 5)
        for r in report:
            self.assertTrue(r.succeeded)
            self.assertEqual(r.added_count, 100)
            self.assertEqual(r.deleted_count, 0)
        calls = iter(plugin.refresh.call_args_list)
        for source in ContentSource.load_all(self.tmp_dir).values():
            for url in source.urls:
                args = calls.next()[0]
                self.assertTrue(isinstance(args[0], CatalogerConduit))
                self.assertEqual(args[1], source.descriptor)
                self.assertEqual(args[2], url)
Esempio n. 11
0
 def test_loading(self):
     sources = ContentSource.load_all(self.tmp_dir)
     self.assertEqual(len(sources), 2)