mirror of
https://github.com/hanzo-ds/connect.git
synced 2026-10-30 20:31:24 +00:00
Imports read `datastore_connect`, distribution `datastore-connect`, so nothing has to import another product's name to talk to Hanzo Datastore. Cut from upstream 0.8.17 — the version this stack already ran — rather than from upstream HEAD, so it is a PURE RENAME with no behaviour change. Forking from HEAD would have dragged versions along with the name (connect alone jumped 0.8.17 -> 1.6.0, a major), which is a different and much riskier change wearing a rename's clothes. X-ClickHouse-* headers are untouched: they are wire protocol the server sends and expects, and a different token shape from the module name.
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from datetime import datetime, date
|
|
|
|
import pytest
|
|
|
|
from datastore_connect.driver.binding import finalize_query, format_bind_value
|
|
|
|
|
|
def test_finalize():
|
|
hash_id = '0x772'
|
|
timestamp = datetime.fromtimestamp(1661447719)
|
|
parameters = {'hash_id': hash_id, 'dt': timestamp}
|
|
expected = "SELECT hash_id FROM db.mytable WHERE hash_id = '0x772' AND dt = '2022-08-25 17:15:19'"
|
|
query = finalize_query('SELECT hash_id FROM db.mytable WHERE hash_id = %(hash_id)s AND dt = %(dt)s', parameters)
|
|
assert query == expected
|
|
|
|
parameters = [hash_id, timestamp]
|
|
query = finalize_query('SELECT hash_id FROM db.mytable WHERE hash_id = %s AND dt = %s', parameters)
|
|
assert query == expected
|
|
|
|
|
|
# pylint: disable=inconsistent-quotes
|
|
@pytest.mark.parametrize('value, expected', [
|
|
("a", "a"),
|
|
("a'", r"a\'"),
|
|
("'a'", r"\'a\'"),
|
|
("''a'", r"\'\'a\'"),
|
|
([], "[]"),
|
|
([1], "[1]"),
|
|
(["a"], "['a']"),
|
|
(["a'"], r"['a\'']"),
|
|
([["a"]], "[['a']]"),
|
|
(date(2023, 6, 1), '2023-06-01'),
|
|
(datetime(2023, 6, 1, 20, 4, 5), '2023-06-01 20:04:05'),
|
|
([date(2023, 6, 1), date(2023, 8, 5)], "['2023-06-01', '2023-08-05']")
|
|
|
|
])
|
|
def test_format_bind_value(value, expected):
|
|
assert format_bind_value(value) == expected
|