Skip to content

Commit

Permalink
Test that setting an optional password to None doesn't trigger valida…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
jwodder committed Mar 7, 2021
1 parent 1e2f272 commit fab33b7
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion test/test_config/test_password.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Any, Dict
from typing import Any, Dict, Optional
from unittest.mock import sentinel
from pydantic import BaseModel, SecretStr, ValidationError
import pytest
Expand Down Expand Up @@ -221,3 +221,27 @@ def test_username_error_password(mocker: MockerFixture) -> None:
UsernameErrorConfig(configpath="foo/bar", password=sentinel.PASSWORD)
assert "Insufficient data to determine password" in str(excinfo.value)
m.assert_not_called()


class OptionalPasswordConfig(BaseModel):
configpath: Path
host: str
username: str
password: Optional[StandardPassword]


def test_none_optional_password(mocker: MockerFixture) -> None:
m = mocker.patch("outgoing.core.resolve_password", return_value="12345")
cfg = OptionalPasswordConfig(
configpath="foo/bar",
host="example.com",
username="me",
password=None,
)
assert cfg.dict() == {
"configpath": Path("foo/bar"),
"host": "example.com",
"username": "me",
"password": None,
}
m.assert_not_called()

0 comments on commit fab33b7

Please sign in to comment.