Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_root_parse_node(self, content_type: str, content: bytes) -> ParseNode:
if not content_type:
raise TypeError("Content Type cannot be null")
valid_content_type = self.get_valid_content_type()
if valid_content_type.casefold() != content_type.casefold():
if valid_content_type.casefold() != content_type.split(";")[0].strip().casefold():
raise TypeError(f"Expected {valid_content_type} as content type")

if not content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_serialization_writer(self, content_type: str) -> SerializationWriter:
if not content_type:
raise TypeError("Content Type cannot be null")
valid_content_type = self.get_valid_content_type()
if valid_content_type.casefold() != content_type.casefold():
if valid_content_type.casefold() != content_type.split(";")[0].strip().casefold():
raise TypeError(f"Expected {valid_content_type} as content type")

return FormSerializationWriter()
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,39 @@
def test_get_valid_content_type():
factory = FormParseNodeFactory()
content_type = factory.get_valid_content_type()
assert content_type == FORM_CONTENT_TYPE
assert content_type == FORM_CONTENT_TYPE


@pytest.mark.parametrize(
"content_type",
[
"application/x-www-form-urlencoded; charset=utf-8",
"application/x-www-form-urlencoded; charset=UTF-8",
"application/x-www-form-urlencoded ; charset=utf-8",
"APPLICATION/X-WWW-FORM-URLENCODED",
"APPLICATION/X-WWW-FORM-URLENCODED; CHARSET=UTF-8",
"Application/x-www-form-urlencoded; charset=utf-8",
],
)
def test_get_root_parse_node_with_parameters_and_case_variants(sample_form_string, content_type):
factory = FormParseNodeFactory()
sample_form_string_bytes = sample_form_string.encode('utf-8')
root = factory.get_root_parse_node(content_type, sample_form_string_bytes)
assert isinstance(root, FormParseNode)


@pytest.mark.parametrize(
"content_type",
[
";",
";;",
"; charset=utf-8",
" ; charset=utf-8",
],
)
def test_get_root_parse_node_delimiter_only(sample_form_string, content_type):
with pytest.raises(TypeError) as e_info:

Check warning on line 79 in packages/serialization/form/tests/unit/test_form_parse_node_factory.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this exception test to have only one invocation possibly throwing an exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-abstractions-python&issues=AaG0sBdoE7uBDFkTHT2A&open=AaG0sBdoE7uBDFkTHT2A&pullRequest=868
factory = FormParseNodeFactory()
sample_form_string_bytes = sample_form_string.encode('utf-8')
factory.get_root_parse_node(content_type, sample_form_string_bytes)
assert str(e_info.value) == f"Expected {FORM_CONTENT_TYPE} as content type"
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,37 @@
def test_get_valid_content_type():
factory = FormSerializationWriterFactory()
content_type = factory.get_valid_content_type()
assert content_type == FORM_CONTENT_TYPE
assert content_type == FORM_CONTENT_TYPE


@pytest.mark.parametrize(
"content_type",
[
"application/x-www-form-urlencoded; charset=utf-8",
"application/x-www-form-urlencoded; charset=UTF-8",
"application/x-www-form-urlencoded ; charset=utf-8",
"APPLICATION/X-WWW-FORM-URLENCODED",
"APPLICATION/X-WWW-FORM-URLENCODED; CHARSET=UTF-8",
"Application/x-www-form-urlencoded; charset=utf-8",
],
)
def test_get_serialization_writer_with_parameters_and_case_variants(content_type):
factory = FormSerializationWriterFactory()
writer = factory.get_serialization_writer(content_type)
assert isinstance(writer, FormSerializationWriter)


@pytest.mark.parametrize(
"content_type",
[
";",
";;",
"; charset=utf-8",
" ; charset=utf-8",
],
)
def test_get_serialization_writer_delimiter_only(content_type):
with pytest.raises(TypeError) as e_info:

Check warning on line 62 in packages/serialization/form/tests/unit/test_form_serialization_writer_factory.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this exception test to have only one invocation possibly throwing an exception.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-abstractions-python&issues=AaG0sBjFE7uBDFkTHT2B&open=AaG0sBjFE7uBDFkTHT2B&pullRequest=868
factory = FormSerializationWriterFactory()
factory.get_serialization_writer(content_type)
assert str(e_info.value) == f"Expected {FORM_CONTENT_TYPE} as content type"
Loading