Skip to content

Commit

Permalink
feature: add test engine driver pytest case
Browse files Browse the repository at this point in the history
  • Loading branch information
DuanKuanJun committed Feb 1, 2025
1 parent 541268e commit cf18e18
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
16 changes: 15 additions & 1 deletion superset/db_engine_specs/TDengine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# TDengine driver for Apache SuperSet
from superset.db_engine_specs.base import BaseEngineSpec
from urllib import parse

class TDengineEngineSpec(BaseEngineSpec):
engine = "taosws"
Expand All @@ -16,4 +17,17 @@ class TDengineEngineSpec(BaseEngineSpec):
"PT1H": "TIMETRUNCATE({col}, 1h, 0)",
"P1D": "TIMETRUNCATE({col}, 1d, 0)",
"P1W": "TIMETRUNCATE({col}, 1w, 0)",
}
}

@classmethod
def get_schema_from_engine_params(
cls,
sqlalchemy_uri: URL,
connect_args: dict[str, Any],
) -> Optional[str]:
"""
Return the configured schema.
A TDengine database is a SQLAlchemy schema.
"""
return parse.unquote(sqlalchemy_uri.database)
51 changes: 51 additions & 0 deletions tests/unit_tests/db_engine_specs/test_TDengine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from datetime import datetime
from decimal import Decimal
from typing import Any, Optional
from unittest.mock import Mock, patch

import pytest
from sqlalchemy import types
from sqlalchemy.engine.url import make_url, URL # noqa: F401
from tests.unit_tests.db_engine_specs.utils import assert_convert_dttm

# test dttm
def test_convert_dttm(
target_type: str,
expected_result: Optional[str],
dttm: datetime, # noqa: F811
) -> None:
from superset.db_engine_specs.rockset import RocksetEngineSpec as spec # noqa: N813

assert_convert_dttm(spec, target_type, expected_result, dttm)


# test get schema
def test_get_schema_from_engine_params() -> None:
"""
Test the ``get_schema_from_engine_params`` method.
"""
from superset.db_engine_specs.TDengine import TDengineEngineSpec

assert (
TDengineEngineSpec.get_schema_from_engine_params(
make_url("taosws://user:password@host:port/dbname"), {}
)
== "dbname"
)

0 comments on commit cf18e18

Please sign in to comment.