# -*- coding: utf-8 -*- from app.yt_assign_db import ( group_eligible_for_time_slot, group_is_time_slot, group_time_slot_armed, normalize_assign_category, ) def test_normalize_assign_category(): assert normalize_assign_category("normal") == "normal" assert normalize_assign_category("普通") == "normal" assert normalize_assign_category("") == "normal" assert normalize_assign_category(None) == "normal" assert normalize_assign_category("time_slot") == "time_slot" assert normalize_assign_category("时间段") == "time_slot" assert normalize_assign_category("timeslot") == "time_slot" assert normalize_assign_category("weird") == "normal" def test_group_is_time_slot(): assert group_is_time_slot({"category": "time_slot"}) is True assert group_is_time_slot({"category": "normal"}) is False assert group_is_time_slot({"category": "普通"}) is False assert group_is_time_slot({}) is False assert group_is_time_slot(None) is False def test_group_time_slot_armed_default_true(): assert group_time_slot_armed({}) is True assert group_time_slot_armed({"time_slot_armed": 1}) is True assert group_time_slot_armed({"time_slot_armed": 0}) is False assert group_time_slot_armed({"time_slot_armed": False}) is False assert group_time_slot_armed({"time_slot_armed": "false"}) is False def test_group_eligible_for_time_slot(): base = { "enabled": True, "category": "time_slot", "has_stream_key": True, "time_slot_armed": True, } assert group_eligible_for_time_slot(base) is True assert group_eligible_for_time_slot({**base, "time_slot_armed": False}) is False assert group_eligible_for_time_slot({**base, "has_stream_key": False}) is False assert group_eligible_for_time_slot({**base, "category": "normal"}) is False assert group_eligible_for_time_slot({**base, "enabled": False}) is False