Skip to content

Commit 705113a

Browse files
more unit tests
1 parent 49cb7c8 commit 705113a

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

test/unit/test_streaming_client_configs.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,15 @@ def test_GIVEN_has_mpl_WHEN_attrs_post_init_THEN_calls_no_mpl_method(
215215
@pytest.mark.parametrize(
216216
"kwargs, stream_type",
217217
(
218-
(dict(source=b"", materials_manager=FakeCryptoMaterialsManager()), io.BytesIO),
219-
(dict(source=b"", key_provider=FakeMasterKeyProvider()), io.BytesIO),
220-
(dict(source="", materials_manager=FakeCryptoMaterialsManager()), io.BytesIO),
221-
(dict(source=io.BytesIO(), materials_manager=FakeCryptoMaterialsManager()), io.BytesIO),
222-
(dict(source=six.StringIO(), materials_manager=FakeCryptoMaterialsManager()), six.StringIO),
223-
(dict(source=b"", keyring=FakeKeyring()), io.BytesIO),
218+
(dict(source=b"", materials_manager=FakeCryptoMaterialsManager())),
219+
(dict(source=b"", key_provider=FakeMasterKeyProvider())),
220+
(dict(source="", materials_manager=FakeCryptoMaterialsManager())),
221+
(dict(source=io.BytesIO(), materials_manager=FakeCryptoMaterialsManager())),
222+
(dict(source=six.StringIO(), materials_manager=FakeCryptoMaterialsManager())),
224223
),
225224
)
226225
def test_client_configs_with_mpl(
227226
kwargs,
228-
stream_type
229227
):
230228
kwargs["commitment_policy"] = CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT
231229

@@ -250,3 +248,29 @@ def test_client_configs_with_mpl(
250248
assert test.key_provider is not None
251249
assert test.key_provider == kwargs["key_provider"]
252250
assert isinstance(test.materials_manager, DefaultCryptoMaterialsManager)
251+
252+
253+
# This needs its own test; pytest parametrize cannot use a conditionally-loaded type
254+
@pytest.mark.skipif(not HAS_MPL, reason="Test should only be executed with MPL in installation")
255+
def test_keyring_client_config_with_mpl(
256+
):
257+
kwargs = {
258+
"source": b"",
259+
"keyring": FakeKeyring()
260+
}
261+
262+
test = _ClientConfig(**kwargs)
263+
264+
# In all cases, config should have a materials manager
265+
assert test.materials_manager is not None
266+
267+
# If materials manager was provided, it should be directly used
268+
if hasattr(kwargs, "materials_manager"):
269+
assert kwargs["materials_manager"] == test.materials_manager
270+
271+
# If MPL keyring was provided, it should be wrapped in MPL materials manager
272+
if hasattr(kwargs, "keyring"):
273+
assert test.keyring is not None
274+
assert test.keyring == kwargs["keyring"]
275+
assert isinstance(test.keyring, IKeyring)
276+
assert isinstance(test.materials_manager, CryptoMaterialsManagerFromMPL)

0 commit comments

Comments
 (0)