Repository navigation
fix(serialization-text): preserve empty string and bytes values and handle malformed inputs #840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
63ce3f4
246e70c
8631a40
9d1d7de
0368634
b90a043
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # ------------------------------------------------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. All Rights Reserved. | ||
| # Licensed under the MIT License. | ||
| # See License in the project root for license information. | ||
| # ------------------------------------------------------------------------------ | ||
|
|
||
| from unittest.mock import Mock | ||
|
|
||
| import pytest | ||
|
|
||
| from kiota_abstractions.serialization import ParseNode, ParseNodeFactory, ParseNodeFactoryRegistry | ||
|
|
||
|
|
||
| def test_registry_dispatches_empty_content(monkeypatch): | ||
| registry = ParseNodeFactoryRegistry() | ||
| mock_node = Mock(spec=ParseNode) | ||
| mock_factory = Mock(spec=ParseNodeFactory) | ||
| mock_factory.get_root_parse_node.return_value = mock_node | ||
|
|
||
| monkeypatch.setitem(registry.CONTENT_TYPE_ASSOCIATED_FACTORIES, "text/plain", mock_factory) | ||
|
|
||
| result = registry.get_root_parse_node("text/plain", b"") | ||
| assert result is mock_node | ||
| mock_factory.get_root_parse_node.assert_called_once_with("text/plain", b"") | ||
|
|
||
|
|
||
| def test_registry_raises_on_none_content(): | ||
| registry = ParseNodeFactoryRegistry() | ||
| with pytest.raises(Exception) as exc_info: | ||
|
Check warning on line 29 in packages/abstractions/tests/test_parse_node_factory_registry.py
|
||
| registry.get_root_parse_node("text/plain", None) | ||
| assert "Content cannot be null" in str(exc_info.value) | ||
|
|
||
|
|
||
| def test_registry_raises_on_empty_content_type(): | ||
| registry = ParseNodeFactoryRegistry() | ||
| with pytest.raises(Exception) as exc_info: | ||
|
Check warning on line 36 in packages/abstractions/tests/test_parse_node_factory_registry.py
|
||
| registry.get_root_parse_node("", b"hello") | ||
| assert "Content type cannot be null" in str(exc_info.value) | ||
Uh oh!
There was an error while loading. Please reload this page.