Exemple #1
0
 def test_run_WASAPIDownloadError(self, mock_download):
     """Test downloader when downloads fail."""
     mock_download.side_effect = wc.WASAPIDownloadError()
     # Create a queue holding two sets of file data.
     get_q = multiprocessing.JoinableQueue()
     for _ in (1, 2):
         get_q.put(self.data_file)
     result_q = multiprocessing.Queue()
     log_q = multiprocessing.Queue()
     p = wc.Downloader(get_q, result_q, log_q)
     p.start()
     p.run()
     # If the join doesn't block, the queue is fully processed.
     get_q.join()
     assert result_q.qsize() == 2
     assert log_q.qsize() == 2
     for _ in (1, 2):
         assert result_q.get() == ('failure', self.filename)
Exemple #2
0
 def test_run(self):
     """Test downloader when downloads are successful."""
     # Create a queue holding two sets of file data.
     get_q = multiprocessing.JoinableQueue()
     for _ in (1, 2):
         get_q.put(self.data_file)
     result_q = multiprocessing.Queue()
     log_q = multiprocessing.Queue()
     with patch('wasapi_client.verify_file', return_value=True), \
             patch('wasapi_client.download_file', return_value=self.data_file):
         p = wc.Downloader(get_q, result_q, log_q)
         p.start()
         p.run()
     # If the join doesn't block, the queue is fully processed.
     get_q.join()
     assert result_q.qsize() == 2
     assert log_q.qsize() == 0
     for _ in (1, 2):
         assert result_q.get() == ('success', self.filename)
 def test_run_WASAPIDownloadError(self, mock_download):
     """Test downloader when downloads fail."""
     expected_error = 'WD Error'
     mock_download.side_effect = wc.WASAPIDownloadError(expected_error)
     # Create a queue holding two sets of file data.
     get_q = multiprocessing.JoinableQueue()
     for _ in (1, 2):
         get_q.put(self.data_file)
     manager = multiprocessing.Manager()
     result_q = manager.Queue()
     log_q = manager.Queue()
     p = wc.Downloader(get_q, result_q, log_q)
     p.start()
     p.run()
     # If the join doesn't block, the queue is fully processed.
     get_q.join()
     for _ in (1, 2):
         assert log_q.get().msg == expected_error
         assert result_q.get() == ('failure', self.filename)
     # Verify those were the only two results on the result_q.
     # Sometimes `empty` needs a moment to register.
     assert result_q.empty()
 def test_run_file_already_verified(self):
     """Test a downloaded file is not verified twice."""
     return_data_file = wc.DataFile(self.locations, self.filename, self.checksums, self.size)
     return_data_file.verified = True
     # Create a queue holding two sets of file data.
     get_q = multiprocessing.JoinableQueue()
     for _ in (1, 2):
         get_q.put(self.data_file)
     manager = multiprocessing.Manager()
     result_q = manager.Queue()
     log_q = manager.Queue()
     with patch('wasapi_client.verify_file', return_value=True) as mock_verify, \
             patch('wasapi_client.download_file', return_value=return_data_file):
         p = wc.Downloader(get_q, result_q, log_q)
         p.start()
         p.run()
     # If the join doesn't block, the queue is fully processed.
     get_q.join()
     assert log_q.empty()
     for _ in (1, 2):
         assert result_q.get() == ('success', self.filename)
     assert result_q.empty()
     # Check verify_exists was not called, since it was called in `download_file`.
     assert not mock_verify.called