|
| 1 | +import pytest |
| 2 | + |
| 3 | +from runloop_api_client.lib.polling import PollingConfig |
| 4 | + |
| 5 | +from .utils import make_client, unique_name |
| 6 | + |
| 7 | +pytestmark = [pytest.mark.smoketest] |
| 8 | + |
| 9 | + |
| 10 | +client = make_client() |
| 11 | + |
| 12 | + |
| 13 | +""" |
| 14 | +Tests are run sequentially and can be dependent on each other. |
| 15 | +This is to avoid overloading resources and save efficiency. |
| 16 | +""" |
| 17 | +_blueprint_id = None |
| 18 | +_blueprint_name = unique_name("bp") |
| 19 | + |
| 20 | + |
| 21 | +def teardown_module() -> None: |
| 22 | + global _blueprint_id |
| 23 | + if _blueprint_id: |
| 24 | + try: |
| 25 | + client.blueprints.delete(_blueprint_id) |
| 26 | + except Exception: |
| 27 | + pass |
| 28 | + |
| 29 | + |
| 30 | +@pytest.mark.timeout(30) |
| 31 | +def test_create_blueprint_and_await_build() -> None: |
| 32 | + global _blueprint_id |
| 33 | + created = client.blueprints.create_and_await_build_complete( |
| 34 | + name=_blueprint_name, |
| 35 | + polling_config=PollingConfig(max_attempts=180, interval_seconds=5.0, timeout_seconds=30 * 60), |
| 36 | + ) |
| 37 | + assert created.status == "build_complete" |
| 38 | + _blueprint_id = created.id |
| 39 | + |
| 40 | + |
| 41 | +@pytest.mark.timeout(30) |
| 42 | +def test_start_devbox_from_base_blueprint_by_id() -> None: |
| 43 | + assert _blueprint_id |
| 44 | + devbox = client.devboxes.create_and_await_running( |
| 45 | + blueprint_id=_blueprint_id, |
| 46 | + polling_config=PollingConfig(max_attempts=120, interval_seconds=5.0, timeout_seconds=20 * 60), |
| 47 | + ) |
| 48 | + assert devbox.blueprint_id == _blueprint_id |
| 49 | + assert devbox.status == "running" |
| 50 | + client.devboxes.shutdown(devbox.id) |
| 51 | + |
| 52 | + |
| 53 | +@pytest.mark.timeout(30) |
| 54 | +def test_start_devbox_from_base_blueprint_by_name() -> None: |
| 55 | + devbox = client.devboxes.create_and_await_running( |
| 56 | + blueprint_name=_blueprint_name, |
| 57 | + polling_config=PollingConfig(max_attempts=120, interval_seconds=5.0, timeout_seconds=20 * 60), |
| 58 | + ) |
| 59 | + assert devbox.blueprint_id |
| 60 | + assert devbox.status == "running" |
| 61 | + client.devboxes.shutdown(devbox.id) |
0 commit comments