Files
gyxx-flow/tests/test_content_marketing_module.py
T

77 lines
2.7 KiB
Python

from __future__ import annotations
from pathlib import Path
from gyxx_flow.adapters.native import DeferredModuleCommandStep
from gyxx_flow.catalog import WorkflowCatalog
from gyxx_flow.modules.content_marketing import (
CONTENT_COMMENT_TIMEOUT_SECONDS,
CONTENT_RESOURCE,
CONTENT_SCHEDULED_WORKFLOW_IDS,
CONTENT_TIMEOUT_SECONDS,
CONTENT_WORKFLOW_IDS,
ContentMarketingModule,
)
PROJECT_ROOT = Path(__file__).resolve().parents[1]
def test_content_module_registers_only_scheduled_entries() -> None:
module = ContentMarketingModule.from_catalog(
WorkflowCatalog.load(PROJECT_ROOT / "config")
)
definitions = module.workflow_definitions()
assert tuple(item.workflow_id for item in definitions) == CONTENT_WORKFLOW_IDS
assert len(CONTENT_SCHEDULED_WORKFLOW_IDS) == 9
def test_content_workflows_use_project_owned_module_commands() -> None:
module = ContentMarketingModule.from_catalog(
WorkflowCatalog.load(PROJECT_ROOT / "config")
)
for definition in module.workflow_definitions():
assert definition.steps
for step in definition.steps:
assert isinstance(step.action, DeferredModuleCommandStep)
expected_timeout = (
CONTENT_COMMENT_TIMEOUT_SECONDS
if definition.workflow_id == "content.comments.weekly"
else CONTENT_TIMEOUT_SECONDS
)
assert step.timeout_seconds == expected_timeout
assert CONTENT_TIMEOUT_SECONDS == 4 * 60 * 60
assert CONTENT_COMMENT_TIMEOUT_SECONDS == 6 * 60 * 60
assert step.max_attempts == 1
if definition.workflow_id == "content.comments.weekly":
assert step.resources == (f"{CONTENT_RESOURCE}:{step.step_id}",)
elif definition.workflow_id == "content.metrics.daily":
assert step.resources == (
f"{CONTENT_RESOURCE}:content.metrics.daily:{step.step_id}",
)
else:
assert step.resources == (CONTENT_RESOURCE,) == (
"module:content_marketing",
)
assert step.production_sink is True
def test_daily_content_steps_have_independent_resources() -> None:
module = ContentMarketingModule.from_catalog(
WorkflowCatalog.load(PROJECT_ROOT / "config")
)
daily = next(
item for item in module.workflow_definitions()
if item.workflow_id == "content.metrics.daily"
)
assert {step.step_id for step in daily.steps} == {
"collect_collaborators",
"refresh_self_mapping",
"collect_self_bilibili",
"collect_self_douyin",
"sync",
}
assert len({step.resources for step in daily.steps}) == len(daily.steps)