Skip to content

Commit

Permalink
fix for new app:register (#17)
Browse files Browse the repository at this point in the history
* new AppEcosystem fix
* correct fix for host DNS problems
  • Loading branch information
bigcat88 authored Jul 4, 2023
1 parent d704c65 commit a212a48
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 24 deletions.
19 changes: 7 additions & 12 deletions .github/workflows/analysis-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ on:
env:
NEXTCLOUD_URL: "http://localhost:8080/index.php"
APP_ID: "nc_py_api"
APP_PORT: 9009
APP_VERSION: "1.0.0"
APP_SECRET: "tC6vkwPhcppjMykD1r0n9NlI95uJMBYjs5blpIcA1PAdoPDmc5qoAjaBAkyocZ6E"
NC_AUTH_USER: "admin"
Expand Down Expand Up @@ -137,10 +138,8 @@ jobs:
sleep 5s
php occ app_ecosystem_v2:daemon:register docker-install Docker unix-socket 0 0 \
--net=host --host="127.0.0.1" --expose="local"
php occ app_ecosystem_v2:app:register $APP_ID $APP_VERSION "NcPyApi" \
--daemon-config-id 1 \
--port 9002 \
--secret $APP_SECRET \
php occ app_ecosystem_v2:app:register \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_id\":1,\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"port\":$APP_PORT}" \
-e --force-scopes --system-app
kill -15 $(cat /tmp/_install.pid)
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null
Expand Down Expand Up @@ -266,10 +265,8 @@ jobs:
sleep 5s
php occ app_ecosystem_v2:daemon:register docker-install Docker unix-socket 0 0 \
--net=host --host="127.0.0.1" --expose="local"
php occ app_ecosystem_v2:app:register $APP_ID $APP_VERSION "NcPyApi" \
--daemon-config-id 1 \
--port 9002 \
--secret $APP_SECRET \
php occ app_ecosystem_v2:app:register \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_id\":1,\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"port\":$APP_PORT}" \
-e --force-scopes --system-app
kill -15 $(cat /tmp/_install.pid)
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null
Expand Down Expand Up @@ -388,10 +385,8 @@ jobs:
sleep 5s
php occ app_ecosystem_v2:daemon:register docker-install Docker unix-socket 0 0 \
--net=host --host="127.0.0.1" --expose="local"
php occ app_ecosystem_v2:app:register $APP_ID $APP_VERSION "NcPyApi" \
--daemon-config-id 1 \
--port 9002 \
--secret $APP_SECRET \
php occ app_ecosystem_v2:app:register \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_id\":1,\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"port\":$APP_PORT}" \
-e --force-scopes --system-app
kill -15 $(cat /tmp/_install.pid)
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file.

## [0.0.21 - 2023-06-04]
## [0.0.21 - 2023-07-04]

### Added

Expand All @@ -12,6 +12,6 @@ All notable changes to this project will be documented in this file.

- All input environment variables now in Upper Case.

## [0.0.20 - 2023-06-03]
## [0.0.20 - 2023-07-03]

- Written from the scratch new version of the Nextcloud Python Client. Deep Alpha.
28 changes: 20 additions & 8 deletions tests/_install.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from os import environ

import uvicorn
from fastapi import FastAPI
import urllib3

from nc_py_api import NextcloudApp, set_enabled_handler, ApiScope, set_scopes

Expand All @@ -15,13 +16,24 @@ def enabled_handler(enabled: bool, _nc: NextcloudApp) -> str:
@APP.on_event("startup")
def initialization():
set_enabled_handler(APP, enabled_handler)
set_scopes(APP, {
"required": [ApiScope.SYSTEM, ApiScope.DAV, ApiScope.USER_INFO, ApiScope.USER_STATUS,
ApiScope.NOTIFICATIONS, ApiScope.WEATHER_STATUS],
"optional": []
})
set_scopes(
APP,
{
"required": [
ApiScope.SYSTEM,
ApiScope.DAV,
ApiScope.USER_INFO,
ApiScope.USER_STATUS,
ApiScope.NOTIFICATIONS,
ApiScope.WEATHER_STATUS,
],
"optional": [],
},
)


if __name__ == "__main__":
urllib3.disable_warnings()
uvicorn.run("_install:APP", host="0.0.0.0", port=9002, log_level='trace')
app_host = environ.get("APP_HOST", "")
uvicorn.run(
"_install:APP", host=app_host if app_host else "0.0.0.0", port=int(environ["APP_PORT"]), log_level="trace"
)
18 changes: 16 additions & 2 deletions tests/weather_status_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from nc_py_api import NextcloudException
from nc_py_api.weather_status import WeatherLocationMode

from gfixture import NC_TO_TEST
Expand All @@ -18,20 +19,31 @@ def test_get_set_location(nc):
assert loc["longitude"] == 0.0
assert isinstance(loc["address"], str)
assert isinstance(loc["mode"], int)
assert nc.weather_status.set_location(address="Paris, France")
try:
assert nc.weather_status.set_location(address="Paris, 75007, France")
except NextcloudException as e:
if e.status_code == 500:
pytest.skip("Some network problem on the host")
raise e from None
loc = nc.weather_status.get_location()
assert loc["latitude"]
assert loc["longitude"]
if loc["address"].find("Unknown") != -1:
pytest.skip("Some network problem on the host")
assert loc["address"].find("Paris") != -1
assert nc.weather_status.set_location(latitude=41.896655, longitude=12.488776)
loc = nc.weather_status.get_location()
assert loc["latitude"] == 41.896655
assert loc["longitude"] == 12.488776
if loc["address"].find("Unknown") != -1:
pytest.skip("Some network problem on the host")
assert loc["address"].find("Rom") != -1
assert nc.weather_status.set_location(latitude=41.896655, longitude=12.488776, address="Paris, France")
loc = nc.weather_status.get_location()
assert loc["latitude"] == 41.896655
assert loc["longitude"] == 12.488776
if loc["address"].find("Unknown") != -1:
pytest.skip("Some network problem on the host")
assert loc["address"].find("Rom") != -1


Expand All @@ -43,7 +55,9 @@ def test_get_set_location_no_lat_lon_address(nc):

@pytest.mark.parametrize("nc", NC_TO_TEST)
def test_get_forecast(nc):
nc.weather_status.set_location(address="Paris, France")
nc.weather_status.set_location(latitude=41.896655, longitude=12.488776)
if nc.weather_status.get_location()["address"].find("Unknown") != -1:
pytest.skip("Some network problem on the host")
forecast = nc.weather_status.get_forecast()
assert isinstance(forecast, list)
assert forecast
Expand Down

0 comments on commit a212a48

Please sign in to comment.