Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Nov 5, 2024
1 parent c252431 commit f129f23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/settings-library/src/settings_library/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class DefaultFromEnvFactoryError(ValueError):
def __init__(self, errors):
super().__init__()
super().__init__("Default could not be constructed")
self.errors = errors


Expand Down
12 changes: 10 additions & 2 deletions packages/settings-library/tests/test_base_w_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,24 @@ def test_parse_from_empty_envs(

S1, S2, S3, S4, S5 = model_classes_factory()

with pytest.raises(ValidationError):
with pytest.raises(ValidationError, match="WEBSERVER_POSTGRES") as exc_info:
S1()

validation_error = exc_info.value
assert validation_error.error_count() == 1
error = validation_error.errors()[0]
assert error["type"] == "missing"
assert error["input"] == {}

s2 = S2()
assert s2.WEBSERVER_POSTGRES_NULLABLE_OPTIONAL is None

with pytest.raises(DefaultFromEnvFactoryError):
with pytest.raises(DefaultFromEnvFactoryError) as exc_info:
# NOTE: cannot have a default or assignment
S3()

assert len(exc_info.value.errors) == 4, "Default could not be constructed"

# auto default factory resolves to None (because is nullable)
s4 = S4()
assert s4.WEBSERVER_POSTGRES_NULLABLE_DEFAULT_ENV is None
Expand Down

0 comments on commit f129f23

Please sign in to comment.