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

65 lines
2.1 KiB
Python

import sys
import pytest
from metadata.generated.schema.entity.services.databaseService import DatabaseService
from metadata.generated.schema.metadataIngestion.databaseServiceQueryUsagePipeline import (
DatabaseUsageConfigType,
)
from metadata.ingestion.lineage.sql_lineage import search_cache
from metadata.workflow.metadata import MetadataWorkflow
from metadata.workflow.usage import UsageWorkflow
if not sys.version_info >= (3, 9):
pytest.skip("requires python 3.9+", allow_module_level=True)
@pytest.fixture()
def usage_config(sink_config, workflow_config, db_service):
return {
"source": {
"type": "postgres-usage",
"serviceName": db_service.fullyQualifiedName.root,
"sourceConfig": {
"config": {"type": DatabaseUsageConfigType.DatabaseUsage.value}
},
},
"processor": {"type": "query-parser", "config": {}},
"stage": {
"type": "table-usage",
"config": {
"filename": "/tmp/postgres_usage",
},
},
"bulkSink": {
"type": "metadata-usage",
"config": {
"filename": "/tmp/postgres_usage",
},
},
"sink": sink_config,
"workflowConfig": workflow_config,
}
def test_usage(run_workflow, ingestion_config, usage_config, metadata, db_service):
search_cache.clear()
run_workflow(MetadataWorkflow, ingestion_config)
run_workflow(UsageWorkflow, usage_config)
@pytest.mark.xfail(
reason="'metadata.ingestion.lineage.sql_lineage.search_cache' gets corrupted with invalid data."
" See issue https://github.com/open-metadata/OpenMetadata/issues/16408",
strict=True,
)
def test_usage_delete_usage(
run_workflow, ingestion_config, usage_config, metadata, db_service
):
search_cache.clear()
run_workflow(MetadataWorkflow, ingestion_config)
run_workflow(UsageWorkflow, usage_config)
metadata.delete(DatabaseService, db_service.id, hard_delete=True, recursive=True)
run_workflow(MetadataWorkflow, ingestion_config)
run_workflow(UsageWorkflow, usage_config)