From c783bd6bd503795cbd98cb953c379d951128b9b8 Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Fri, 23 Aug 2024 15:44:20 +0300 Subject: [PATCH] removed deprecated AI providers, added test for TaskProcessing Signed-off-by: Alexander Piskun --- CHANGELOG.md | 6 + README.md | 29 ++- docs/reference/ExApp.rst | 18 -- nc_py_api/_version.py | 2 +- nc_py_api/ex_app/providers/providers.py | 21 --- nc_py_api/ex_app/providers/speech_to_text.py | 128 -------------- nc_py_api/ex_app/providers/text_processing.py | 135 -------------- nc_py_api/ex_app/providers/translations.py | 165 ------------------ .../actual_tests/speech2text_provider_test.py | 67 ------- .../taskprocessing_provider_test.py | 54 ++++++ .../text_processing_provider_test.py | 69 -------- .../actual_tests/translation_provider_test.py | 124 ------------- 12 files changed, 75 insertions(+), 743 deletions(-) delete mode 100644 nc_py_api/ex_app/providers/speech_to_text.py delete mode 100644 nc_py_api/ex_app/providers/text_processing.py delete mode 100644 nc_py_api/ex_app/providers/translations.py delete mode 100644 tests/actual_tests/speech2text_provider_test.py create mode 100644 tests/actual_tests/taskprocessing_provider_test.py delete mode 100644 tests/actual_tests/text_processing_provider_test.py delete mode 100644 tests/actual_tests/translation_provider_test.py diff --git a/CHANGELOG.md b/CHANGELOG.md index df308658..c8416b4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## [0.17.0 - 2024-0x-xx] + +### Changed + +- NextcloudApp: `TextProcessing`, `Speech2Text` and `Translation` AI Providers API was removed. + ## [0.16.0 - 2024-08-12] ### Changed diff --git a/README.md b/README.md index 6193dc47..1ecc7ca6 100644 --- a/README.md +++ b/README.md @@ -24,23 +24,22 @@ Python library that provides a robust and well-documented API that allows develo * **Sync + Async**: Provides both sync and async APIs. ### Capabilities -| **_Capability_** | Nextcloud 27 | Nextcloud 28 | Nextcloud 29 | Nextcloud 30 | -|-----------------------|:------------:|:------------:|:------------:|:------------:| -| Calendar | ✅ | ✅ | ✅ | ✅ | -| File System & Tags | ✅ | ✅ | ✅ | ✅ | -| Nextcloud Talk | ✅ | ✅ | ✅ | ✅ | -| Notifications | ✅ | ✅ | ✅ | ✅ | -| Shares | ✅ | ✅ | ✅ | ✅ | -| Users & Groups | ✅ | ✅ | ✅ | ✅ | -| User & Weather status | ✅ | ✅ | ✅ | ✅ | -| Other APIs*** | ✅ | ✅ | ✅ | ✅ | -| Talk Bot API* | ✅ | ✅ | ✅ | ✅ | -| Settings UI API* | N/A | N/A | ✅ | ✅ | -| AI Providers API** | N/A | N/A | ✅ | ✅ | +| **_Capability_** | Nextcloud 27 | Nextcloud 28 | Nextcloud 29 | Nextcloud 30 | +|------------------------------|:------------:|:------------:|:------------:|:------------:| +| Calendar | ✅ | ✅ | ✅ | ✅ | +| File System & Tags | ✅ | ✅ | ✅ | ✅ | +| Nextcloud Talk | ✅ | ✅ | ✅ | ✅ | +| Notifications | ✅ | ✅ | ✅ | ✅ | +| Shares | ✅ | ✅ | ✅ | ✅ | +| Users & Groups | ✅ | ✅ | ✅ | ✅ | +| User & Weather status | ✅ | ✅ | ✅ | ✅ | +| Other APIs** | ✅ | ✅ | ✅ | ✅ | +| Talk Bot API* | ✅ | ✅ | ✅ | ✅ | +| Settings UI API* | N/A | N/A | ✅ | ✅ | +| TaskProcessing Provider API* | N/A | N/A | N/A | ✅ | *_available only for **NextcloudApp**_
-**_available only for **NextcloudApp**: SpeechToText, TextProcessing, Translation_
-***_Activity, Notes_ +**_Activity, Notes_ ### Differences between the Nextcloud and NextcloudApp classes diff --git a/docs/reference/ExApp.rst b/docs/reference/ExApp.rst index 8d737f55..f3c08f2b 100644 --- a/docs/reference/ExApp.rst +++ b/docs/reference/ExApp.rst @@ -69,24 +69,6 @@ UI methods should be accessed with the help of :class:`~nc_py_api.nextcloud.Next .. autoclass:: nc_py_api.ex_app.providers.providers.ProvidersApi :members: -.. autoclass:: nc_py_api.ex_app.providers.speech_to_text.SpeechToTextProvider - :members: - -.. autoclass:: nc_py_api.ex_app.providers.speech_to_text._SpeechToTextProviderAPI - :members: - -.. autoclass:: nc_py_api.ex_app.providers.text_processing.TextProcessingProvider - :members: - -.. autoclass:: nc_py_api.ex_app.providers.text_processing._TextProcessingProviderAPI - :members: - -.. autoclass:: nc_py_api.ex_app.providers.translations.TranslationsProvider - :members: - -.. autoclass:: nc_py_api.ex_app.providers.translations._TranslationsProviderAPI - :members: - .. autoclass:: nc_py_api.ex_app.providers.task_processing.ShapeType :members: diff --git a/nc_py_api/_version.py b/nc_py_api/_version.py index bb25be8e..f262b71d 100644 --- a/nc_py_api/_version.py +++ b/nc_py_api/_version.py @@ -1,3 +1,3 @@ """Version of nc_py_api.""" -__version__ = "0.16.0" +__version__ = "0.17.0.dev0" diff --git a/nc_py_api/ex_app/providers/providers.py b/nc_py_api/ex_app/providers/providers.py index 6240af33..ce22976c 100644 --- a/nc_py_api/ex_app/providers/providers.py +++ b/nc_py_api/ex_app/providers/providers.py @@ -1,45 +1,24 @@ """Nextcloud API for AI Providers.""" from ..._session import AsyncNcSessionApp, NcSessionApp -from .speech_to_text import _AsyncSpeechToTextProviderAPI, _SpeechToTextProviderAPI from .task_processing import _AsyncTaskProcessingProviderAPI, _TaskProcessingProviderAPI -from .text_processing import _AsyncTextProcessingProviderAPI, _TextProcessingProviderAPI -from .translations import _AsyncTranslationsProviderAPI, _TranslationsProviderAPI class ProvidersApi: """Class that encapsulates all AI Providers functionality.""" - speech_to_text: _SpeechToTextProviderAPI - """SpeechToText Provider API.""" - text_processing: _TextProcessingProviderAPI - """TextProcessing Provider API.""" - translations: _TranslationsProviderAPI - """Translations Provider API.""" task_processing: _TaskProcessingProviderAPI """TaskProcessing Provider API.""" def __init__(self, session: NcSessionApp): - self.speech_to_text = _SpeechToTextProviderAPI(session) - self.text_processing = _TextProcessingProviderAPI(session) - self.translations = _TranslationsProviderAPI(session) self.task_processing = _TaskProcessingProviderAPI(session) class AsyncProvidersApi: """Class that encapsulates all AI Providers functionality.""" - speech_to_text: _AsyncSpeechToTextProviderAPI - """SpeechToText Provider API.""" - text_processing: _AsyncTextProcessingProviderAPI - """TextProcessing Provider API.""" - translations: _AsyncTranslationsProviderAPI - """Translations Provider API.""" task_processing: _AsyncTaskProcessingProviderAPI """TaskProcessing Provider API.""" def __init__(self, session: AsyncNcSessionApp): - self.speech_to_text = _AsyncSpeechToTextProviderAPI(session) - self.text_processing = _AsyncTextProcessingProviderAPI(session) - self.translations = _AsyncTranslationsProviderAPI(session) self.task_processing = _AsyncTaskProcessingProviderAPI(session) diff --git a/nc_py_api/ex_app/providers/speech_to_text.py b/nc_py_api/ex_app/providers/speech_to_text.py deleted file mode 100644 index 30f297c6..00000000 --- a/nc_py_api/ex_app/providers/speech_to_text.py +++ /dev/null @@ -1,128 +0,0 @@ -"""Nextcloud API for declaring SpeechToText provider.""" - -import contextlib -import dataclasses - -from ..._exceptions import NextcloudException, NextcloudExceptionNotFound -from ..._misc import require_capabilities -from ..._session import AsyncNcSessionApp, NcSessionApp - -_EP_SUFFIX: str = "ai_provider/speech_to_text" - - -@dataclasses.dataclass -class SpeechToTextProvider: - """Speech2Text provider description.""" - - def __init__(self, raw_data: dict): - self._raw_data = raw_data - - @property - def name(self) -> str: - """Unique ID for the provider.""" - return self._raw_data["name"] - - @property - def display_name(self) -> str: - """Providers display name.""" - return self._raw_data["display_name"] - - @property - def action_handler(self) -> str: - """Relative ExApp url which will be called by Nextcloud.""" - return self._raw_data["action_handler"] - - def __repr__(self): - return f"<{self.__class__.__name__} name={self.name}, handler={self.action_handler}>" - - -class _SpeechToTextProviderAPI: - """API for Speech2Text providers, avalaible as **nc.providers.text_processing.**.""" - - def __init__(self, session: NcSessionApp): - self._session = session - - def register(self, name: str, display_name: str, callback_url: str) -> None: - """Registers or edit the SpeechToText provider.""" - require_capabilities("app_api", self._session.capabilities) - params = { - "name": name, - "displayName": display_name, - "actionHandler": callback_url, - } - self._session.ocs("POST", f"{self._session.ae_url}/{_EP_SUFFIX}", json=params) - - def unregister(self, name: str, not_fail=True) -> None: - """Removes SpeechToText provider.""" - require_capabilities("app_api", self._session.capabilities) - try: - self._session.ocs("DELETE", f"{self._session.ae_url}/{_EP_SUFFIX}", params={"name": name}) - except NextcloudExceptionNotFound as e: - if not not_fail: - raise e from None - - def get_entry(self, name: str) -> SpeechToTextProvider | None: - """Get information of the SpeechToText.""" - require_capabilities("app_api", self._session.capabilities) - try: - return SpeechToTextProvider( - self._session.ocs("GET", f"{self._session.ae_url}/{_EP_SUFFIX}", params={"name": name}) - ) - except NextcloudExceptionNotFound: - return None - - def report_result(self, task_id: int, result: str = "", error: str = "") -> None: - """Report results of speech to text task to Nextcloud.""" - require_capabilities("app_api", self._session.capabilities) - with contextlib.suppress(NextcloudException): - self._session.ocs( - "PUT", - f"{self._session.ae_url}/{_EP_SUFFIX}", - json={"taskId": task_id, "result": result, "error": error}, - ) - - -class _AsyncSpeechToTextProviderAPI: - """Async API for Speech2Text providers.""" - - def __init__(self, session: AsyncNcSessionApp): - self._session = session - - async def register(self, name: str, display_name: str, callback_url: str) -> None: - """Registers or edit the SpeechToText provider.""" - require_capabilities("app_api", await self._session.capabilities) - params = { - "name": name, - "displayName": display_name, - "actionHandler": callback_url, - } - await self._session.ocs("POST", f"{self._session.ae_url}/{_EP_SUFFIX}", json=params) - - async def unregister(self, name: str, not_fail=True) -> None: - """Removes SpeechToText provider.""" - require_capabilities("app_api", await self._session.capabilities) - try: - await self._session.ocs("DELETE", f"{self._session.ae_url}/{_EP_SUFFIX}", params={"name": name}) - except NextcloudExceptionNotFound as e: - if not not_fail: - raise e from None - - async def get_entry(self, name: str) -> SpeechToTextProvider | None: - """Get information of the SpeechToText.""" - require_capabilities("app_api", await self._session.capabilities) - try: - return SpeechToTextProvider( - await self._session.ocs("GET", f"{self._session.ae_url}/{_EP_SUFFIX}", params={"name": name}) - ) - except NextcloudExceptionNotFound: - return None - - async def report_result(self, task_id: int, result: str = "", error: str = "") -> None: - """Report results of speech to text task to Nextcloud.""" - require_capabilities("app_api", await self._session.capabilities) - with contextlib.suppress(NextcloudException): - await self._session.ocs( - "PUT", - f"{self._session.ae_url}/{_EP_SUFFIX}", - json={"taskId": task_id, "result": result, "error": error}, - ) diff --git a/nc_py_api/ex_app/providers/text_processing.py b/nc_py_api/ex_app/providers/text_processing.py deleted file mode 100644 index 095bf1fe..00000000 --- a/nc_py_api/ex_app/providers/text_processing.py +++ /dev/null @@ -1,135 +0,0 @@ -"""Nextcloud API for declaring TextProcessing provider.""" - -import contextlib -import dataclasses - -from ..._exceptions import NextcloudException, NextcloudExceptionNotFound -from ..._misc import require_capabilities -from ..._session import AsyncNcSessionApp, NcSessionApp - -_EP_SUFFIX: str = "ai_provider/text_processing" - - -@dataclasses.dataclass -class TextProcessingProvider: - """TextProcessing provider description.""" - - def __init__(self, raw_data: dict): - self._raw_data = raw_data - - @property - def name(self) -> str: - """Unique ID for the provider.""" - return self._raw_data["name"] - - @property - def display_name(self) -> str: - """Providers display name.""" - return self._raw_data["display_name"] - - @property - def action_handler(self) -> str: - """Relative ExApp url which will be called by Nextcloud.""" - return self._raw_data["action_handler"] - - @property - def task_type(self) -> str: - """The TaskType provided by this provider.""" - return self._raw_data["task_type"] - - def __repr__(self): - return f"<{self.__class__.__name__} name={self.name}, type={self.task_type}, handler={self.action_handler}>" - - -class _TextProcessingProviderAPI: - """API for TextProcessing providers, avalaible as **nc.providers.speech_to_text.**.""" - - def __init__(self, session: NcSessionApp): - self._session = session - - def register(self, name: str, display_name: str, callback_url: str, task_type: str) -> None: - """Registers or edit the TextProcessing provider.""" - require_capabilities("app_api", self._session.capabilities) - params = { - "name": name, - "displayName": display_name, - "actionHandler": callback_url, - "taskType": task_type, - } - self._session.ocs("POST", f"{self._session.ae_url}/{_EP_SUFFIX}", json=params) - - def unregister(self, name: str, not_fail=True) -> None: - """Removes TextProcessing provider.""" - require_capabilities("app_api", self._session.capabilities) - try: - self._session.ocs("DELETE", f"{self._session.ae_url}/{_EP_SUFFIX}", params={"name": name}) - except NextcloudExceptionNotFound as e: - if not not_fail: - raise e from None - - def get_entry(self, name: str) -> TextProcessingProvider | None: - """Get information of the TextProcessing.""" - require_capabilities("app_api", self._session.capabilities) - try: - return TextProcessingProvider( - self._session.ocs("GET", f"{self._session.ae_url}/{_EP_SUFFIX}", params={"name": name}) - ) - except NextcloudExceptionNotFound: - return None - - def report_result(self, task_id: int, result: str = "", error: str = "") -> None: - """Report results of the text processing to Nextcloud.""" - require_capabilities("app_api", self._session.capabilities) - with contextlib.suppress(NextcloudException): - self._session.ocs( - "PUT", - f"{self._session.ae_url}/{_EP_SUFFIX}", - json={"taskId": task_id, "result": result, "error": error}, - ) - - -class _AsyncTextProcessingProviderAPI: - """Async API for TextProcessing providers.""" - - def __init__(self, session: AsyncNcSessionApp): - self._session = session - - async def register(self, name: str, display_name: str, callback_url: str, task_type: str) -> None: - """Registers or edit the TextProcessing provider.""" - require_capabilities("app_api", await self._session.capabilities) - params = { - "name": name, - "displayName": display_name, - "actionHandler": callback_url, - "taskType": task_type, - } - await self._session.ocs("POST", f"{self._session.ae_url}/{_EP_SUFFIX}", json=params) - - async def unregister(self, name: str, not_fail=True) -> None: - """Removes TextProcessing provider.""" - require_capabilities("app_api", await self._session.capabilities) - try: - await self._session.ocs("DELETE", f"{self._session.ae_url}/{_EP_SUFFIX}", params={"name": name}) - except NextcloudExceptionNotFound as e: - if not not_fail: - raise e from None - - async def get_entry(self, name: str) -> TextProcessingProvider | None: - """Get information of the TextProcessing.""" - require_capabilities("app_api", await self._session.capabilities) - try: - return TextProcessingProvider( - await self._session.ocs("GET", f"{self._session.ae_url}/{_EP_SUFFIX}", params={"name": name}) - ) - except NextcloudExceptionNotFound: - return None - - async def report_result(self, task_id: int, result: str = "", error: str = "") -> None: - """Report results of the text processing to Nextcloud.""" - require_capabilities("app_api", await self._session.capabilities) - with contextlib.suppress(NextcloudException): - await self._session.ocs( - "PUT", - f"{self._session.ae_url}/{_EP_SUFFIX}", - json={"taskId": task_id, "result": result, "error": error}, - ) diff --git a/nc_py_api/ex_app/providers/translations.py b/nc_py_api/ex_app/providers/translations.py deleted file mode 100644 index 5b3b798f..00000000 --- a/nc_py_api/ex_app/providers/translations.py +++ /dev/null @@ -1,165 +0,0 @@ -"""Nextcloud API for declaring Translations provider.""" - -import contextlib -import dataclasses - -from ..._exceptions import NextcloudException, NextcloudExceptionNotFound -from ..._misc import require_capabilities -from ..._session import AsyncNcSessionApp, NcSessionApp - -_EP_SUFFIX: str = "ai_provider/translation" - - -@dataclasses.dataclass -class TranslationsProvider: - """Translations provider description.""" - - def __init__(self, raw_data: dict): - self._raw_data = raw_data - - @property - def name(self) -> str: - """Unique ID for the provider.""" - return self._raw_data["name"] - - @property - def display_name(self) -> str: - """Providers display name.""" - return self._raw_data["display_name"] - - @property - def from_languages(self) -> dict[str, str]: - """Input languages supported by provider.""" - return self._raw_data["from_languages"] - - @property - def to_languages(self) -> dict[str, str]: - """Output languages supported by provider.""" - return self._raw_data["to_languages"] - - @property - def action_handler(self) -> str: - """Relative ExApp url which will be called by Nextcloud.""" - return self._raw_data["action_handler"] - - @property - def action_handler_detect_lang(self) -> str: - """Relative ExApp url which will be called by Nextcloud to detect language.""" - return self._raw_data.get("action_detect_lang", "") - - def __repr__(self): - return f"<{self.__class__.__name__} name={self.name}, handler={self.action_handler}>" - - -class _TranslationsProviderAPI: - """API for Translations providers, avalaible as **nc.providers.translations.**.""" - - def __init__(self, session: NcSessionApp): - self._session = session - - def register( - self, - name: str, - display_name: str, - callback_url: str, - from_languages: dict[str, str], - to_languages: dict[str, str], - detect_lang_callback_url: str = "", - ) -> None: - """Registers or edit the Translations provider.""" - require_capabilities("app_api", self._session.capabilities) - params = { - "name": name, - "displayName": display_name, - "fromLanguages": from_languages, - "toLanguages": to_languages, - "actionHandler": callback_url, - "actionDetectLang": detect_lang_callback_url, - } - self._session.ocs("POST", f"{self._session.ae_url}/{_EP_SUFFIX}", json=params) - - def unregister(self, name: str, not_fail=True) -> None: - """Removes Translations provider.""" - require_capabilities("app_api", self._session.capabilities) - try: - self._session.ocs("DELETE", f"{self._session.ae_url}/{_EP_SUFFIX}", params={"name": name}) - except NextcloudExceptionNotFound as e: - if not not_fail: - raise e from None - - def get_entry(self, name: str) -> TranslationsProvider | None: - """Get information of the TranslationsProvider.""" - require_capabilities("app_api", self._session.capabilities) - try: - return TranslationsProvider( - self._session.ocs("GET", f"{self._session.ae_url}/{_EP_SUFFIX}", params={"name": name}) - ) - except NextcloudExceptionNotFound: - return None - - def report_result(self, task_id: int, result: str = "", error: str = "") -> None: - """Report results of translation task to Nextcloud.""" - require_capabilities("app_api", self._session.capabilities) - with contextlib.suppress(NextcloudException): - self._session.ocs( - "PUT", - f"{self._session.ae_url}/{_EP_SUFFIX}", - json={"taskId": task_id, "result": result, "error": error}, - ) - - -class _AsyncTranslationsProviderAPI: - """Async API for Translations providers.""" - - def __init__(self, session: AsyncNcSessionApp): - self._session = session - - async def register( - self, - name: str, - display_name: str, - callback_url: str, - from_languages: dict[str, str], - to_languages: dict[str, str], - detect_lang_callback_url: str = "", - ) -> None: - """Registers or edit the Translations provider.""" - require_capabilities("app_api", await self._session.capabilities) - params = { - "name": name, - "displayName": display_name, - "fromLanguages": from_languages, - "toLanguages": to_languages, - "actionHandler": callback_url, - "actionDetectLang": detect_lang_callback_url, - } - await self._session.ocs("POST", f"{self._session.ae_url}/{_EP_SUFFIX}", json=params) - - async def unregister(self, name: str, not_fail=True) -> None: - """Removes Translations provider.""" - require_capabilities("app_api", await self._session.capabilities) - try: - await self._session.ocs("DELETE", f"{self._session.ae_url}/{_EP_SUFFIX}", params={"name": name}) - except NextcloudExceptionNotFound as e: - if not not_fail: - raise e from None - - async def get_entry(self, name: str) -> TranslationsProvider | None: - """Get information of the TranslationsProvider.""" - require_capabilities("app_api", await self._session.capabilities) - try: - return TranslationsProvider( - await self._session.ocs("GET", f"{self._session.ae_url}/{_EP_SUFFIX}", params={"name": name}) - ) - except NextcloudExceptionNotFound: - return None - - async def report_result(self, task_id: int, result: str = "", error: str = "") -> None: - """Report results of translation task to Nextcloud.""" - require_capabilities("app_api", await self._session.capabilities) - with contextlib.suppress(NextcloudException): - await self._session.ocs( - "PUT", - f"{self._session.ae_url}/{_EP_SUFFIX}", - json={"taskId": task_id, "result": result, "error": error}, - ) diff --git a/tests/actual_tests/speech2text_provider_test.py b/tests/actual_tests/speech2text_provider_test.py deleted file mode 100644 index 46710d88..00000000 --- a/tests/actual_tests/speech2text_provider_test.py +++ /dev/null @@ -1,67 +0,0 @@ -import pytest - -from nc_py_api import NextcloudExceptionNotFound - - -@pytest.mark.require_nc(major=29) -def test_speech2text_provider(nc_app): - nc_app.providers.speech_to_text.register("test_id", "Test #1 Prov", "/some_url") - result = nc_app.providers.speech_to_text.get_entry("test_id") - assert result.name == "test_id" - assert result.display_name == "Test #1 Prov" - assert result.action_handler == "some_url" - nc_app.providers.speech_to_text.register("test_id2", "Test #2 Prov", "some_url2") - result2 = nc_app.providers.speech_to_text.get_entry("test_id2") - assert result2.name == "test_id2" - assert result2.display_name == "Test #2 Prov" - assert result2.action_handler == "some_url2" - nc_app.providers.speech_to_text.register("test_id", "Renamed", "/new_url") - result = nc_app.providers.speech_to_text.get_entry("test_id") - assert result.name == "test_id" - assert result.display_name == "Renamed" - assert result.action_handler == "new_url" - nc_app.providers.speech_to_text.unregister(result.name) - nc_app.providers.speech_to_text.unregister(result.name) - with pytest.raises(NextcloudExceptionNotFound): - nc_app.providers.speech_to_text.unregister(result.name, not_fail=False) - nc_app.providers.speech_to_text.unregister(result2.name, not_fail=False) - assert nc_app.providers.speech_to_text.get_entry(result2.name) is None - assert str(result).find("name=") != -1 - - -@pytest.mark.asyncio(scope="session") -@pytest.mark.require_nc(major=29) -async def test_speech2text_provider_async(anc_app): - await anc_app.providers.speech_to_text.register("test_id", "Test #1 Prov", "/some_url") - result = await anc_app.providers.speech_to_text.get_entry("test_id") - assert result.name == "test_id" - assert result.display_name == "Test #1 Prov" - assert result.action_handler == "some_url" - await anc_app.providers.speech_to_text.register("test_id2", "Test #2 Prov", "some_url2") - result2 = await anc_app.providers.speech_to_text.get_entry("test_id2") - assert result2.name == "test_id2" - assert result2.display_name == "Test #2 Prov" - assert result2.action_handler == "some_url2" - await anc_app.providers.speech_to_text.register("test_id", "Renamed", "/new_url") - result = await anc_app.providers.speech_to_text.get_entry("test_id") - assert result.name == "test_id" - assert result.display_name == "Renamed" - assert result.action_handler == "new_url" - await anc_app.providers.speech_to_text.unregister(result.name) - await anc_app.providers.speech_to_text.unregister(result.name) - with pytest.raises(NextcloudExceptionNotFound): - await anc_app.providers.speech_to_text.unregister(result.name, not_fail=False) - await anc_app.providers.speech_to_text.unregister(result2.name, not_fail=False) - assert await anc_app.providers.speech_to_text.get_entry(result2.name) is None - assert str(result).find("name=") != -1 - - -@pytest.mark.require_nc(major=29) -def test_speech2text_provider_fail_report(nc_app): - nc_app.providers.speech_to_text.report_result(999999) - - -@pytest.mark.asyncio(scope="session") -@pytest.mark.require_nc(major=29) -async def test_speech2text_provider_fail_report_async(anc_app): - await anc_app.providers.speech_to_text.report_result(999999) diff --git a/tests/actual_tests/taskprocessing_provider_test.py b/tests/actual_tests/taskprocessing_provider_test.py new file mode 100644 index 00000000..9bff5cb3 --- /dev/null +++ b/tests/actual_tests/taskprocessing_provider_test.py @@ -0,0 +1,54 @@ +import pytest + +from nc_py_api import NextcloudException, NextcloudExceptionNotFound +from nc_py_api.ex_app.providers.task_processing import TaskProcessingProvider + + +@pytest.mark.require_nc(major=30) +def test_task_processing_provider(nc_app): + provider_info = TaskProcessingProvider( + id=f"test_id", name=f"Test Display Name", task_type="core:text2image" # noqa + ) + nc_app.providers.task_processing.register(provider_info) + nc_app.providers.task_processing.unregister(provider_info.id) + with pytest.raises(NextcloudExceptionNotFound): + nc_app.providers.task_processing.unregister(provider_info.id, not_fail=False) + nc_app.providers.task_processing.unregister(provider_info.id) + nc_app.providers.task_processing.register(provider_info) + assert not nc_app.providers.task_processing.next_task(["test_id"], ["core:text2image"]) + assert not nc_app.providers.task_processing.set_progress(9999, 0.5) + assert not nc_app.providers.task_processing.report_result(9999, error_message="no such task") + with pytest.raises(NextcloudException): + nc_app.providers.task_processing.upload_result_file(9999, b"00") + nc_app.providers.task_processing.unregister(provider_info.id, not_fail=False) + + +@pytest.mark.asyncio(scope="session") +@pytest.mark.require_nc(major=30) +async def test_task_processing_async(anc_app): + provider_info = TaskProcessingProvider( + id=f"test_id", name=f"Test Display Name", task_type="core:text2image" # noqa + ) + await anc_app.providers.task_processing.register(provider_info) + await anc_app.providers.task_processing.unregister(provider_info.id) + with pytest.raises(NextcloudExceptionNotFound): + await anc_app.providers.task_processing.unregister(provider_info.id, not_fail=False) + await anc_app.providers.task_processing.unregister(provider_info.id) + await anc_app.providers.task_processing.register(provider_info) + assert not await anc_app.providers.task_processing.next_task(["test_id"], ["core:text2image"]) + assert not await anc_app.providers.task_processing.set_progress(9999, 0.5) + assert not await anc_app.providers.task_processing.report_result(9999, error_message="no such task") + with pytest.raises(NextcloudException): + await anc_app.providers.task_processing.upload_result_file(9999, b"00") + await anc_app.providers.task_processing.unregister(provider_info.id, not_fail=False) + + +@pytest.mark.require_nc(major=30) +def test_task_processing_provider_fail_report(nc_app): + nc_app.providers.task_processing.report_result(999999) + + +@pytest.mark.asyncio(scope="session") +@pytest.mark.require_nc(major=30) +async def test_task_processing_provider_fail_report_async(anc_app): + await anc_app.providers.task_processing.report_result(999999) diff --git a/tests/actual_tests/text_processing_provider_test.py b/tests/actual_tests/text_processing_provider_test.py deleted file mode 100644 index bc0fea36..00000000 --- a/tests/actual_tests/text_processing_provider_test.py +++ /dev/null @@ -1,69 +0,0 @@ -import pytest - -from nc_py_api import NextcloudExceptionNotFound - - -@pytest.mark.require_nc(major=29) -def test_text_processing_provider(nc_app): - nc_app.providers.text_processing.register("test_id", "Test #1 Prov", "/some_url", "free_prompt") - result = nc_app.providers.text_processing.get_entry("test_id") - assert result.name == "test_id" - assert result.display_name == "Test #1 Prov" - assert result.action_handler == "some_url" - nc_app.providers.text_processing.register("test_id2", "Test #2 Prov", "some_url2", "free_prompt") - result2 = nc_app.providers.text_processing.get_entry("test_id2") - assert result2.name == "test_id2" - assert result2.display_name == "Test #2 Prov" - assert result2.action_handler == "some_url2" - nc_app.providers.text_processing.register("test_id", "Renamed", "/new_url", "free_prompt") - result = nc_app.providers.text_processing.get_entry("test_id") - assert result.name == "test_id" - assert result.display_name == "Renamed" - assert result.action_handler == "new_url" - assert result.task_type == "free_prompt" - nc_app.providers.text_processing.unregister(result.name) - nc_app.providers.text_processing.unregister(result.name) - with pytest.raises(NextcloudExceptionNotFound): - nc_app.providers.text_processing.unregister(result.name, not_fail=False) - nc_app.providers.text_processing.unregister(result2.name, not_fail=False) - assert nc_app.providers.text_processing.get_entry(result2.name) is None - assert str(result).find("type=free_prompt") != -1 - - -@pytest.mark.asyncio(scope="session") -@pytest.mark.require_nc(major=29) -async def test_text_processing_provider_async(anc_app): - await anc_app.providers.text_processing.register("test_id", "Test #1 Prov", "/some_url", "free_prompt") - result = await anc_app.providers.text_processing.get_entry("test_id") - assert result.name == "test_id" - assert result.display_name == "Test #1 Prov" - assert result.action_handler == "some_url" - await anc_app.providers.text_processing.register("test_id2", "Test #2 Prov", "some_url2", "free_prompt") - result2 = await anc_app.providers.text_processing.get_entry("test_id2") - assert result2.name == "test_id2" - assert result2.display_name == "Test #2 Prov" - assert result2.action_handler == "some_url2" - await anc_app.providers.text_processing.register("test_id", "Renamed", "/new_url", "free_prompt") - result = await anc_app.providers.text_processing.get_entry("test_id") - assert result.name == "test_id" - assert result.display_name == "Renamed" - assert result.action_handler == "new_url" - assert result.task_type == "free_prompt" - await anc_app.providers.text_processing.unregister(result.name) - await anc_app.providers.text_processing.unregister(result.name) - with pytest.raises(NextcloudExceptionNotFound): - await anc_app.providers.text_processing.unregister(result.name, not_fail=False) - await anc_app.providers.text_processing.unregister(result2.name, not_fail=False) - assert await anc_app.providers.text_processing.get_entry(result2.name) is None - assert str(result).find("type=free_prompt") != -1 - - -@pytest.mark.require_nc(major=29) -def test_text_processing_provider_fail_report(nc_app): - nc_app.providers.text_processing.report_result(999999) - - -@pytest.mark.asyncio(scope="session") -@pytest.mark.require_nc(major=29) -async def test_text_processing_provider_fail_report_async(anc_app): - await anc_app.providers.text_processing.report_result(999999) diff --git a/tests/actual_tests/translation_provider_test.py b/tests/actual_tests/translation_provider_test.py deleted file mode 100644 index 85cdba07..00000000 --- a/tests/actual_tests/translation_provider_test.py +++ /dev/null @@ -1,124 +0,0 @@ -import pytest - -from nc_py_api import NextcloudExceptionNotFound - -FROM_LANG1 = {"ar_AR": "Arabic", "de_DE": "German", "uk_UA": "Ukrainian"} -TO_LANG1 = {"zh_CN": "Chinese", "en_US": "English", "es_ES": "Spanish"} - - -@pytest.mark.require_nc(major=29) -def test_translation_provider(nc_app): - nc_app.providers.translations.register( - "test_id", - "Test #1 Prov", - "/some_url", - FROM_LANG1, - TO_LANG1, - ) - result = nc_app.providers.translations.get_entry("test_id") - assert result.name == "test_id" - assert result.display_name == "Test #1 Prov" - assert result.action_handler == "some_url" - assert result.from_languages == FROM_LANG1 - assert result.to_languages == TO_LANG1 - assert result.action_handler_detect_lang == "" - nc_app.providers.translations.register( - "test_id2", - "Test #2 Prov", - "some_url2", - {"pl_PL": "Polish"}, - {"tr_TR": "Turkish"}, - "/detect_lang", - ) - result2 = nc_app.providers.translations.get_entry("test_id2") - assert result2.name == "test_id2" - assert result2.display_name == "Test #2 Prov" - assert result2.action_handler == "some_url2" - assert result2.from_languages == {"pl_PL": "Polish"} - assert result2.to_languages == {"tr_TR": "Turkish"} - assert result2.action_handler_detect_lang == "detect_lang" - nc_app.providers.translations.register( - "test_id", - "Renamed", - "/new_url", - {"kk_KZ": "Kazakh"}, - {"it_IT": "Italian"}, - ) - result = nc_app.providers.translations.get_entry("test_id") - assert result.name == "test_id" - assert result.display_name == "Renamed" - assert result.action_handler == "new_url" - assert result.from_languages == {"kk_KZ": "Kazakh"} - assert result.to_languages == {"it_IT": "Italian"} - nc_app.providers.translations.unregister(result.name) - with pytest.raises(NextcloudExceptionNotFound): - nc_app.providers.translations.unregister(result.name, not_fail=False) - nc_app.providers.translations.unregister(result.name) - nc_app.providers.translations.unregister(result2.name, not_fail=False) - assert nc_app.providers.translations.get_entry(result2.name) is None - assert str(result).find("name=") != -1 - - -@pytest.mark.asyncio(scope="session") -@pytest.mark.require_nc(major=29) -async def test_translation_async(anc_app): - await anc_app.providers.translations.register( - "test_id", - "Test #1 Prov", - "/some_url", - FROM_LANG1, - TO_LANG1, - ) - result = await anc_app.providers.translations.get_entry("test_id") - assert result.name == "test_id" - assert result.display_name == "Test #1 Prov" - assert result.action_handler == "some_url" - assert result.from_languages == FROM_LANG1 - assert result.to_languages == TO_LANG1 - assert result.action_handler_detect_lang == "" - await anc_app.providers.translations.register( - "test_id2", - "Test #2 Prov", - "some_url2", - {"pl_PL": "Polish"}, - {"tr_TR": "Turkish"}, - "/detect_lang", - ) - result2 = await anc_app.providers.translations.get_entry("test_id2") - assert result2.name == "test_id2" - assert result2.display_name == "Test #2 Prov" - assert result2.action_handler == "some_url2" - assert result2.from_languages == {"pl_PL": "Polish"} - assert result2.to_languages == {"tr_TR": "Turkish"} - assert result2.action_handler_detect_lang == "detect_lang" - await anc_app.providers.translations.register( - "test_id", - "Renamed", - "/new_url", - {"kk_KZ": "Kazakh"}, - {"it_IT": "Italian"}, - ) - result = await anc_app.providers.translations.get_entry("test_id") - assert result.name == "test_id" - assert result.display_name == "Renamed" - assert result.action_handler == "new_url" - assert result.from_languages == {"kk_KZ": "Kazakh"} - assert result.to_languages == {"it_IT": "Italian"} - await anc_app.providers.translations.unregister(result.name) - with pytest.raises(NextcloudExceptionNotFound): - await anc_app.providers.translations.unregister(result.name, not_fail=False) - await anc_app.providers.translations.unregister(result.name) - await anc_app.providers.translations.unregister(result2.name, not_fail=False) - assert await anc_app.providers.translations.get_entry(result2.name) is None - assert str(result).find("name=") != -1 - - -@pytest.mark.require_nc(major=29) -def test_translations_provider_fail_report(nc_app): - nc_app.providers.translations.report_result(999999) - - -@pytest.mark.asyncio(scope="session") -@pytest.mark.require_nc(major=29) -async def test_translations_provider_fail_report_async(anc_app): - await anc_app.providers.translations.report_result(999999)