403Webshell
Server IP : 3.147.158.171  /  Your IP : 216.73.216.88
Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5
System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.21
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /tsai/repo/api/tests/unit/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /tsai/repo/api/tests/unit/test_select_characters.py
"""Unit tests for calendar-only character selection.

After removing probability-based posting, DrupalService.selectCharacters
selects a character only when it has the relevant calendar schedule and that
schedule matches the current day/hour. Characters with no schedule never post.
"""

from datetime import datetime

from app.appTypes import Character, ContentSchedule
from app.services.drupal import DrupalService


def _today_js_weekday() -> int:
    """JS convention: Sunday=0..Saturday=6."""
    return (datetime.now().weekday() + 1) % 7


def _character(name: str, **overrides) -> Character:
    base = dict(
        name=name,
        email=f"{name.lower()}@example.test",
        description="test character",
        enabled=True,
        date="2026-01-01",
    )
    base.update(overrides)
    return Character(**base)


def test_no_schedule_is_never_selected():
    svc = DrupalService()
    char = _character("NoSchedule")
    assert svc.selectCharacters([char], field="articlesPerDay") == []


def test_matching_article_schedule_is_selected():
    svc = DrupalService()
    schedule = ContentSchedule(
        daysOfWeek=[_today_js_weekday()],
        preferredHours=[datetime.now().hour],
    )
    char = _character("Matches", articleSchedule=schedule)
    selected = svc.selectCharacters([char], field="articlesPerDay")
    assert [c.name for c in selected] == ["Matches"]


def test_non_matching_day_is_not_selected():
    svc = DrupalService()
    # A day-of-week that is guaranteed not to be today.
    other_day = (_today_js_weekday() + 1) % 7
    schedule = ContentSchedule(daysOfWeek=[other_day])
    char = _character("WrongDay", articleSchedule=schedule)
    assert svc.selectCharacters([char], field="articlesPerDay") == []


def test_article_field_uses_article_schedule_not_comment():
    svc = DrupalService()
    # Character has a matching comment schedule but no article schedule;
    # selecting for articles should skip it.
    schedule = ContentSchedule(daysOfWeek=[_today_js_weekday()])
    char = _character("CommentOnly", commentSchedule=schedule)
    assert svc.selectCharacters([char], field="articlesPerDay") == []
    assert [c.name for c in svc.selectCharacters([char], field="commentsPerDay")] == ["CommentOnly"]

Youez - 2016 - github.com/yon3zu
LinuXploit