# -*- coding: utf-8 -*-
"""filter_verify_tables 单元测试"""

import pytest
from tasks.verification.models import filter_verify_tables


class TestFilterVerifyTables:
    """按层过滤校验表名"""

    def test_none_input_returns_none(self):
        assert filter_verify_tables("DWD", None) is None

    def test_empty_list_returns_none(self):
        assert filter_verify_tables("DWD", []) is None

    def test_dwd_layer_filters_correctly(self):
        tables = ["dwd_order", "dim_member", "fact_payment", "ods_raw", "dws_daily"]
        result = filter_verify_tables("DWD", tables)
        assert result == ["dwd_order", "dim_member", "fact_payment"]

    def test_dws_layer_filters_correctly(self):
        tables = ["dws_daily", "dwd_order", "dws_summary"]
        result = filter_verify_tables("DWS", tables)
        assert result == ["dws_daily", "dws_summary"]

    def test_index_layer_filters_correctly(self):
        tables = ["v_score", "wbi_index", "dws_daily", "v_rank"]
        result = filter_verify_tables("INDEX", tables)
        assert result == ["v_score", "wbi_index", "v_rank"]

    def test_ods_layer_filters_correctly(self):
        tables = ["ods_order", "dwd_order", "ods_member"]
        result = filter_verify_tables("ODS", tables)
        assert result == ["ods_order", "ods_member"]

    def test_unknown_layer_returns_normalized(self):
        tables = ["  SomeTable  ", "Another"]
        result = filter_verify_tables("UNKNOWN", tables)
        assert result == ["sometable", "another"]

    def test_layer_case_insensitive(self):
        tables = ["dwd_order", "ods_raw"]
        assert filter_verify_tables("dwd", tables) == ["dwd_order"]
        assert filter_verify_tables("Dwd", tables) == ["dwd_order"]

    def test_whitespace_and_empty_entries_stripped(self):
        tables = ["  dwd_order  ", "", "  ", None, "dim_member"]
        result = filter_verify_tables("DWD", tables)
        assert result == ["dwd_order", "dim_member"]
