-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow JSON values in
Secret
block (#14980)
- Loading branch information
Showing
5 changed files
with
99 additions
and
29 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
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 |
---|---|---|
@@ -1,18 +1,43 @@ | ||
import pendulum | ||
import pytest | ||
from pydantic import Secret as PydanticSecret | ||
from pydantic import SecretStr | ||
from pydantic_extra_types.pendulum_dt import DateTime as PydanticDateTime | ||
|
||
from prefect.blocks import system | ||
from prefect.blocks.system import DateTime, Secret | ||
|
||
|
||
async def test_datetime(): | ||
await system.DateTime(value=pendulum.datetime(2022, 1, 1)).save(name="test") | ||
api_block = await system.DateTime.load("test") | ||
def test_datetime(): | ||
DateTime(value=PydanticDateTime(2022, 1, 1)).save(name="test") | ||
api_block = DateTime.load("test") | ||
assert api_block.value == pendulum.datetime(2022, 1, 1) | ||
|
||
|
||
async def test_secret_block(): | ||
await system.Secret(value="test").save(name="test") | ||
api_block = await system.Secret.load("test") | ||
assert isinstance(api_block.value, SecretStr) | ||
@pytest.mark.parametrize( | ||
"value", | ||
["test", {"key": "value"}, ["test"]], | ||
ids=["string", "dict", "list"], | ||
) | ||
def test_secret_block(value): | ||
Secret(value=value).save(name="test") | ||
api_block = Secret.load("test") | ||
assert isinstance(api_block.value, PydanticSecret) | ||
|
||
assert api_block.get() == "test" | ||
assert api_block.get() == value | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"value", | ||
[ | ||
SecretStr("test"), | ||
PydanticSecret[dict]({"key": "value"}), | ||
PydanticSecret[list](["test"]), | ||
], | ||
ids=["secret_string", "secret_dict", "secret_list"], | ||
) | ||
def test_secret_block_with_pydantic_secret(value): | ||
Secret(value=value).save(name="test") | ||
api_block = Secret.load("test") | ||
assert isinstance(api_block.value, PydanticSecret) | ||
|
||
assert api_block.get() == value.get_secret_value() |