-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for
config.id_must_be_valid()
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Tests the :obj:`trolldb.config.config` module.""" | ||
|
||
import pytest | ||
from pydantic import ValidationError | ||
|
||
from trolldb.config.config import id_must_be_valid | ||
|
||
|
||
@pytest.mark.parametrize("id_string", [ | ||
1, 1.0, {}, None, [], () | ||
]) | ||
def test_id_must_be_valid_bad_types(id_string): | ||
"""Tests that we fail to generate a valid ObjectId with wrong input types.""" | ||
with pytest.raises(ValidationError): | ||
id_must_be_valid(id_string) | ||
|
||
|
||
def test_id_must_be_valid_bad_values(): | ||
"""Tests that we fail to generate a valid ObjectId with wrong input values.""" | ||
number_of_chars = list(range(1, 24)) + list(range(25, 30)) | ||
for i in number_of_chars: | ||
id_string = "0" * i | ||
with pytest.raises(ValueError, match=id_string): | ||
id_must_be_valid(id_string) | ||
|
||
|
||
@pytest.mark.parametrize("id_string", [ | ||
"0" * 24, "f" * 24, "6255bbd29606404848162477" | ||
]) | ||
def test_id_must_be_valid_success(id_string): | ||
"""Tests that we succeed to generate a valid ObjectId with valid input values and type.""" | ||
assert str(id_must_be_valid(id_string)) == id_string |