def test_get_space(): client = get_steamship_client() default = Space.get(client=client).data space1 = Space.create(client=client, handle="test").data space1a = Space.get(client=client, space_id=space1.id).data assert space1a.id == space1.id assert space1a.id != default.id assert space1a.handle == space1.handle
def test_deploy_in_space(): client = get_steamship_client() space = Space.create(client, handle="test-non-default-space").data instance = PluginInstance.create(client, plugin_handle="test-tagger", space_id=space.id).data assert instance.space_id == space.id
def test_upload_download_text(): tempbase = Path(tempfile.mkdtemp()) upfile = tempbase / "up.txt" downfile = tempbase / "down.txt" with open(upfile, "w") as f: f.write("Hello") # Grab a Steamship client and generate an upload url client = get_steamship_client() space = Space.get(client=client).data upload_name = random_name() url_resp = space.create_signed_url( SignedUrl.Request( bucket=SignedUrl.Bucket.PLUGIN_DATA, filepath=upload_name, operation=SignedUrl.Operation.WRITE, )) assert url_resp is not None assert url_resp.data is not None assert url_resp.data.signed_url is not None # Upload the zip file to the URL upload_to_signed_url(url_resp.data.signed_url, filepath=upfile) # Now create a download signed URL download_resp = space.create_signed_url( SignedUrl.Request( bucket=SignedUrl.Bucket.PLUGIN_DATA, filepath=upload_name, operation=SignedUrl.Operation.READ, )) assert download_resp is not None assert download_resp.data is not None assert download_resp.data.signed_url is not None # Verify that we get an exception when downloading something that doesn't exist # TODO: Follow up after we get a firmer understaing of the failure semantics of Localstack 404 errors with # pre-signed URLs versus AWS Actual errors with pre-signed URLs. Localstack seems to reply with an HTTP 200 # containing an XML string that contains an error message. # url = download_resp.data.signedUrl # parsed_url = urlparse(url) # bad_url = urlunparse(parsed_url._replace(path=f"{parsed_url.path}BOOGA")) # bad_download_path = tempbase / Path("bad.zip") # with pytest.raises(Exception): # download_from_signed_url(download_resp.data.signedUrl, to_file=bad_download_path) # Download the zip file to the URL download_from_signed_url(download_resp.data.signed_url, to_file=downfile) # Verify the download URL is there assert os.path.exists(downfile) == True # Verify the zip files are the same with open(downfile, "r") as f1: with open(upfile, "r") as f2: f1c = f1.read() f2c = f2.read() assert f1c == f2c
def test_deploy_in_space(): client = get_steamship_client() demo_app_path = APPS_PATH / "demo_app.py" space = Space.create(client, handle="test-non-default-space").data with deploy_app(client, demo_app_path, space_id=space.id) as (_, _, instance): assert instance.space_id == space.id
def client() -> Steamship: """ Returns a client rooted in a new space, then deletes that space afterwards. """ steamship = get_steamship_client() space = Space.create(client=steamship).data new_client = steamship.for_space(space_id=space.id) yield new_client space.delete()
def test_create_use_delete_space(): client = get_steamship_client() default = Space.get(client=client).data space1 = Space.create(client=client, handle="test").data space2 = Space.create(client=client, handle="test2").data assert space1 is not None assert space1.handle == "test" assert space2 is not None assert space2.handle == "test2" assert space2.id != space1.id assert space1.id != default.id assert space2.id != default.id space1a = Space.get(client=client, space_id=space1.id).data space1b = Space.get(client=client, space_handle=space1.handle).data space1c = Space.get(client=client, space=space1).data assert space1.id == space1a.id assert space1.id == space1b.id assert space1.id == space1c.id space1ad = space1a.delete() assert space1ad.error is None # These two are the same space! You can't delete twice! space1bd = space1b.delete() assert space1bd.error is not None space1cd = space1c.delete() assert space1cd.error is not None space2.delete() space1a_deleted = Space.get(client=client, space_id=space1.id) assert space1a_deleted.error is not None
def test_delete_space(): client = get_steamship_client() default = Space.get(client=client).data space1 = Space.create(client=client, handle="test").data assert default.id is not None assert space1.id is not None assert default.id != space1.id space1.delete() space1a = Space.get(client=client, space_id=space1.id) assert space1a.error is not None space1 = Space.create(client=client, handle="test").data assert default.id is not None assert space1.id is not None assert default.id != space1.id space1a = Space.get(client=client, space_id=space1.id) assert space1a.data is not None assert space1a.error is None space1.delete() space1a = Space.get(client=client, space_id=space1.id) assert space1a.error is not None
def test_default_space(): client = get_steamship_client() space = Space.get(client=client).data assert space is not None assert space.handle == "default"
def temporary_space(steamship: Steamship) -> Space: space = Space.create(client=steamship).data yield space space.delete() # or whatever you need to do at exit
def test_upload_download(): """This test simulates some of the operations models must do when trainable/loading. It performs the following steps: 1. Zips up a folder 2. Creates a signed-url with Write access in the "model" bucket of a space 3. Uploads the zip file 4. Creates a signed-url with Read access in the "model" bucket of a space, pointing to the same file 5. Downloads the file 6. Verifies that they are the same file """ # Copy the test assets to a temp folder tempbase = Path(tempfile.mkdtemp()) shutil.copytree(TEST_ASSETS_PATH, os.path.join(tempbase, "src")) # Zip that folder zip_path = tempbase / Path("src.zip") zip_folder(tempbase / Path("src"), into_file=zip_path) # Verify that on disk, src.zip exists assert os.path.exists(zip_path) == True # Grab a Steamship client and generate an upload url client = get_steamship_client() space = Space.get(client=client).data upload_name = random_name() url_resp = space.create_signed_url( SignedUrl.Request( bucket=SignedUrl.Bucket.PLUGIN_DATA, filepath=upload_name, operation=SignedUrl.Operation.WRITE, )) assert url_resp is not None assert url_resp.data is not None assert url_resp.data.signed_url is not None # Upload the zip file to the URL upload_to_signed_url(url_resp.data.signed_url, filepath=zip_path) # Now create a download signed URL download_resp = space.create_signed_url( SignedUrl.Request( bucket=SignedUrl.Bucket.PLUGIN_DATA, filepath=upload_name, operation=SignedUrl.Operation.READ, )) assert download_resp is not None assert download_resp.data is not None assert download_resp.data.signed_url is not None # Verify that we get an exception when downloading something that doesn't exist # TODO: Follow up after we get a firmer understaing of the failure semantics of Localstack 404 errors with # pre-signed URLs versus AWS Actual errors with pre-signed URLs. Localstack seems to reply with an HTTP 200 # containing an XML string that contains an error message. # url = download_resp.data.signedUrl # parsed_url = urlparse(url) # bad_url = urlunparse(parsed_url._replace(path=f"{parsed_url.path}BOOGA")) # bad_download_path = tempbase / Path("bad.zip") # with pytest.raises(Exception): # download_from_signed_url(download_resp.data.signedUrl, to_file=bad_download_path) # Download the zip file to the URL download_path = tempbase / Path("out.zip") download_from_signed_url(download_resp.data.signed_url, to_file=download_path) # Verify the download URL is there assert os.path.exists(download_path) == True # Verify the zip files are the same with open(download_path, "rb") as f1: with open(zip_path, "rb") as f2: f1c = f1.read() f2c = f2.read() assert f1c == f2c