Beispiel #1
0
    def test_skips_mkdir_if_dest_dir_exists(self, *_args):
        new_dir = self.tmpdir.joinpath('not_exists')
        new_dir.mkdir()
        assert new_dir.exists() is True

        download_file(self.mock_filename, self.mock_src_url, new_dir)
        assert new_dir.exists() is True
Beispiel #2
0
    def test_saves_content_to_dest_path(self, mock_shutil, mock_urlopen, *_args):
        mock_shutil.stop()
        expected_content = b'response content'
        response = BytesIO(expected_content)
        mock_urlopen.return_value = response
        expected_filepath = self.tmpdir.joinpath(self.mock_filename)
        assert expected_filepath.exists() is False

        download_file(self.mock_filename, self.mock_src_url, self.tmpdir)
        assert expected_filepath.exists() is True
        assert mock_shutil.copyfileobj.call_count == 1
Beispiel #3
0
 def test_download_manifest_dummy_file():
     """ will download a tiny file from the array-manifest-files s3 bucket, to test the SSL connection on all platforms.
     The dummy file is not a proper manifest CSV, so doesn't test format.
     download_file now defaults to non-SSL if SSL fails, with warning to user."""
     test_filename = 'unittest.txt'
     test_s3_bucket = 'https://array-manifest-files.s3.amazonaws.com'  # 's3://array-manifest-files'
     dest_dir = ''
     # use the .download_file() method in files.py to test the download step specifically. this is called by Manifests() class.
     download_file(test_filename, test_s3_bucket, dest_dir, overwrite=False)
     # in testing mode, this should not exist, and should get deleted right after each successful test.
     if not Path(dest_dir, test_filename).is_file():
         raise AssertionError()
     Path(dest_dir, test_filename).unlink()  # deletes file.
Beispiel #4
0
    def test_makes_dir_if_dest_dir_not_exists(self, *_args):
        new_dir = self.tmpdir.joinpath('not_exists')
        assert new_dir.exists() is False

        download_file(self.mock_filename, self.mock_src_url, new_dir)
        assert new_dir.exists() is True
Beispiel #5
0
 def test_doesnt_raise_if_file_exists_overwrite_true(self, *_args):
     self.tmpdir.joinpath(self.mock_filename).touch()
     download_file(self.mock_filename, self.mock_src_url, self.tmpdir, overwrite=True)