Skip to content

Commit

Permalink
test: add DefaultCollection.parse_init_arguments tests (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovsds authored Feb 20, 2024
1 parent 3f6e05f commit 63de282
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions secret_transfer/default/collection/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def from_init_arguments(cls, data: core.InitArgumentType) -> typing_extensions.S
source = data.get("source")
if source is None:
raise ValueError("Should have a source.")

if not isinstance(source, protocol.SourceProtocol):
raise ValueError("Should have a source of type SourceProtocol.")

Expand Down
37 changes: 34 additions & 3 deletions tests/unit/default/collection/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,45 @@ def test_parse_init_arguments():
}


def test_parse_init_arguments_invalid():
test_source = test_utils.MagicMock(spec=protocol.SourceProtocol)
def test_parse_init_arguments_not_a_mapping():
with pytest.raises(secret_transfer.DefaultCollection.ValidationError):
secret_transfer.DefaultCollection.parse_init_arguments(
**{
TEST_KEY: "not_a_mapping",
}
)


def test_parse_init_arguments_no_source():
with pytest.raises(secret_transfer.DefaultCollection.ValidationError):
secret_transfer.DefaultCollection.parse_init_arguments(
**{
TEST_KEY: {
"key": TEST_SOURCE_KEY,
},
}
)


def test_parse_init_arguments_no_source_of_type():
with pytest.raises(secret_transfer.DefaultCollection.ValidationError):
secret_transfer.DefaultCollection.parse_init_arguments(
**{
TEST_KEY: {
"source": "not_a_source",
"key": TEST_SOURCE_KEY,
},
}
)


def test_parse_init_arguments_no_key_of_type():
with pytest.raises(secret_transfer.DefaultCollection.ValidationError):
secret_transfer.DefaultCollection.parse_init_arguments(
**{
TEST_KEY: {
"source1": test_source,
"source": test_utils.MagicMock(spec=protocol.SourceProtocol),
"key": 123,
},
}
)
Expand Down

0 comments on commit 63de282

Please sign in to comment.