Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
f.write(dummy_content)
expected_path.remove()
product_info = api.download(uuid, str(tmpdir), checksum=False)
assert not tempfile_path.check(exists=1)
assert expected_path.check(exists=1, file=1)
assert expected_path.computehash("md5") != hash
expected_product_info["downloaded_bytes"] = expected_product_info["size"] - len(dummy_content)
assert product_info == expected_product_info
# Create invalid tempfile, with checksum check
# Expect continued download and exception raised
dummy_content = b"aaaaaaaaaaaaaaaaaaaaaaaaa"
with tempfile_path.open("wb") as f:
f.write(dummy_content)
expected_path.remove()
with pytest.raises(InvalidChecksumError):
api.download(uuid, str(tmpdir), checksum=True)
assert not tempfile_path.check(exists=1)
assert not expected_path.check(exists=1, file=1)
tmpdir.remove()
# clean up
for f in tmpdir.listdir():
f.remove()
# Prepare a response with an invalid checksum
url = "https://scihub.copernicus.eu/apihub/odata/v1/Products('%s')?$format=json" % product_id
json = api.session.get(url).json()
json["d"]["Checksum"]["Value"] = "00000000000000000000000000000000"
# Force the download to fail by providing an incorrect checksum
with requests_mock.mock(real_http=True) as rqst:
rqst.get(url, json=json)
# md5 flag set (implicitly), should raise an exception
run_cli(*command, must_raise=InvalidChecksumError)
# clean up
tmpdir.remove()
f.write(dummy_content)
expected_path.remove()
product_info = api.download(uuid, str(tmpdir), checksum=False)
assert not tempfile_path.check(exists=1)
assert expected_path.check(exists=1, file=1)
assert expected_path.computehash("md5") != hash
expected_product_info["downloaded_bytes"] = expected_product_info["size"] - len(dummy_content)
assert product_info == expected_product_info
# Create invalid tempfile, with checksum check
# Expect continued download and exception raised
dummy_content = b'aaaaaaaaaaaaaaaaaaaaaaaaa'
with tempfile_path.open("wb") as f:
f.write(dummy_content)
expected_path.remove()
with pytest.raises(InvalidChecksumError):
api.download(uuid, str(tmpdir), checksum=True)
assert not tempfile_path.check(exists=1)
assert not expected_path.check(exists=1, file=1)
tmpdir.remove()