def test_download_image_shub_wrong_url(self, mock_request, mock_json): # we need this for the fake download tmp_dir = "/tmp/singularity-images" if not os.path.isdir(tmp_dir): os.mkdir(tmp_dir) download_obj = DownloadWorkflow(pipeline="dummy", outdir=tempfile.mkdtemp()) # simulauates the first response querying the API for the container # information resp_shub = requests.Response() resp_shub.status_code = 200 mock_json.side_effect = [{'image': 'my-container', 'version': 'h4sh'}] # simulates the second response querying the # container download stream resp_download = requests.Response() resp_download.status_code = 404 # assign the response order mock_request.side_effect = [resp_shub, resp_download] # test download_obj.download_shub_image("awesome-container") # Clean up shutil.rmtree(tmp_dir)
def test_download_shub_image_on_sucess(self, mock_request, mock_json, mock_content, mock_progressbar, mock_md5): tmp_dir = tempfile.mkdtemp() os.mkdir(os.path.join(tmp_dir, 'singularity-images')) download_obj = DownloadWorkflow(pipeline="dummy", outdir=tmp_dir) # simulauates the first response querying the API for the container # information resp_shub = requests.Response() resp_shub.status_code = 200 mock_json.side_effect = [{'image': 'my-container', 'version': 'h4sh'}] # simulates the second response querying the # container download stream resp_download = requests.Response() resp_download.status_code = 200 resp_download.headers = {'content-length': 1024} mock_content.side_effect = b"Awesome" # assign the response order mock_request.side_effect = [resp_shub, resp_download] # test download_obj.download_shub_image("awesome-container") # Clean up shutil.rmtree(tmp_dir)
def test_download_shub_image_on_sucess(self, mock_request, mock_json, mock_content, mock_progressbar, mock_md5): # we need this for the fake download tmp_dir = "/tmp/singularity-images" if not os.path.isdir(tmp_dir): os.mkdir(tmp_dir) download_obj = DownloadWorkflow(pipeline="dummy", outdir="/tmp") # simulauates the first response querying the API for the container # information resp_shub = requests.Response() resp_shub.status_code = 200 mock_json.side_effect = [{'image': 'my-container', 'version': 'h4sh'}] # simulates the second response querying the # container download stream resp_download = requests.Response() resp_download.status_code = 200 resp_download.headers = {'content-length': 1024} mock_content.side_effect = b"Awesome" # assign the response order mock_request.side_effect = [resp_shub, resp_download] # test download_obj.download_shub_image("awesome-container")
def test_download_image_shub_without_hit(self, mock_request): # we need this for the fake download tmp_dir = "/tmp/singularity-images" if not os.path.isdir(tmp_dir): os.mkdir(tmp_dir) download_obj = DownloadWorkflow(pipeline="dummy", outdir="/tmp") # simulauates the first response querying the API for the container # information resp_shub = requests.Response() resp_shub.status_code = 404 # assign the response order mock_request.side_effect = [resp_shub] # test download_obj.download_shub_image("awesome-container")