2 Tests for SQL preprocessing.
 
   7 def sql_factory(tmp_path):
 
   9         (tmp_path / 'test.sql').write_text("""
 
  10           CREATE OR REPLACE FUNCTION test() RETURNS TEXT
 
  15           $$ LANGUAGE plpgsql IMMUTABLE;""".format(sql_body))
 
  20 @pytest.mark.parametrize("expr,ret", [
 
  22     ("'{{db.partitions|join}}'", '012'),
 
  23     ("{% if 'country_name' in db.tables %}'yes'{% else %}'no'{% endif %}", "yes"),
 
  24     ("{% if 'xxx' in db.tables %}'yes'{% else %}'no'{% endif %}", "no"),
 
  26 def test_load_file_simple(sql_preprocessor, sql_factory, temp_db_conn, temp_db_cursor, expr, ret):
 
  27     sqlfile = sql_factory("RETURN {};".format(expr))
 
  29     sql_preprocessor.run_sql_file(temp_db_conn, sqlfile)
 
  31     assert temp_db_cursor.scalar('SELECT test()') == ret
 
  34 def test_load_file_with_params(sql_preprocessor, sql_factory, temp_db_conn, temp_db_cursor):
 
  35     sqlfile = sql_factory("RETURN '{{ foo }} {{ bar }}';")
 
  37     sql_preprocessor.run_sql_file(temp_db_conn, sqlfile, bar='XX', foo='ZZ')
 
  39     assert temp_db_cursor.scalar('SELECT test()') == 'ZZ XX'