|
1 | 1 | from typing import Callable, List |
2 | 2 |
|
| 3 | +from pydantic import ValidationError |
3 | 4 | from pytest import raises |
4 | 5 | from pytest_httpx import HTTPXMock |
5 | 6 |
|
6 | 7 | from firebolt.common import Settings |
7 | 8 | from firebolt.common.exception import FireboltError, NoAttachedDatabaseError |
8 | | -from firebolt.model.engine import Engine |
| 9 | +from firebolt.model.engine import Engine, _EngineCreateRequest |
| 10 | +from firebolt.model.engine_revision import EngineRevision |
9 | 11 | from firebolt.model.instance_type import InstanceType |
10 | 12 | from firebolt.model.region import Region |
11 | 13 | from firebolt.service.manager import ResourceManager |
@@ -47,6 +49,103 @@ def test_engine_create( |
47 | 49 | assert engine.name == engine_name |
48 | 50 |
|
49 | 51 |
|
| 52 | +def test_engine_create_with_kwargs( |
| 53 | + httpx_mock: HTTPXMock, |
| 54 | + auth_callback: Callable, |
| 55 | + auth_url: str, |
| 56 | + provider_callback: Callable, |
| 57 | + provider_url: str, |
| 58 | + instance_type_region_1_callback: Callable, |
| 59 | + instance_type_region_1_url: str, |
| 60 | + region_callback: Callable, |
| 61 | + region_url: str, |
| 62 | + settings: Settings, |
| 63 | + mock_engine: Engine, |
| 64 | + engine_name: str, |
| 65 | + account_id_callback: Callable, |
| 66 | + account_id_url: str, |
| 67 | + engine_callback: Callable, |
| 68 | + engine_url: str, |
| 69 | + account_id: str, |
| 70 | + mock_engine_revision: EngineRevision, |
| 71 | +): |
| 72 | + httpx_mock.add_callback(auth_callback, url=auth_url) |
| 73 | + httpx_mock.add_callback(provider_callback, url=provider_url) |
| 74 | + httpx_mock.add_callback( |
| 75 | + instance_type_region_1_callback, url=instance_type_region_1_url |
| 76 | + ) |
| 77 | + httpx_mock.add_callback(account_id_callback, url=account_id_url) |
| 78 | + httpx_mock.add_callback(auth_callback, url=auth_url) |
| 79 | + httpx_mock.add_callback(region_callback, url=region_url) |
| 80 | + # Setting to manager.engines.create defaults |
| 81 | + mock_engine.key = None |
| 82 | + mock_engine.description = "" |
| 83 | + mock_engine.endpoint = None |
| 84 | + # Testing kwargs |
| 85 | + mock_engine.settings.minimum_logging_level = "ENGINE_SETTINGS_LOGGING_LEVEL_DEBUG" |
| 86 | + mock_engine_revision.specification.proxy_version = "0.2.3" |
| 87 | + engine_content = _EngineCreateRequest( |
| 88 | + account_id=account_id, engine=mock_engine, engine_revision=mock_engine_revision |
| 89 | + ) |
| 90 | + httpx_mock.add_callback( |
| 91 | + engine_callback, |
| 92 | + url=engine_url, |
| 93 | + method="POST", |
| 94 | + match_content=engine_content.json(by_alias=True).encode("ascii"), |
| 95 | + ) |
| 96 | + |
| 97 | + manager = ResourceManager(settings=settings) |
| 98 | + engine_settings_kwargs = { |
| 99 | + "minimum_logging_level": "ENGINE_SETTINGS_LOGGING_LEVEL_DEBUG" |
| 100 | + } |
| 101 | + revision_spec_kwargs = {"proxy_version": "0.2.3"} |
| 102 | + engine = manager.engines.create( |
| 103 | + name=engine_name, |
| 104 | + engine_settings_kwargs=engine_settings_kwargs, |
| 105 | + revision_spec_kwargs=revision_spec_kwargs, |
| 106 | + ) |
| 107 | + |
| 108 | + assert engine.name == engine_name |
| 109 | + |
| 110 | + |
| 111 | +def test_engine_create_with_kwargs_fail( |
| 112 | + httpx_mock: HTTPXMock, |
| 113 | + auth_callback: Callable, |
| 114 | + auth_url: str, |
| 115 | + provider_callback: Callable, |
| 116 | + provider_url: str, |
| 117 | + instance_type_region_1_callback: Callable, |
| 118 | + instance_type_region_1_url: str, |
| 119 | + region_callback: Callable, |
| 120 | + region_url: str, |
| 121 | + settings: Settings, |
| 122 | + engine_name: str, |
| 123 | + account_id_callback: Callable, |
| 124 | + account_id_url: str, |
| 125 | +): |
| 126 | + httpx_mock.add_callback(auth_callback, url=auth_url) |
| 127 | + httpx_mock.add_callback(provider_callback, url=provider_url) |
| 128 | + httpx_mock.add_callback( |
| 129 | + instance_type_region_1_callback, url=instance_type_region_1_url |
| 130 | + ) |
| 131 | + httpx_mock.add_callback(account_id_callback, url=account_id_url) |
| 132 | + httpx_mock.add_callback(auth_callback, url=auth_url) |
| 133 | + httpx_mock.add_callback(region_callback, url=region_url) |
| 134 | + |
| 135 | + manager = ResourceManager(settings=settings) |
| 136 | + revision_spec_kwargs = {"incorrect_kwarg": "val"} |
| 137 | + with raises(ValidationError): |
| 138 | + manager.engines.create( |
| 139 | + name=engine_name, revision_spec_kwargs=revision_spec_kwargs |
| 140 | + ) |
| 141 | + |
| 142 | + engine_settings_kwargs = {"incorrect_kwarg": "val"} |
| 143 | + with raises(TypeError): |
| 144 | + manager.engines.create( |
| 145 | + name=engine_name, engine_settings_kwargs=engine_settings_kwargs |
| 146 | + ) |
| 147 | + |
| 148 | + |
50 | 149 | def test_engine_create_no_available_types( |
51 | 150 | httpx_mock: HTTPXMock, |
52 | 151 | auth_callback: Callable, |
|
0 commit comments