diff --git a/app/services/platforms/__init__.py b/app/services/platforms/__init__.py index e69de29..a987cec 100644 --- a/app/services/platforms/__init__.py +++ b/app/services/platforms/__init__.py @@ -0,0 +1,28 @@ +from __future__ import annotations + +from app.services.platforms.base import PostingStrategy, PostResult +from app.services.platforms.reddit_post import RedditPostStrategy + +_REGISTRY: dict[str, PostingStrategy] = { + s.campaign_type: s() + for s in [ + RedditPostStrategy, + # RedditCommentStrategy — added in Plan B + # BlogPostStrategy — added in Plan C + ] +} + +SUPPORTED_PLATFORMS: frozenset[str] = frozenset(_REGISTRY) + + +def get_client(campaign_type: str) -> PostingStrategy: + """Return the strategy instance for the given campaign type. + + Raises ValueError for unknown types. + """ + if campaign_type not in _REGISTRY: + raise ValueError(f"Unknown campaign type: {campaign_type!r}") + return _REGISTRY[campaign_type] + + +__all__ = ["get_client", "SUPPORTED_PLATFORMS", "PostingStrategy", "PostResult"] diff --git a/tests/services/platforms/test_registry.py b/tests/services/platforms/test_registry.py new file mode 100644 index 0000000..5a877d6 --- /dev/null +++ b/tests/services/platforms/test_registry.py @@ -0,0 +1,17 @@ +import pytest +from app.services.platforms import get_client, SUPPORTED_PLATFORMS +from app.services.platforms.reddit_post import RedditPostStrategy + + +def test_get_client_returns_reddit_post_strategy(): + client = get_client("reddit_post") + assert isinstance(client, RedditPostStrategy) + + +def test_get_client_unknown_type_raises(): + with pytest.raises(ValueError, match="Unknown campaign type"): + get_client("nonexistent_type") + + +def test_supported_platforms_contains_reddit_post(): + assert "reddit_post" in SUPPORTED_PLATFORMS