|
| 1 | +import json |
| 2 | +from typing import List |
| 3 | + |
| 4 | +import pytest |
| 5 | +from steamship_tests import TEST_ASSETS_PATH |
| 6 | +from steamship_tests.utils.deployables import zip_deployable |
| 7 | + |
| 8 | +from steamship import Package, PackageInstance, PackageVersion, Steamship, SteamshipError |
| 9 | +from steamship.data.package.package_version import CreatePackageVersionRequest |
| 10 | +from steamship.utils.url import Verb |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.usefixtures("client") |
| 14 | +def test_install_two_packages_at_once(client: Steamship): |
| 15 | + |
| 16 | + pillow_version_task = create_version(client, additional_requirements=["pillow"]) |
| 17 | + pandas_version_task = create_version(client, additional_requirements=["pandas"]) |
| 18 | + |
| 19 | + pillow_version = pillow_version_task.wait() |
| 20 | + pandas_version = pandas_version_task.wait() |
| 21 | + |
| 22 | + pillow_instance = PackageInstance.create( |
| 23 | + client, package_id=pillow_version.package_id, package_version_id=pillow_version.id |
| 24 | + ) |
| 25 | + pandas_instance = PackageInstance.create( |
| 26 | + client, package_id=pandas_version.package_id, package_version_id=pandas_version.id |
| 27 | + ) |
| 28 | + |
| 29 | + # Pillow version should be able to run the method that imports pillow locally |
| 30 | + assert pillow_instance.invoke("try_pillow", verb=Verb.GET) == "PIL" |
| 31 | + |
| 32 | + # Pillow version should NOT be able to run the method that imports pandas locally |
| 33 | + with pytest.raises(SteamshipError): |
| 34 | + _ = pillow_instance.invoke("try_pandas", verb=Verb.GET) |
| 35 | + |
| 36 | + # Pandas version should be able to run the method that imports pandas locally |
| 37 | + assert pandas_instance.invoke("try_pandas", verb=Verb.GET) == "pandas" |
| 38 | + |
| 39 | + # Pandas version should NOT be able to run the method that imports pillow locally |
| 40 | + with pytest.raises(SteamshipError): |
| 41 | + _ = pandas_instance.invoke("try_pillow", verb=Verb.GET) |
| 42 | + |
| 43 | + pillow_version.delete() |
| 44 | + pandas_version.delete() |
| 45 | + |
| 46 | + |
| 47 | +def create_version(client: Steamship, additional_requirements: List[str]): |
| 48 | + """Separate implementation of create version so that we can not wait on the task, and run multiple at once.""" |
| 49 | + package = Package.create(client) |
| 50 | + |
| 51 | + zip_bytes = zip_deployable( |
| 52 | + TEST_ASSETS_PATH / "packages" / "requirement_isolation_package.py", |
| 53 | + additional_requirements=additional_requirements, |
| 54 | + ) |
| 55 | + hosting_handler = "steamship.invocable.entrypoint.safe_handler" |
| 56 | + |
| 57 | + req = CreatePackageVersionRequest( |
| 58 | + handle="handle", |
| 59 | + package_id=package.id, |
| 60 | + config_template=json.dumps({}), |
| 61 | + hosting_handler=hosting_handler, |
| 62 | + ) |
| 63 | + |
| 64 | + task = client.post( |
| 65 | + "package/version/create", |
| 66 | + payload=req, |
| 67 | + file=("package.zip", zip_bytes, "multipart/form-data"), |
| 68 | + expect=PackageVersion, |
| 69 | + ) |
| 70 | + return task |
0 commit comments