1
0

Store posting results to a mongodb

This commit is contained in:
2026-03-30 12:23:13 +02:00
parent d800d9b7be
commit fb19145e8c
13 changed files with 331 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ import pytest
from content_automation.adapters.storage.base import StorageAdapterBase
from content_automation.controller import PublishController
from content_automation.models import PublishedContentRecord
from content_automation.settings import AppSettings
@@ -29,6 +30,23 @@ class FakeAdapter:
return f"{self.name}-post-id"
class FakeAdapterWithResponsePayload:
def __init__(self, payload: object) -> None:
self.name = "adapter-with-payload"
self._payload = payload
def post_media(self, media_url: str, caption: str) -> object:
return self._payload
class FakePublishedContentStore:
def __init__(self) -> None:
self.records: list[PublishedContentRecord] = []
def save(self, record: PublishedContentRecord) -> None:
self.records.append(record)
def test_controller_publishes_to_all_configured_networks() -> None:
settings = AppSettings.model_validate(
{"target_social_networks": ["instagram", "youtube"]}
@@ -47,6 +65,47 @@ def test_controller_publishes_to_all_configured_networks() -> None:
assert result == {"instagram": "instagram-post-id", "youtube": "youtube-post-id"}
def test_controller_stores_published_content_with_youtube_id_only() -> None:
settings = AppSettings.model_validate(
{"target_social_networks": ["instagram", "youtube"]}
)
published_content_store = FakePublishedContentStore()
controller = PublishController(
settings=settings,
storage=FakeStorage(exists_result=True),
social_adapters={
"instagram": FakeAdapterWithResponsePayload(
{"id": "ig-123", "status": "ok"}
),
"youtube": FakeAdapterWithResponsePayload(
{
"id": "yt-456",
"kind": "youtube#video",
"snippet": {"title": "hello"},
}
),
},
published_content_store=published_content_store,
)
result = controller.publish(relative_path="video.mp4", caption="hello")
assert result["youtube"] == {
"id": "yt-456",
"kind": "youtube#video",
"snippet": {"title": "hello"},
}
assert len(published_content_store.records) == 1
saved_record = published_content_store.records[0]
assert saved_record.relative_path == "video.mp4"
assert saved_record.caption == "hello"
assert saved_record.platform_responses["instagram"] == {
"id": "ig-123",
"status": "ok",
}
assert saved_record.platform_responses["youtube"] == "yt-456"
def test_controller_raises_when_file_missing() -> None:
settings = AppSettings.model_validate({"target_social_networks": ["youtube"]})
controller = PublishController(