|
| 1 | +from unittest.mock import patch |
| 2 | + |
| 3 | +from dstack._internal.core.backends.vastai.compute import VastAICompute |
| 4 | +from dstack._internal.core.backends.vastai.models import VastAIConfig, VastAICreds |
| 5 | + |
| 6 | + |
| 7 | +def _config(community_cloud=None) -> VastAIConfig: |
| 8 | + return VastAIConfig(creds=VastAICreds(api_key="test"), community_cloud=community_cloud) |
| 9 | + |
| 10 | + |
| 11 | +def test_vastai_compute_enables_community_cloud_by_default(): |
| 12 | + with patch( |
| 13 | + "dstack._internal.core.backends.vastai.compute.VastAIProvider" |
| 14 | + ) as vast_provider_cls, patch( |
| 15 | + "dstack._internal.core.backends.vastai.compute.gpuhunt.Catalog" |
| 16 | + ) as catalog_cls: |
| 17 | + catalog_instance = catalog_cls.return_value |
| 18 | + VastAICompute(_config()) |
| 19 | + vast_provider_cls.assert_called_once() |
| 20 | + assert vast_provider_cls.call_args.kwargs["community_cloud"] is True |
| 21 | + catalog_instance.add_provider.assert_called_once() |
| 22 | + |
| 23 | + |
| 24 | +def test_vastai_compute_can_enable_community_cloud(): |
| 25 | + with patch( |
| 26 | + "dstack._internal.core.backends.vastai.compute.VastAIProvider" |
| 27 | + ) as vast_provider_cls, patch( |
| 28 | + "dstack._internal.core.backends.vastai.compute.gpuhunt.Catalog" |
| 29 | + ) as catalog_cls: |
| 30 | + catalog_instance = catalog_cls.return_value |
| 31 | + VastAICompute(_config(community_cloud=True)) |
| 32 | + vast_provider_cls.assert_called_once() |
| 33 | + assert vast_provider_cls.call_args.kwargs["community_cloud"] is True |
| 34 | + catalog_instance.add_provider.assert_called_once() |
| 35 | + |
| 36 | + |
| 37 | +def test_vastai_compute_can_disable_community_cloud(): |
| 38 | + with patch( |
| 39 | + "dstack._internal.core.backends.vastai.compute.VastAIProvider" |
| 40 | + ) as vast_provider_cls, patch( |
| 41 | + "dstack._internal.core.backends.vastai.compute.gpuhunt.Catalog" |
| 42 | + ) as catalog_cls: |
| 43 | + catalog_instance = catalog_cls.return_value |
| 44 | + VastAICompute(_config(community_cloud=False)) |
| 45 | + vast_provider_cls.assert_called_once() |
| 46 | + assert vast_provider_cls.call_args.kwargs["community_cloud"] is False |
| 47 | + catalog_instance.add_provider.assert_called_once() |
0 commit comments