forked from LiveCarta/ContentAutomation
Implemented content upload app with tests and pre-commit hooks
This commit is contained in:
59
tests/test_controller.py
Normal file
59
tests/test_controller.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from content_automation.adapters.storage.base import StorageAdapterBase
|
||||
from content_automation.controller import PublishController
|
||||
from content_automation.settings import AppSettings
|
||||
|
||||
|
||||
class FakeStorage(StorageAdapterBase):
|
||||
def __init__(
|
||||
self, exists_result: bool, public_url: str = "file:///tmp/video.mp4"
|
||||
) -> None:
|
||||
self._exists_result = exists_result
|
||||
self._public_url = public_url
|
||||
|
||||
def exists(self, relative_path: str) -> bool:
|
||||
return self._exists_result
|
||||
|
||||
def get_public_url(self, relative_path: str) -> str:
|
||||
return self._public_url
|
||||
|
||||
|
||||
class FakeAdapter:
|
||||
def __init__(self, adapter_name: str) -> None:
|
||||
self.name = adapter_name
|
||||
|
||||
def post_media(self, media_url: str, caption: str) -> str:
|
||||
return f"{self.name}-post-id"
|
||||
|
||||
|
||||
def test_controller_publishes_to_all_configured_networks() -> None:
|
||||
settings = AppSettings.model_validate(
|
||||
{"target_social_networks": ["instagram", "youtube"]}
|
||||
)
|
||||
controller = PublishController(
|
||||
settings=settings,
|
||||
storage=FakeStorage(exists_result=True),
|
||||
social_adapters={
|
||||
"instagram": FakeAdapter("instagram"),
|
||||
"youtube": FakeAdapter("youtube"),
|
||||
},
|
||||
)
|
||||
|
||||
result = controller.publish(relative_path="video.mp4", caption="hello")
|
||||
|
||||
assert result == {"instagram": "instagram-post-id", "youtube": "youtube-post-id"}
|
||||
|
||||
|
||||
def test_controller_raises_when_file_missing() -> None:
|
||||
settings = AppSettings.model_validate({"target_social_networks": ["youtube"]})
|
||||
controller = PublishController(
|
||||
settings=settings,
|
||||
storage=FakeStorage(exists_result=False),
|
||||
social_adapters={"youtube": FakeAdapter("youtube")},
|
||||
)
|
||||
|
||||
with pytest.raises(FileNotFoundError):
|
||||
controller.publish(relative_path="video.mp4", caption="hello")
|
||||
Reference in New Issue
Block a user