|
1 | 1 | import spatialite
|
| 2 | +import sqlite3 |
2 | 3 | import pytest
|
3 | 4 | import pandas as pd
|
4 | 5 |
|
5 | 6 | from digital_land.expectations.operation import (
|
| 7 | + check_columns, |
6 | 8 | count_lpa_boundary,
|
7 | 9 | count_deleted_entities,
|
8 | 10 | )
|
@@ -174,3 +176,67 @@ def test_count_deleted_entities(dataset_path, mocker):
|
174 | 176 | for key in detail_keys:
|
175 | 177 | assert key in details, f"{key} missing from details"
|
176 | 178 | assert "1002" in details["entities"]
|
| 179 | + |
| 180 | + |
| 181 | +def test_check_columns(dataset_path): |
| 182 | + expected = { |
| 183 | + "entity": [ |
| 184 | + "dataset", |
| 185 | + "end_date", |
| 186 | + "entity", |
| 187 | + "entry_date", |
| 188 | + "geojson", |
| 189 | + "geometry", |
| 190 | + "json", |
| 191 | + "name", |
| 192 | + "organisation_entity", |
| 193 | + "point", |
| 194 | + "prefix", |
| 195 | + "reference", |
| 196 | + "start_date", |
| 197 | + "typology", |
| 198 | + ], |
| 199 | + "old_entity": ["old_entity", "entity"], |
| 200 | + } |
| 201 | + |
| 202 | + with sqlite3.connect(dataset_path) as conn: |
| 203 | + result, message, details = check_columns(conn.cursor(), expected) |
| 204 | + |
| 205 | + assert result |
| 206 | + assert "2 out of 2 tables had expected columns" in message |
| 207 | + |
| 208 | + assert details[0]["table"] == "entity" |
| 209 | + assert any(x in details[0]["actual"] for x in expected["entity"]) |
| 210 | + assert any(x in details[0]["expected"] for x in expected["entity"]) |
| 211 | + |
| 212 | + |
| 213 | +def test_check_columns_failure(dataset_path): |
| 214 | + expected = { |
| 215 | + "entity": [ |
| 216 | + "missing", |
| 217 | + "columns", |
| 218 | + "dataset", |
| 219 | + "end_date", |
| 220 | + "entity", |
| 221 | + "entry_date", |
| 222 | + "geojson", |
| 223 | + "geometry", |
| 224 | + "json", |
| 225 | + "name", |
| 226 | + "organisation_entity", |
| 227 | + "point", |
| 228 | + "prefix", |
| 229 | + "reference", |
| 230 | + "start_date", |
| 231 | + "typology", |
| 232 | + ], |
| 233 | + "old_entity": ["old_entity", "entity"], |
| 234 | + } |
| 235 | + |
| 236 | + with sqlite3.connect(dataset_path) as conn: |
| 237 | + result, message, details = check_columns(conn.cursor(), expected) |
| 238 | + assert not result |
| 239 | + assert "1 out of 2 tables had expected columns" in message |
| 240 | + assert not details[0]["success"] |
| 241 | + assert "missing" in details[0]["missing"] |
| 242 | + assert "columns" in details[0]["missing"] |
0 commit comments