-
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathtest_discover.py
More file actions
60 lines (42 loc) · 1.91 KB
/
test_discover.py
File metadata and controls
60 lines (42 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from pathlib import Path
import pytest
from fastapi_cli.discover import (
ImportData,
get_import_data_from_import_string,
)
from fastapi_cli.exceptions import FastAPICLIException
from tests.utils import changing_dir
assets_path = Path(__file__).parent / "assets"
def test_get_import_data_from_import_string_valid() -> None:
with changing_dir(assets_path):
result = get_import_data_from_import_string("package.mod.app:app")
assert isinstance(result, ImportData)
assert result.app_name == "app"
assert result.import_string == "package.mod.app:app"
assert result.module_data.module_import_str == "package.mod.app"
assert result.module_data.extra_sys_path == Path(assets_path).resolve()
assert result.module_data.module_paths == []
def test_get_import_data_from_import_string_missing_colon() -> None:
with pytest.raises(FastAPICLIException) as exc_info:
get_import_data_from_import_string("module.submodule")
assert "Import string must be in the format module.submodule:app_name" in str(
exc_info.value
)
def test_get_import_data_from_import_string_missing_app() -> None:
with pytest.raises(FastAPICLIException) as exc_info:
get_import_data_from_import_string("module.submodule:")
assert "Import string must be in the format module.submodule:app_name" in str(
exc_info.value
)
def test_get_import_data_from_import_string_missing_module() -> None:
with pytest.raises(FastAPICLIException) as exc_info:
get_import_data_from_import_string(":app")
assert "Import string must be in the format module.submodule:app_name" in str(
exc_info.value
)
def test_get_import_data_from_import_string_empty() -> None:
with pytest.raises(FastAPICLIException) as exc_info:
get_import_data_from_import_string("")
assert "Import string must be in the format module.submodule:app_name" in str(
exc_info.value
)