Imri Paran 0fee79b200
MINOR: fix sample data issue with Pydantic v2 and refactor python integration tests (#16943)
* tests: refactor

refactor tests and consolidate common functionality in integrations.conftest

this enables writing tests more concisely.
demonstrated with postgres and mssql.
will migrate more

* format

* removed helpers

* changed scope of fictures

* changed scope of fixtures

* added profiler test for mssql

* fixed import in data_quality test

* json safe serialization

* format

* set MARS_Connection

* use SerializableTableData instead of TableData

* deleted file test_postgres.py

* fixed tests

* added more test cases

* format

* changed name test_models.py

* removed the logic for serializing table data

* wip

* changed mapping in common type map

* changed mapping in common type map

* reverted TableData imports

* reverted TableData imports

* reverted TableData imports
2024-07-17 08:11:34 +02:00

58 lines
1.5 KiB
Python

import pytest
from _openmetadata_testutils.helpers.markers import xfail_param
from metadata.generated.schema.entity.data.table import TableData
@pytest.mark.parametrize(
"parameter",
[
TableData(
columns=[],
rows=[],
),
TableData(
columns=[],
rows=[[1]],
),
TableData(
columns=[],
rows=[["a"]],
),
TableData(
columns=[],
rows=[
[b"\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"]
],
),
],
)
def test_table_data_serialization(parameter):
for row in parameter.rows:
for i, cell in enumerate(row):
if isinstance(cell, bytes):
# bytes are written as strings and deserialize as strings
row[i] = cell.decode("utf-8")
assert TableData.model_validate_json(parameter.model_dump_json()) == parameter
@pytest.mark.parametrize(
"parameter",
[
xfail_param(
TableData(
columns=[],
rows=[
[
b"\xe6\x10\x00\x00\x01\x0c\xae\x8b\xfc(\xbc\xe4G@g\xa8\x91\x89\x89\x8a^\xc0"
]
],
),
reason="TODO: change TableData.rows to List[List[str]]",
),
],
)
def test_unserializble(parameter):
parameter = TableData.model_validate(parameter.model_dump())
assert TableData.model_validate_json(parameter.model_dump_json()) != parameter