-
Notifications
You must be signed in to change notification settings - Fork 59
Fix default port on secure connection + Query Parameterization #138
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import ssl | ||
| from contextlib import nullcontext as does_not_raise | ||
| from datetime import date, datetime | ||
| from enum import Enum | ||
| from typing import Any, ContextManager, Optional | ||
| from uuid import UUID | ||
|
|
||
| import pytest | ||
| from pytest import param | ||
|
|
||
| from asynch.proto.utils.escape import escape_param, escape_params, substitute_params | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("item", "expected"), | ||
| [ | ||
| param(None, "NULL", id="None"), | ||
| param(date(2025, 5, 21), "'2025-05-21'", id="date"), | ||
| param(datetime(2025, 5, 21, 12, 0, 0), "'2025-05-21 12:00:00'", id="datetime"), | ||
| param("test", "'test'", id="str"), | ||
| param([1, 2, 3], "[1, 2, 3]", id="list"), | ||
| param((1, 2, 3), "(1, 2, 3)", id="tuple"), | ||
| param( | ||
| UUID("123e4567-e89b-12d3-a456-426614174000"), | ||
| "'123e4567-e89b-12d3-a456-426614174000'", | ||
| id="uuid", | ||
| ), | ||
| param(Enum("testEnum", {"test1": "test1", "test2": "test2"}).test1, "'test1'", id="enum"), | ||
| ], | ||
| ) | ||
| def test_escape_param(item, expected): | ||
| assert escape_param(item) == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("params", "expected"), | ||
| [ | ||
| param({"test": "test"}, {"test": "'test'"}, id="strings"), | ||
| param( | ||
| {"test": 1, "test2": 2, "test3": 0, "test4": -1}, | ||
| {"test": 1, "test2": 2, "test3": 0, "test4": -1}, | ||
| id="ints", | ||
| ), | ||
| param( | ||
| {"test": 1.0, "test2": 0.1, "test3": -0.1, "test4": 0.0}, | ||
| {"test": 1.0, "test2": 0.1, "test3": -0.1, "test4": 0.0}, | ||
| id="floats", | ||
| ), | ||
| param({"test": None}, {"test": "NULL"}, id="none"), | ||
| param({"test": date(2025, 5, 21)}, {"test": "'2025-05-21'"}, id="dates"), | ||
| param( | ||
| {"test": datetime(2025, 5, 21, 12, 0, 0)}, | ||
| {"test": "'2025-05-21 12:00:00'"}, | ||
| id="datetimes", | ||
| ), | ||
| param( | ||
| {"test": UUID("123e4567-e89b-12d3-a456-426614174000")}, | ||
| {"test": "'123e4567-e89b-12d3-a456-426614174000'"}, | ||
| id="uuids", | ||
| ), | ||
| ], | ||
| ) | ||
| def test_escape_params(params, expected): | ||
| assert escape_params(params) == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("query", "params", "expected"), | ||
| [ | ||
| param("{test}", {"test": "test"}, "'test'", id="string"), | ||
| param("{test} {test}", {"test": "test"}, "'test' 'test'", id="strings"), | ||
| param("{test} {test}", {"test": None}, "NULL NULL", id="none"), | ||
| param("{test} {test}", {"test": 1}, "1 1", id="int"), | ||
| param("{test} {test}", {"test": 1.0}, "1.0 1.0", id="float"), | ||
| param("{test} {test}", {"test": date(2025, 5, 21)}, "'2025-05-21' '2025-05-21'", id="date"), | ||
| param( | ||
| "{test} {test}", | ||
| {"test": datetime(2025, 5, 21, 12, 0, 0)}, | ||
| "'2025-05-21 12:00:00' '2025-05-21 12:00:00'", | ||
| id="datetime", | ||
| ), | ||
| param( | ||
| "{test} {test}", | ||
| {"test": UUID("123e4567-e89b-12d3-a456-426614174000")}, | ||
| "'123e4567-e89b-12d3-a456-426614174000' '123e4567-e89b-12d3-a456-426614174000'", | ||
| ), | ||
| ], | ||
| ) | ||
| def test_substitute_params(query, params, expected): | ||
| assert substitute_params(query, params) == expected |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need
stack_track=stack_trackin the middle?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on what I see above, because
stack_trackis not part ofdsn, so will be missing if we follow the first if branch above. Probably for same reason it was explicitly passed in prev version.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be excluded from
configthen, I think