Guest User

Untitled

a guest
Sep 22nd, 2020
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. diff --git a/glance/tests/unit/async_/flows/test_web_download.py b/glance/tests/unit/async_/flows/test_web_download.py
  2. index cccbf5fca..eec809fe1 100644
  3. --- a/glance/tests/unit/async_/flows/test_web_download.py
  4. +++ b/glance/tests/unit/async_/flows/test_web_download.py
  5. @@ -178,12 +178,29 @@ class TestWebDownloadTask(test_utils.BaseTestCase):
  6. self.assertEqual(1, mock_unlik.call_count)
  7.  
  8. @mock.patch("glance.async_.flows._internal_plugins.web_download.store_api")
  9. - def test_web_download_revert_without_failure(self, mock_store_api):
  10. + @mock.patch("glance.common.scripts.utils.get_image_data_iter")
  11. + def test_web_download_revert_without_failure(self, mock_data,
  12. + mock_store_api):
  13. web_download_task = web_download._WebDownload(
  14. self.task.task_id, self.task_type, self.task_repo,
  15. self.image_id, self.uri)
  16. - web_download_task._path = "/path/to_downloaded_data"
  17. - web_download_task.revert("/path/to_downloaded_data")
  18. +
  19. + with mock.patch.object(web_download_task, 'store') as mock_store:
  20. + # Data iterator reports content-length header of 456
  21. + mock_data.return_value.headers = {'content-length': 456}
  22. +
  23. + # Store returns only 123 bytes read
  24. + mock_store.add.return_value = "/path/to_downloaded_data", 123
  25. +
  26. + # task.execute() should fail because of the mismatch
  27. + self.assertRaises(glance.common.exception.ImportTaskError,
  28. + web_download_task.execute)
  29. +
  30. + # Call task.revert() like taskflow will
  31. + web_download_task.revert(None)
  32. +
  33. + # Make sure we delete from store with the path that the store
  34. + # add call returned
  35. mock_store_api.delete_from_backend.assert_called_once_with(
  36. "/path/to_downloaded_data")
Advertisement
Add Comment
Please, Sign In to add comment