|
1 | 1 | import os |
2 | 2 |
|
3 | 3 | import pytest |
| 4 | +from helpers.data_source_test_helper import DataSourceTestHelper |
| 5 | +from helpers.mock_soda_cloud import MockResponse |
4 | 6 | from helpers.test_connection import TestConnection |
| 7 | +from helpers.test_table import TestTableSpecification |
| 8 | + |
| 9 | +test_table_specification = ( |
| 10 | + TestTableSpecification.builder() |
| 11 | + .table_purpose("1-schema_databricks-special-chars") |
| 12 | + .column_varchar("id-1") |
| 13 | + .column_integer("2-size") |
| 14 | + .column_date("/+created") |
| 15 | + .build() |
| 16 | +) |
5 | 17 |
|
6 | 18 | DATABRICKS_HOST = os.getenv("DATABRICKS_HOST") |
7 | 19 | DATABRICKS_HTTP_PATH = os.getenv("DATABRICKS_HTTP_PATH") |
|
61 | 73 | @pytest.mark.parametrize("test_connection", test_connections, ids=[tc.test_name for tc in test_connections]) |
62 | 74 | def test_databricks_connections(test_connection: TestConnection): |
63 | 75 | test_connection.test() |
| 76 | + |
| 77 | + |
| 78 | +def test_databricks_schema_check_special_chars(data_source_test_helper: DataSourceTestHelper): |
| 79 | + test_table = data_source_test_helper.ensure_test_table(test_table_specification) |
| 80 | + data_source_test_helper.enable_soda_cloud_mock( |
| 81 | + [ |
| 82 | + MockResponse(status_code=200, json_object={"fileId": "a81bc81b-dead-4e5d-abff-90865d1e13b1"}), |
| 83 | + ] |
| 84 | + ) |
| 85 | + |
| 86 | + data_source_test_helper.assert_contract_pass( |
| 87 | + test_table=test_table, |
| 88 | + contract_yaml_str=f""" |
| 89 | + checks: |
| 90 | + - schema: |
| 91 | + columns: |
| 92 | + - name: id-1 |
| 93 | + data_type: {test_table.data_type('id-1')} |
| 94 | + - name: 2-size |
| 95 | + data_type: {test_table.data_type('2-size')} |
| 96 | + - name: /+created |
| 97 | + """, |
| 98 | + ) |
| 99 | + |
| 100 | + soda_core_insert_scan_results_command = data_source_test_helper.soda_cloud.requests[1].json |
| 101 | + check_json: dict = soda_core_insert_scan_results_command["checks"][0] |
| 102 | + schema_diagnostics: dict = check_json["diagnostics"]["v4"] |
| 103 | + assert schema_diagnostics["type"] == "schema" |
| 104 | + assert set([c["name"] for c in schema_diagnostics["actual"]]) == {"id-1", "2-size", "/+created"} |
| 105 | + assert set([c["name"] for c in schema_diagnostics["expected"]]) == {"id-1", "2-size", "/+created"} |
0 commit comments