def test_download_asset_with_cid(metadata): publisher_instance = get_publisher_instance(True, False, False) publisher = publisher_instance.main_account with tempfile.NamedTemporaryFile() as f: f.write(b"bbb") f.flush() url = publisher_instance.files.upload_filecoin(f.name) metadata["main"]["files"] = [{ "index": 0, "contentType": "text/text", "encoding": "UTF-8", "compression": "zip", "checksum": str(uuid.uuid4()), "checksumType": "MD5", "contentLength": "12057507", "url": url, }] ddo = publisher_instance.assets.create(metadata, publisher) service_agreement = ddo.get_service("access") path = publisher_instance.assets.download(ddo.did, service_agreement.index, publisher, "/tmp/outputs") assert path is not None with (pathlib.Path(path) / "file-0").open("rb") as f: assert f.read() == b"bbb"
def test_upload_filecoin(): publisher_instance = get_publisher_instance(True, False, False) with tempfile.NamedTemporaryFile() as f: f.write(b"Hello, Nevermined!") f.flush() url = publisher_instance.files.upload_filecoin(f.name) assert url == "cid://QmSJA3xNH62sj4xggZZzCp2VXpsXbkR9zYoqNYXp3c4xuN"
def test_publisher_download_compute(metadata): config = ExampleConfig.get_config() publisher_instance = get_publisher_instance(True, False, False) publisher = publisher_instance.main_account ddo = publisher_instance.assets.create_compute(metadata, publisher) assert ddo service_agreement = ddo.get_service("compute") assert publisher_instance.assets.download( ddo.did, service_agreement.index, publisher, config.downloads_path ) publisher_instance.assets.retire(ddo.did)
def __init__(self, ocean_instance=None, account=None): if not ocean_instance: from tests.resources.helper_functions import get_publisher_instance ocean_instance = get_publisher_instance(init_tokens=False, use_ss_mock=False, use_gateway_mock=True) self.ocean_instance = ocean_instance self.account = account if not account: from tests.resources.helper_functions import get_publisher_account self.account = get_publisher_account()
def test_publisher_download_algorithm(ddo_algorithm): config = ExampleConfig.get_config() publisher_instance = get_publisher_instance(True, False, False) publisher = publisher_instance.main_account metadata = ddo_algorithm["service"][0] ddo = publisher_instance.assets.create(metadata["attributes"], publisher) assert ddo service_agreement = ddo.get_service("access") assert publisher_instance.assets.download( ddo.did, service_agreement.index, publisher, config.downloads_path ) publisher_instance.assets.retire(ddo.did)
def test_provider_download_algorithm(ddo_algorithm): config = ExampleConfig.get_config() publisher_instance = get_publisher_instance(True, False, False) provider = publisher_instance.main_account consumer_instance = get_consumer_instance(True, False, False) consumer = consumer_instance.main_account metadata = ddo_algorithm["service"][0] # consumer creates algorithm asset (for a compute job) ddo = consumer_instance.assets.create( metadata["attributes"], consumer, providers=[provider.address] ) assert ddo # provider downloads the asset service_agreement = ddo.get_service("access") assert publisher_instance.assets.download( ddo.did, service_agreement.index, consumer, config.downloads_path ) consumer_instance.assets.retire(ddo.did)
def test_create_asset_with_cid(metadata): publisher_instance = get_publisher_instance(True, False, False) publisher = publisher_instance.main_account with tempfile.NamedTemporaryFile() as f: f.write(b"aaa") f.flush() url = publisher_instance.files.upload_filecoin(f.name) metadata["main"]["files"] = [{ "index": 0, "contentType": "text/text", "encoding": "UTF-8", "compression": "zip", "checksum": str(uuid.uuid4()), "checksumType": "MD5", "contentLength": "12057507", "url": url, }] ddo = publisher_instance.assets.create(metadata, publisher) assert ddo is not None
def test_consumer_download_compute(metadata): config = ExampleConfig.get_config() publisher_instance = get_publisher_instance(True, False, False) publisher = publisher_instance.main_account consumer_instance = get_consumer_instance(True, False, False) consumer = consumer_instance.main_account # publisher creates compute asset ddo = publisher_instance.assets.create_compute(metadata, publisher) assert ddo # consumer orders compute asset service_agreement = ddo.get_service("compute") _agreement_id = consumer_instance.assets.order( ddo.did, service_agreement.index, consumer, consumer ) # consumer tries to download the asset with pytest.raises(ValueError): consumer_instance.assets.download( ddo.did, service_agreement.index, consumer, config.downloads_path ) publisher_instance.assets.retire(ddo.did)
def registered_ddo(): return get_registered_ddo(get_publisher_instance(), get_publisher_account())
def publisher_instance_gateway(): return get_publisher_instance(use_gateway_mock=False, use_ss_mock=False)
def publisher_instance_no_init(): return get_publisher_instance(False, False, False)
def publisher_instance(): return get_publisher_instance()