2023-05-01 14:30:09 -04:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from freezegun import freeze_time
|
|
|
|
|
|
|
|
from datahub.ingestion.source.unity.config import UnityCatalogSourceConfig
|
|
|
|
|
|
|
|
FROZEN_TIME = datetime.fromisoformat("2023-01-01 00:00:00+00:00")
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time(FROZEN_TIME)
|
|
|
|
def test_within_thirty_days():
|
|
|
|
config = UnityCatalogSourceConfig.parse_obj(
|
|
|
|
{
|
|
|
|
"token": "token",
|
2023-05-08 22:43:53 +05:30
|
|
|
"workspace_url": "https://workspace_url",
|
2023-05-01 14:30:09 -04:00
|
|
|
"include_usage_statistics": True,
|
|
|
|
"start_time": FROZEN_TIME - timedelta(days=30),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
assert config.start_time == FROZEN_TIME - timedelta(days=30)
|
|
|
|
|
2023-05-08 22:43:53 +05:30
|
|
|
with pytest.raises(
|
|
|
|
ValueError, match="Query history is only maintained for 30 days."
|
|
|
|
):
|
2023-05-01 14:30:09 -04:00
|
|
|
UnityCatalogSourceConfig.parse_obj(
|
|
|
|
{
|
|
|
|
"token": "token",
|
2023-05-08 22:43:53 +05:30
|
|
|
"workspace_url": "https://workspace_url",
|
2023-05-01 14:30:09 -04:00
|
|
|
"include_usage_statistics": True,
|
|
|
|
"start_time": FROZEN_TIME - timedelta(days=31),
|
|
|
|
}
|
|
|
|
)
|
2023-05-08 22:43:53 +05:30
|
|
|
|
|
|
|
|
2023-05-11 13:00:50 -04:00
|
|
|
def test_profiling_requires_warehouses_id():
|
|
|
|
config = UnityCatalogSourceConfig.parse_obj(
|
|
|
|
{
|
|
|
|
"token": "token",
|
|
|
|
"workspace_url": "https://workspace_url",
|
|
|
|
"profiling": {"enabled": True, "warehouse_id": "my_warehouse_id"},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
assert config.profiling.enabled is True
|
|
|
|
|
|
|
|
config = UnityCatalogSourceConfig.parse_obj(
|
|
|
|
{
|
|
|
|
"token": "token",
|
|
|
|
"workspace_url": "https://workspace_url",
|
|
|
|
"profiling": {"enabled": False},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
assert config.profiling.enabled is False
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
UnityCatalogSourceConfig.parse_obj(
|
|
|
|
{
|
|
|
|
"token": "token",
|
|
|
|
"workspace_url": "workspace_url",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-05-08 22:43:53 +05:30
|
|
|
@freeze_time(FROZEN_TIME)
|
|
|
|
def test_workspace_url_should_start_with_https():
|
|
|
|
|
|
|
|
with pytest.raises(ValueError, match="Workspace URL must start with http scheme"):
|
|
|
|
UnityCatalogSourceConfig.parse_obj(
|
|
|
|
{
|
|
|
|
"token": "token",
|
|
|
|
"workspace_url": "workspace_url",
|
2023-05-11 13:00:50 -04:00
|
|
|
"profiling": {"enabled": True},
|
2023-05-08 22:43:53 +05:30
|
|
|
}
|
|
|
|
)
|