def test_cancel_begin_downloading(self): # Setup request = self.request(3) request.downloader = HTTPCurlDownloader(DownloaderConfig()) request.downloader.download = Mock( side_effect=request.downloader.download) request.downloader.cancel = Mock() download = dict(url='http://redhat.com/file') unit = dict(unit_id='123', type_id='T', unit_key={}, metadata={}, _download=download, _storage_path='/tmp/file') units = [(unit, None)] inventory = UnitInventory(units, []) # Test strategy = ImporterStrategy() strategy._add_units(request, inventory) self.assertEqual(request.cancelled_call_count, 3) self.assertTrue(request.downloader.download.called) self.assertTrue(request.downloader.cancel.called)
def test_cancel_during_download_succeeded(self): # Setup unit_id = str(uuid4()) request = self.request(4) request.downloader = HTTPCurlDownloader(DownloaderConfig()) request.downloader.download = Mock( side_effect=request.downloader.download) request.downloader.cancel = Mock() download = dict(url='http://redhat.com/%s' % unit_id) unit = dict(unit_id=unit_id, type_id='T', unit_key={}, metadata={}, storage_path='/tmp/node/testing/%s' % unit_id, relative_path='testing/%s' % unit_id) units = [unit] inventory = UnitInventory(TestManifest(units), []) # Test strategy = ImporterStrategy() strategy._add_units(request, inventory) self.assertEqual(request.cancelled_call_count, 4) self.assertTrue(request.downloader.download.called) self.assertTrue(request.downloader.cancel.called)