Validate that expected columns are present in the table
(app, expected_columns)
| 157 | |
| 158 | |
| 159 | def validate_table_columns(app, expected_columns): |
| 160 | """Validate that expected columns are present in the table""" |
| 161 | columns, _ = get_table_data(app) |
| 162 | |
| 163 | # Convert to lowercase for comparison (already stripped in get_table_data) |
| 164 | columns_lower = [col.lower() for col in columns] |
| 165 | |
| 166 | missing_columns = [] |
| 167 | for expected in expected_columns: |
| 168 | expected_lower = expected.lower().strip() |
| 169 | |
| 170 | # Check for exact match or partial match |
| 171 | # Be very flexible - username might appear as 'user', 'username', 'usr', etc. |
| 172 | found = False |
| 173 | for col in columns_lower: |
| 174 | # Check various possibilities |
| 175 | if (expected_lower == col or # Exact match |
| 176 | expected_lower in col or # Expected is substring of column |
| 177 | col in expected_lower or # Column is substring of expected |
| 178 | (expected_lower[:3] in col and len(expected_lower) > 3) or # First 3 chars match |
| 179 | (col[:3] in expected_lower and len(col) > 3)): # First 3 chars of col in expected |
| 180 | found = True |
| 181 | break |
| 182 | |
| 183 | if not found: |
| 184 | missing_columns.append(expected) |
| 185 | |
| 186 | if missing_columns: |
| 187 | error_msg = f"Validation error: Columns {missing_columns} not found. Available columns: {columns}" |
| 188 | print(error_msg) |
| 189 | return False |
| 190 | |
| 191 | print(f"✓ Validated columns: {expected_columns} found in {columns}") |
| 192 | return True |
| 193 | |
| 194 | |
| 195 | # Main test functions |
no test coverage detected