Ejemplo n.º 1
0
    def test_find_sources(self, fake_manager):
        type_id = 'test_1'
        unit_key = 1
        destination = '/tmp/123'
        url = 'http://redhat.com/repository'

        primary = PrimarySource(None)
        alternatives = dict([(s, ContentSource(s, d)) for s, d in DESCRIPTOR])
        fake_manager().find.return_value = CATALOG

        # test

        request = Request(type_id, unit_key, url, destination)
        request.find_sources(primary, alternatives)

        # validation

        # validate sources sorted by priority with the primary last.
        # should only have matched on s-1 and s-3.

        self.assertEqual(len(request.sources), 5)
        self.assertEqual(request.sources[0][0].id, 's-3')
        self.assertEqual(request.sources[0][1], CATALOG[2][constants.URL])
        self.assertEqual(request.sources[1][0].id, 's-3')
        self.assertEqual(request.sources[1][1], CATALOG[3][constants.URL])
        self.assertEqual(request.sources[2][0].id, 's-1')
        self.assertEqual(request.sources[2][1], CATALOG[0][constants.URL])
        self.assertEqual(request.sources[3][0].id, 's-1')
        self.assertEqual(request.sources[3][1], CATALOG[1][constants.URL])
        self.assertEqual(request.sources[4][0].id, primary.id)
        self.assertEqual(request.sources[4][1], url)
Ejemplo n.º 2
0
    def test_find_sources(self, fake_manager):
        type_id = 'test_1'
        unit_key = 1
        destination = '/tmp/123'
        url = 'http://redhat.com/repository'

        primary = PrimarySource(None)
        alternatives = dict([(s, ContentSource(s, d)) for s, d in DESCRIPTOR])
        fake_manager().find.return_value = CATALOG

        # test

        request = Request(type_id, unit_key, url, destination)
        request.find_sources(primary, alternatives)

        # validation

        # validate sources sorted by priority with the primary last.
        # should only have matched on s-1 and s-3.

        request.sources = list(request.sources)
        self.assertEqual(len(request.sources), 5)
        self.assertEqual(request.sources[0][0].id, 's-3')
        self.assertEqual(request.sources[0][1], CATALOG[2][constants.URL])
        self.assertEqual(request.sources[1][0].id, 's-3')
        self.assertEqual(request.sources[1][1], CATALOG[3][constants.URL])
        self.assertEqual(request.sources[2][0].id, 's-1')
        self.assertEqual(request.sources[2][1], CATALOG[0][constants.URL])
        self.assertEqual(request.sources[3][0].id, 's-1')
        self.assertEqual(request.sources[3][1], CATALOG[1][constants.URL])
        self.assertEqual(request.sources[4][0].id, primary.id)
        self.assertEqual(request.sources[4][1], url)
Ejemplo n.º 3
0
    def test_download(self, fake_load):
        sources = []
        for n in range(3):
            s = ContentSource('s-%d' % n, {})
            s.get_downloader = Mock()
            sources.append(s)

        fake_load.return_value = sources

        request_list = []
        for n in range(6):
            r = Request('T', {}, 'url-%d' % n, 'path-%d' % n)
            r.find_sources = Mock(return_value=sources[n % 3:])
            request_list.append(r)

        collated = [
            {
                sources[0]: ['nectar-1'],
                sources[1]: ['nectar-2', 'nectar-3', 'nectar-4'],
                sources[2]: ['nectar-5', 'nectar-6']
            },
            {}
        ]
        fake_collated = Mock(side_effect=collated)

        fake_listener = Mock()
        canceled = FakeEvent()
        fake_primary = PrimarySource(Mock())

        # test
        container = ContentContainer('')
        container.refresh = Mock()
        container.collated = fake_collated
        report = container.download(canceled, fake_primary, request_list, fake_listener)

        # validation
        container.refresh.assert_called_with(canceled)

        for r in request_list:
            r.find_sources.assert_called_with(fake_primary, container.sources)

        self.assertEqual(report.total_passes, 1)
        self.assertEqual(report.total_sources, len(sources))
        self.assertEqual(len(report.downloads), 3)
        for source in sources:
            self.assertEqual(report.downloads[source.id].total_succeeded, 0)
            self.assertEqual(report.downloads[source.id].total_failed, 0)

        for source in sources:
            source.get_downloader.assert_called_with()
            downloader = source.get_downloader()
            listener = downloader.event_listener
            self.assertEqual(listener.cancel_event, canceled)
            self.assertEqual(listener.downloader, downloader)
            self.assertEqual(listener.listener, fake_listener)
            downloader.download.assert_called_with(collated[0][source])
Ejemplo n.º 4
0
    def test_download(self, fake_load):
        sources = []
        for n in range(3):
            s = ContentSource('s-%d' % n, {})
            s.get_downloader = Mock()
            sources.append(s)

        fake_load.return_value = sources

        request_list = []
        for n in range(6):
            r = Request('T', {}, 'url-%d' % n, 'path-%d' % n)
            r.find_sources = Mock(return_value=sources[n % 3:])
            request_list.append(r)

        collated = [{
            sources[0]: ['nectar-1'],
            sources[1]: ['nectar-2', 'nectar-3', 'nectar-4'],
            sources[2]: ['nectar-5', 'nectar-6']
        }, {}]
        fake_collated = Mock(side_effect=collated)

        fake_listener = Mock()
        canceled = FakeEvent()
        fake_primary = PrimarySource(Mock())

        # test
        container = ContentContainer('')
        container.refresh = Mock()
        container.collated = fake_collated
        report = container.download(canceled, fake_primary, request_list,
                                    fake_listener)

        # validation
        container.refresh.assert_called_with(canceled)

        for r in request_list:
            r.find_sources.assert_called_with(fake_primary, container.sources)

        self.assertEqual(report.total_passes, 1)
        self.assertEqual(report.total_sources, len(sources))
        self.assertEqual(len(report.downloads), 3)
        for source in sources:
            self.assertEqual(report.downloads[source.id].total_succeeded, 0)
            self.assertEqual(report.downloads[source.id].total_failed, 0)

        for source in sources:
            source.get_downloader.assert_called_with()
            downloader = source.get_downloader()
            listener = downloader.event_listener
            self.assertEqual(listener.cancel_event, canceled)
            self.assertEqual(listener.downloader, downloader)
            self.assertEqual(listener.listener, fake_listener)
            downloader.download.assert_called_with(collated[0][source])
Ejemplo n.º 5
0
    def test_download_canceled_after_collated(self, fake_load):
        sources = []
        for n in range(3):
            s = ContentSource('s-%d' % n, {})
            s.get_downloader = Mock()
            sources.append(s)

        fake_load.return_value = sources

        request_list = []
        for n in range(6):
            r = Request('T', {}, 'url-%d' % n, 'path-%d' % n)
            r.find_sources = Mock(return_value=sources[n % 3:])
            request_list.append(r)

        collated = [
            {
                sources[0]: ['nectar-1'],
                sources[1]: ['nectar-2', 'nectar-3', 'nectar-4'],
                sources[2]: ['nectar-5', 'nectar-6']
            },
            {}
        ]
        fake_collated = Mock(side_effect=collated)

        fake_listener = Mock()
        canceled = Mock()
        canceled.isSet.side_effect = [False, True, True]
        fake_primary = PrimarySource(Mock())

        # test
        container = ContentContainer('')
        container.refresh = Mock()
        container.collated = fake_collated
        report = container.download(canceled, fake_primary, request_list, fake_listener)

        # validation
        container.refresh.assert_called_with(canceled)

        for r in request_list:
            r.find_sources.assert_called_with(fake_primary, container.sources)

        called = 0
        for s in sources:
            if s.get_downloader.called:
                called += 1

        self.assertEqual(called, 1)
        self.assertEqual(report.total_passes, 1)
        self.assertEqual(report.total_sources, len(sources))
        self.assertEqual(len(report.downloads), 1)
        self.assertEqual(report.downloads[sources[2].id].total_succeeded, 0)
        self.assertEqual(report.downloads[sources[2].id].total_failed, 0)
Ejemplo n.º 6
0
    def test_download_canceled_after_collated(self, fake_load):
        sources = []
        for n in range(3):
            s = ContentSource('s-%d' % n, {})
            s.get_downloader = Mock()
            sources.append(s)

        fake_load.return_value = sources

        request_list = []
        for n in range(6):
            r = Request('T', {}, 'url-%d' % n, 'path-%d' % n)
            r.find_sources = Mock(return_value=sources[n % 3:])
            request_list.append(r)

        collated = [{
            sources[0]: ['nectar-1'],
            sources[1]: ['nectar-2', 'nectar-3', 'nectar-4'],
            sources[2]: ['nectar-5', 'nectar-6']
        }, {}]
        fake_collated = Mock(side_effect=collated)

        fake_listener = Mock()
        canceled = Mock()
        canceled.isSet.side_effect = [False, True, True]
        fake_primary = PrimarySource(Mock())

        # test
        container = ContentContainer('')
        container.refresh = Mock()
        container.collated = fake_collated
        report = container.download(canceled, fake_primary, request_list,
                                    fake_listener)

        # validation
        container.refresh.assert_called_with(canceled)

        for r in request_list:
            r.find_sources.assert_called_with(fake_primary, container.sources)

        called = 0
        for s in sources:
            if s.get_downloader.called:
                called += 1

        self.assertEqual(called, 1)
        self.assertEqual(report.total_passes, 1)
        self.assertEqual(report.total_sources, len(sources))
        self.assertEqual(len(report.downloads), 1)
        self.assertEqual(report.downloads[sources[2].id].total_succeeded, 0)
        self.assertEqual(report.downloads[sources[2].id].total_failed, 0)