36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
"""Unit-тесты db/connection.py — SQL-конвертация (без БД)."""
|
|
from db.connection import _pg_to_sqlite, _extract_table
|
|
|
|
|
|
class TestPgToSqlite:
|
|
def test_placeholder(self):
|
|
assert _pg_to_sqlite("SELECT * FROM x WHERE a = %s") == "SELECT * FROM x WHERE a = ?"
|
|
|
|
def test_jsonb(self):
|
|
out = _pg_to_sqlite("UPDATE t SET j = %s::jsonb WHERE id = %s")
|
|
assert "::jsonb" not in out
|
|
|
|
def test_boolean(self):
|
|
out = _pg_to_sqlite("CREATE TABLE t (flag BOOLEAN)")
|
|
assert "BOOLEAN" not in out
|
|
assert "INTEGER" in out
|
|
|
|
def test_ilike(self):
|
|
assert _pg_to_sqlite("WHERE name ILIKE 'x'") == "WHERE name LIKE 'x'"
|
|
|
|
def test_true_false(self):
|
|
out = _pg_to_sqlite("SET a = TRUE, b = FALSE")
|
|
assert "TRUE" not in out
|
|
assert "FALSE" not in out
|
|
|
|
|
|
class TestExtractTable:
|
|
def test_insert(self):
|
|
assert _extract_table("INSERT INTO documents (id) VALUES (1)") == "documents"
|
|
|
|
def test_insert_no_space(self):
|
|
assert _extract_table("INSERT INTO prompts(id) VALUES (1)") == "prompts"
|
|
|
|
def test_no_insert(self):
|
|
assert _extract_table("SELECT * FROM documents") is None
|