|
12 | 12 |
|
13 | 13 | import testgen.ui.services.form_service as fm
|
14 | 14 | from testgen.common import date_service
|
| 15 | +from testgen.common.database.database_service import get_flavor_service, replace_params |
15 | 16 | from testgen.common.models import with_database_session
|
16 | 17 | from testgen.common.models.connection import Connection
|
17 | 18 | from testgen.common.models.table_group import TableGroup, TableGroupMinimal
|
@@ -1179,17 +1180,33 @@ def get_column_names(table_groups_id: str, table_name: str) -> list[str]:
|
1179 | 1180 | def validate_test(test_definition, table_group: TableGroupMinimal):
|
1180 | 1181 | schema = test_definition["schema_name"]
|
1181 | 1182 | table_name = test_definition["table_name"]
|
| 1183 | + connection = Connection.get_by_table_group(table_group.id) |
1182 | 1184 |
|
1183 | 1185 | if test_definition["test_type"] == "Condition_Flag":
|
1184 | 1186 | condition = test_definition["custom_query"]
|
| 1187 | + concat_operator = get_flavor_service(connection.sql_flavor).get_concat_operator() |
1185 | 1188 | query = f"""
|
1186 | 1189 | SELECT
|
1187 |
| - COALESCE(CAST(SUM(CASE WHEN {condition} THEN 1 ELSE 0 END) AS VARCHAR(1000) ) || '|' ,'<NULL>|') |
| 1190 | + COALESCE( |
| 1191 | + CAST( |
| 1192 | + SUM( |
| 1193 | + CASE WHEN {condition} THEN 1 ELSE 0 END |
| 1194 | + ) AS VARCHAR(1000) |
| 1195 | + ) |
| 1196 | + {concat_operator} '|', |
| 1197 | + '<NULL>|' |
| 1198 | + ) |
1188 | 1199 | FROM {schema}.{table_name};
|
1189 | 1200 | """
|
1190 | 1201 | else:
|
1191 |
| - query = test_definition["custom_query"] |
1192 |
| - query = query.replace("{DATA_SCHEMA}", schema) |
| 1202 | + query = replace_params( |
| 1203 | + f""" |
| 1204 | + SELECT COUNT(*) |
| 1205 | + FROM ( |
| 1206 | + {test_definition["custom_query"]} |
| 1207 | + ) TEST |
| 1208 | + """, |
| 1209 | + {"DATA_SCHEMA": schema}, |
| 1210 | + ) |
1193 | 1211 |
|
1194 |
| - connection = Connection.get_by_table_group(table_group.id) |
1195 | 1212 | fetch_from_target_db(connection, query)
|
0 commit comments