-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/notificative-notifications
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from functools import partial | ||
from typing import Callable, List, Optional | ||
|
||
import pytest | ||
|
||
from core.configuration.library import LibrarySettings | ||
from core.util.problem_detail import ProblemError | ||
|
||
LibrarySettingsFixture = Callable[..., LibrarySettings] | ||
|
||
|
||
@pytest.fixture | ||
def library_settings() -> LibrarySettingsFixture: | ||
# Provide a default library settings object for tests, it just gives | ||
# default values for required fields, so we can construct the settings | ||
# without worrying about the defaults. | ||
return partial( | ||
LibrarySettings, | ||
website="http://library.com", | ||
help_web="http://library.com/help", | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"languages,expected", | ||
[ | ||
(None, None), | ||
([], []), | ||
(["English"], ["eng"]), | ||
(["English", "eng", "fr", "fre", "french"], ["eng", "fre"]), | ||
], | ||
) | ||
def test_validate_language_codes( | ||
languages: Optional[List[str]], | ||
expected: Optional[List[str]], | ||
library_settings: LibrarySettingsFixture, | ||
) -> None: | ||
settings = library_settings(large_collection_languages=languages) | ||
assert settings.large_collection_languages == expected | ||
|
||
settings = library_settings(small_collection_languages=languages) | ||
assert settings.small_collection_languages == expected | ||
|
||
settings = library_settings(tiny_collection_languages=languages) | ||
assert settings.tiny_collection_languages == expected | ||
|
||
|
||
def test_validate_language_codes_error( | ||
library_settings: LibrarySettingsFixture, | ||
) -> None: | ||
with pytest.raises(ProblemError) as excinfo: | ||
library_settings(large_collection_languages=["eng", "xyz"]) | ||
|
||
assert excinfo.value.problem_detail.detail is not None | ||
assert '"xyz" is not a valid language code' in excinfo.value.problem_detail.detail |