Skip to content

Commit

Permalink
rewrite the unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mapledan committed Nov 17, 2023
1 parent 7c7210f commit 2f05b7f
Showing 1 changed file with 19 additions and 47 deletions.
66 changes: 19 additions & 47 deletions tests/unit_tests/datasets/schema_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,31 @@
import pytest
from marshmallow import ValidationError

from superset.datasets.schemas import validate_python_date_format


# pylint: disable=too-few-public-methods
@pytest.mark.parametrize(
"payload",
[
(
{
"column_name": "insert_time",
"filterable": True,
"groupby": True,
"python_date_format": None,
}
),
(
{
"column_name": "insert_time",
"filterable": True,
"groupby": True,
"python_date_format": "epoch_ms",
}
),
(
{
"column_name": "insert_time",
"filterable": True,
"groupby": True,
"python_date_format": "epoch_s",
}
),
(
{
"column_name": "insert_time",
"filterable": True,
"groupby": True,
"python_date_format": "%Y/%m/%dT%H:%M:%S.%f",
}
),
(
{
"column_name": "insert_time",
"filterable": True,
"groupby": True,
"python_date_format": "%Y%m%d",
}
),
None,
"epoch_ms",
"epoch_s",
"%Y/%m/%dT%H:%M:%S.%f",
"%Y-%m-%dT%H:%M:%S.%f",
"%Y%m%d",
],
)
def test_datasets_schema_update_column_datetime_format(payload) -> None:
from superset.datasets.schemas import DatasetColumnsPutSchema
def test_validate_python_date_format(payload) -> None:
assert None == validate_python_date_format(payload)

schema = DatasetColumnsPutSchema()

try:
schema.load(payload)
except ValidationError as err:
assert False, err.messages
@pytest.mark.parametrize(
"payload",
[
"%d%m%Y",
],
)
def test_validate_python_date_format_raises(payload) -> None:
with pytest.raises(ValidationError):
validate_python_date_format(payload)

0 comments on commit 2f05b7f

Please sign in to comment.