def test_substitute_mapping(self): sql = substitute_parameters( "SELECT %(id)s, %(name)s FROM t WHERE x LIKE 'A%%'", { "id": 1, "name": "foo" }, ) assert sql == "SELECT 1, 'foo' FROM t WHERE x LIKE 'A%'"
def test_invalid(self, value): with pytest.raises(TypeError): substitute_parameters("SELECT %s", value)
def test_substitute_none(self): sql = substitute_parameters("SELECT * FROM t WHERE x LIKE 'A%'") assert sql == "SELECT * FROM t WHERE x LIKE 'A%'"
def test_substitute_sequence(self): sql = substitute_parameters("SELECT %s, %s FROM t WHERE x LIKE 'A%%'", [1, "foo"]) assert sql == "SELECT 1, 'foo' FROM t WHERE x LIKE 'A%'"
def _get_sql(self, operation: str, parameters: PARAMETERS) -> str: sql = substitute_parameters(operation, parameters) if self.normalize: sql = normalize_sql(sql) return sql