-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to pydantic schema and module_loading
- Loading branch information
Showing
4 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
|
||
from esmerald import EsmeraldAPISettings | ||
from esmerald.utils.module_loading import import_string | ||
|
||
|
||
def test_import_error_module_loading(): | ||
path = "tests" | ||
|
||
with pytest.raises(ImportError): | ||
import_string(path) | ||
|
||
|
||
def test_attribute_error_module_loading(): | ||
path = "tests.settings.TestSetting" | ||
|
||
with pytest.raises(ImportError): | ||
import_string(path) | ||
|
||
|
||
def test_imports_successfully(): | ||
path = "tests.settings.TestSettings" | ||
|
||
settings = import_string(path) | ||
|
||
assert issubclass(settings, EsmeraldAPISettings) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from typing import Any | ||
|
||
import pytest | ||
|
||
from esmerald.params import Param | ||
from esmerald.utils.pydantic.schema import is_any_type, is_field_optional | ||
|
||
|
||
def test_is_any_type(): | ||
field = Param(annotation=Any) | ||
|
||
assert is_any_type(field) | ||
|
||
|
||
@pytest.mark.parametrize("allow_none,return_type", [(True, False), (False, False)]) | ||
def test_is_field_optional(allow_none, return_type): | ||
field = Param(allow_none=allow_none) | ||
|
||
assert is_field_optional(field) == return_type |