Skip to content

skip OCS parsing when status == NO CONTENT #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 1, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file.

- API for registering Speech to Text provider(*avalaible from Nextcloud 29*). #196

### Fixed

- OCS: Correctly handling of `HTTP 204 No Content` status. #197

## [0.7.2 - 2023-12-28]

### Fixed
Expand Down
4 changes: 3 additions & 1 deletion nc_py_api/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def ocs(

check_error(response, info)
if response.status_code == 204: # NO_CONTENT
return ""
return []
response_data = loads(response.text)
ocs_meta = response_data["ocs"]["meta"]
if ocs_meta["status"] != "ok":
Expand Down Expand Up @@ -300,6 +300,8 @@ async def ocs(
raise NextcloudException(408, info=info) from None

check_error(response, info)
if response.status_code == 204: # NO_CONTENT
return []
response_data = loads(response.text)
ocs_meta = response_data["ocs"]["meta"]
if ocs_meta["status"] != "ok":
Expand Down
4 changes: 3 additions & 1 deletion nc_py_api/ex_app/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ class ApiScope(enum.IntEnum):
ACTIVITIES = 110
"""Activity App endpoints."""
NOTES = 120
"""Notes App endpoints"""
"""Notes App endpoints."""
ALL = 9999
"""All endpoints allowed."""
2 changes: 1 addition & 1 deletion scripts/ci_register.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

php occ app_api:daemon:register manual_install "Manual Install" manual-install 0 0 0
php occ app_api:app:register "$1" manual_install --json-info \
"{\"appid\":\"$1\",\"name\":\"$1\",\"daemon_config_name\":\"manual_install\",\"version\":\"$2\",\"secret\":\"$3\",\"host\":\"$4\",\"scopes\":{\"required\":[\"SYSTEM\", \"FILES\", \"FILES_SHARING\"],\"optional\":[\"USER_INFO\", \"USER_STATUS\", \"NOTIFICATIONS\", \"WEATHER_STATUS\", \"TALK\", \"TALK_BOT\", \"ACTIVITIES\", \"NOTES\", \"AI_PROVIDERS\"]},\"port\":$5,\"protocol\":\"http\",\"system_app\":1}" \
"{\"appid\":\"$1\",\"name\":\"$1\",\"daemon_config_name\":\"manual_install\",\"version\":\"$2\",\"secret\":\"$3\",\"host\":\"$4\",\"scopes\":{\"required\":[\"ALL\"],\"optional\":[]},\"port\":$5,\"protocol\":\"http\",\"system_app\":1}" \
--force-scopes --wait-finish
2 changes: 1 addition & 1 deletion scripts/dev_register.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ NEXTCLOUD_URL="http://$2" APP_PORT=9009 APP_ID="nc_py_api" APP_SECRET="12345" AP
echo $! > /tmp/_install.pid
python3 tests/_install_wait.py "http://localhost:9009/heartbeat" "\"status\":\"ok\"" 15 0.5
docker exec "$1" sudo -u www-data php occ app_api:app:register nc_py_api manual_install --json-info \
"{\"appid\":\"nc_py_api\",\"name\":\"nc_py_api\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"scopes\":{\"required\":[\"SYSTEM\", \"FILES\", \"FILES_SHARING\"],\"optional\":[\"USER_INFO\", \"USER_STATUS\", \"NOTIFICATIONS\", \"WEATHER_STATUS\", \"TALK\", \"TALK_BOT\", \"ACTIVITIES\", \"NOTES\", \"AI_PROVIDERS\"]},\"port\":9009,\"protocol\":\"http\",\"system_app\":1}" \
"{\"appid\":\"nc_py_api\",\"name\":\"nc_py_api\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"scopes\":{\"required\":[\"ALL\"],\"optional\":[]},\"port\":9009,\"protocol\":\"http\",\"system_app\":1}" \
--force-scopes --wait-finish
cat /tmp/_install.pid
kill -15 "$(cat /tmp/_install.pid)"
Expand Down
11 changes: 11 additions & 0 deletions tests/actual_tests/misc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ async def test_public_ocs_async(anc_any):
assert r == await anc_any._session.ocs("GET", "ocs/v1.php/cloud/capabilities") # noqa


def test_all_scope(nc_any):
r = nc_any.ocs("GET", "/ocs/v2.php/core/whatsnew")
assert isinstance(r, list)


@pytest.mark.asyncio(scope="session")
async def test_all_scope_async(anc_any):
r = await anc_any.ocs("GET", "/ocs/v2.php/core/whatsnew")
assert isinstance(r, list)


def test_perform_login(nc_any):
new_nc = Nextcloud() if isinstance(nc_any, Nextcloud) else NextcloudApp()
assert not new_nc._session._capabilities
Expand Down
22 changes: 14 additions & 8 deletions tests/actual_tests/nc_app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ async def test_get_users_list_async(anc_app):

def test_scope_allowed(nc_app):
for i in ApiScope:
assert nc_app.scope_allowed(i)
if i == ApiScope.ALL.value:
assert nc_app.scope_allowed(i)
else:
assert not nc_app.scope_allowed(i)
assert not nc_app.scope_allowed(0) # noqa
assert not nc_app.scope_allowed(999999999) # noqa


@pytest.mark.asyncio(scope="session")
async def test_scope_allowed_async(anc_app):
for i in ApiScope:
assert await anc_app.scope_allowed(i)
if i == ApiScope.ALL.value:
assert await anc_app.scope_allowed(i)
else:
assert not await anc_app.scope_allowed(i)
assert not await anc_app.scope_allowed(0) # noqa
assert not await anc_app.scope_allowed(999999999) # noqa

Expand All @@ -50,25 +56,25 @@ async def test_app_cfg_async(anc_app):


def test_scope_allow_app_ecosystem_disabled(nc_client, nc_app):
assert nc_app.scope_allowed(ApiScope.FILES)
assert nc_app.scope_allowed(ApiScope.ALL)
nc_client.apps.disable("app_api")
try:
assert nc_app.scope_allowed(ApiScope.FILES)
assert nc_app.scope_allowed(ApiScope.ALL)
nc_app.update_server_info()
assert not nc_app.scope_allowed(ApiScope.FILES)
assert not nc_app.scope_allowed(ApiScope.ALL)
finally:
nc_client.apps.enable("app_api")
nc_app.update_server_info()


@pytest.mark.asyncio(scope="session")
async def test_scope_allow_app_ecosystem_disabled_async(anc_client, anc_app):
assert await anc_app.scope_allowed(ApiScope.FILES)
assert await anc_app.scope_allowed(ApiScope.ALL)
await anc_client.apps.disable("app_api")
try:
assert await anc_app.scope_allowed(ApiScope.FILES)
assert await anc_app.scope_allowed(ApiScope.ALL)
await anc_app.update_server_info()
assert not await anc_app.scope_allowed(ApiScope.FILES)
assert not await anc_app.scope_allowed(ApiScope.ALL)
finally:
await anc_client.apps.enable("app_api")
await anc_app.update_server_info()
Expand Down