Skip to content

Commit

Permalink
added ex_app_get_list, ex_app_get_info (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigcat88 authored Jul 10, 2023
1 parent a854d34 commit 5b4b188
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Added

- `VERIFY_NC_CERTIFICATE` option.
- `apps.ex_app_get_list` and `apps.ex_app_get_info` methods.

## [0.0.23 - 2023-07-07]

Expand Down
25 changes: 24 additions & 1 deletion nc_py_api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@
Nextcloud API for working with applications.
"""

from typing import Optional
from typing import Optional, TypedDict

from ._session import NcSessionBasic
from .constants import APP_V2_BASIC_URL
from .misc import require_capabilities

ENDPOINT = "/ocs/v1.php/cloud/apps"


class ExAppInfo(TypedDict):
id: str
name: str
version: str
enabled: bool
last_response_time: int
system: bool


class AppAPI:
def __init__(self, session: NcSessionBasic):
self._session = session
Expand Down Expand Up @@ -44,3 +55,15 @@ def is_disabled(self, app_name: str) -> bool:
if not app_name:
raise ValueError("`app_name` parameter can not be empty")
return app_name in self.get_list(enabled=False)

def ex_app_get_list(self) -> list[str]:
"""Gets list of the external applications installed on the server."""

require_capabilities("app_ecosystem_v2", self._session.capabilities)
return self._session.ocs(method="GET", path=f"{APP_V2_BASIC_URL}/ex-app/all", params={"extended": 0})

def ex_app_get_info(self) -> list[ExAppInfo]:
"""Gets information of the external applications installed on the server."""

require_capabilities("app_ecosystem_v2", self._session.capabilities)
return self._session.ocs(method="GET", path=f"{APP_V2_BASIC_URL}/ex-app/all", params={"extended": 1})
24 changes: 24 additions & 0 deletions tests/apps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,27 @@ def test_invalid_param(nc):
nc.apps.enable("")
with pytest.raises(ValueError):
nc.apps.disable("")


@pytest.mark.parametrize("nc", NC_TO_TEST)
def test_ex_app_get_list(nc):
if "app_ecosystem_v2" not in nc.capabilities:
pytest.skip("app_ecosystem_v2 is not installed.")
ex_apps = nc.apps.ex_app_get_list()
assert isinstance(ex_apps, list)
assert isinstance(ex_apps[0], str)


@pytest.mark.parametrize("nc", NC_TO_TEST)
def test_ex_app_get_info(nc):
if "app_ecosystem_v2" not in nc.capabilities:
pytest.skip("app_ecosystem_v2 is not installed.")
ex_apps = nc.apps.ex_app_get_info()
assert isinstance(ex_apps, list)
nc_py_api = [i for i in ex_apps if i["id"] == "nc_py_api"][0]
assert nc_py_api["id"] == "nc_py_api"
assert isinstance(nc_py_api["name"], str)
assert isinstance(nc_py_api["version"], str)
assert nc_py_api["enabled"]
assert isinstance(nc_py_api["last_response_time"], int)
assert nc_py_api["system"]

0 comments on commit 5b4b188

Please sign in to comment.