Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions contentcuration/automation/tests/appnexus/test_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from automation.utils.appnexus.base import Adapter
from automation.utils.appnexus.base import Backend

Expand All @@ -19,6 +21,11 @@ def mockoperation(self):
pass


def test_backend_error():
with pytest.raises(NotImplementedError) as error:
Backend.get_instance()
assert "Subclasses should implement the creation of instance" in str(error.value)

def test_backend_singleton():
b1, b2 = MockBackend.get_instance(), MockBackend.get_instance()
assert id(b1) == id(b2)
Expand Down
44 changes: 44 additions & 0 deletions contentcuration/contentcuration/utils/transcription.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from automation.utils.appnexus.base import Adapter
from automation.utils.appnexus.base import Backend
from automation.utils.appnexus.base import BackendFactory
from automation.utils.appnexus.base import BackendRequest
from automation.utils.appnexus.base import BackendResponse


class WhisperRequest(BackendRequest):
def __init__(self) -> None:
super().__init__()

class WhisperResponse(BackendResponse):
def __init__(self) -> None:
super().__init__()


class Whisper(Backend):
def connect(self) -> None:
raise NotImplementedError("The 'connect' method is not implemented for the 'Whisper' backend.")

def make_request(self, request: WhisperRequest) -> WhisperResponse:
# Implement production backend here.
pass

@classmethod
def _create_instance(cls) -> 'Whisper':
return cls()

class LocalWhisper(Backend):
def make_request(self, request: WhisperRequest) -> WhisperResponse:
# Implement your local backend here.
pass


class WhisperBackendFactory(BackendFactory):
def create_backend(self) -> Backend:
# Return backend based on some setting.
return super().create_backend()


class WhisperAdapter(Adapter):
def transcribe(self, caption_file_id: str) -> WhisperResponse:
request = WhisperRequest()
return self.backend.make_request(request)