Skip to content

Commit 6d149db

Browse files
authored
Merge pull request #1 from cloud-py-api/tests-fix
fixed tests with Oracle
2 parents 0e924f2 + 9b39582 commit 6d149db

File tree

13 files changed

+74
-67
lines changed

13 files changed

+74
-67
lines changed

.github/.codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
codecov:
22
notify:
3-
after_n_builds: 2
3+
after_n_builds: 3
44

55
comment:
66
require_changes: true

.github/workflows/analysis-coverage.yml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jobs:
108108
php occ config:system:set allow_local_remote_servers --value true
109109
php -S localhost:8080 &
110110
111-
- name: Checkout nc_py_api
111+
- name: Checkout NcPyApi
112112
uses: actions/checkout@v3
113113
with:
114114
path: nc_py_api
@@ -135,12 +135,12 @@ jobs:
135135
php occ app_ecosystem_v2:app:register $app_name $app_version "NcPyApi" \
136136
--host 127.0.0.1 --port 9002 \
137137
--secret $app_secret \
138-
-e --force-scopes
138+
-e --force-scopes --system-app
139139
kill -9 $(cat /tmp/_install.pid)
140140
141141
- name: Generate coverage report
142142
working-directory: nc_py_api
143-
run: coverage run -m pytest -rs && coverage xml && coverage html
143+
run: coverage run -m pytest && coverage xml && coverage html
144144

145145
- name: HTML coverage to artifacts
146146
uses: actions/upload-artifact@v3
@@ -232,12 +232,12 @@ jobs:
232232
php occ maintenance:install --verbose --database=pgsql --database-name=${{ env.NC_dbname }} \
233233
--database-host=127.0.0.1 --database-user=root --database-pass=rootpassword \
234234
--admin-user admin --admin-pass adminpassword
235-
php occ config:system:set loglevel --value 1
235+
php occ config:system:set loglevel --value=1
236236
php occ config:system:set debug --value=true --type=boolean
237237
php occ config:system:set allow_local_remote_servers --value true
238238
php -S localhost:8080 &
239239
240-
- name: Checkout nc_py_api
240+
- name: Checkout NcPyApi
241241
uses: actions/checkout@v3
242242
with:
243243
path: nc_py_api
@@ -264,12 +264,12 @@ jobs:
264264
php occ app_ecosystem_v2:app:register $app_name $app_version "NcPyApi" \
265265
--host 127.0.0.1 --port 9002 \
266266
--secret $app_secret \
267-
-e --force-scopes
267+
-e --force-scopes --system-app
268268
kill -9 $(cat /tmp/_install.pid)
269269
270270
- name: Generate coverage report
271271
working-directory: nc_py_api
272-
run: coverage run -m pytest -rs && coverage xml && coverage html
272+
run: coverage run -m pytest && coverage xml && coverage html
273273

274274
- name: HTML coverage to artifacts
275275
uses: actions/upload-artifact@v3
@@ -333,7 +333,7 @@ jobs:
333333
with:
334334
php-version: ${{ matrix.php-version }}
335335
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, \
336-
pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, oci8
336+
posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, oci8
337337

338338
- uses: actions/setup-python@v4
339339
with:
@@ -357,12 +357,12 @@ jobs:
357357
php occ maintenance:install --verbose --database=oci --database-name=XE \
358358
--database-host=127.0.0.1 --database-port=1521 --database-user=useroracle --database-pass=userpassword \
359359
--admin-user admin --admin-pass admin
360-
php occ config:system:set loglevel --value=0 --type=integer
360+
php occ config:system:set loglevel --value=1 --type=integer
361361
php occ config:system:set debug --value=true --type=boolean
362362
php occ config:system:set allow_local_remote_servers --value true
363363
php -S localhost:8080 &
364364
365-
- name: Checkout nc_py_api
365+
- name: Checkout NcPyApi
366366
uses: actions/checkout@v3
367367
with:
368368
path: nc_py_api
@@ -389,12 +389,14 @@ jobs:
389389
php occ app_ecosystem_v2:app:register $app_name $app_version "NcPyApi" \
390390
--host 127.0.0.1 --port 9002 \
391391
--secret $app_secret \
392-
-e --force-scopes
392+
-e --force-scopes --system-app
393393
kill -9 $(cat /tmp/_install.pid)
394394
395395
- name: Generate coverage report
396396
working-directory: nc_py_api
397-
run: coverage run -m pytest -rs && coverage xml && coverage html
397+
run: coverage run -m pytest && coverage xml && coverage html
398+
env:
399+
SKIP_NC_WO_AE: 1
398400

399401
- name: HTML coverage to artifacts
400402
uses: actions/upload-artifact@v3
@@ -411,10 +413,6 @@ jobs:
411413
fail_ci_if_error: true
412414
verbose: true
413415

414-
- name: Setup tmate session
415-
if: always()
416-
uses: mxschmitt/action-tmate@v3
417-
418416
- name: Upload NC logs
419417
if: always()
420418
uses: actions/upload-artifact@v3

nc_py_api/preferences.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self, session: NcSessionBasic):
1313
self._session = session
1414

1515
@property
16-
def avalaible(self) -> bool:
16+
def available(self) -> bool:
1717
return not check_capabilities("provisioning_api", self._session.capabilities)
1818

1919
def set(self, app_name: str, key: str, value: str) -> None:

nc_py_api/users_statuses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, session: NcSessionBasic):
3737
self._session = session
3838

3939
@property
40-
def avalaible(self) -> bool:
40+
def available(self) -> bool:
4141
return not check_capabilities("user_status", self._session.capabilities)
4242

4343
def get_all(self, limit: Optional[int] = None, offset: Optional[int] = None) -> list[UserStatus]:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ filterwarnings = [
2121
"ignore::DeprecationWarning",
2222
]
2323
log_cli = true
24-
addopts = "--color=yes"
24+
addopts = "-rs --color=yes"
2525

2626
[tool.coverage.run]
2727
cover_pylib = true

tests/appconfig_preferences_ex_test.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22

33
from nc_py_api import NextcloudException
44

5-
from gfixture import NC_TO_TEST
6-
NC_APP = NC_TO_TEST[1] if len(NC_TO_TEST) > 1 else None
5+
from gfixture import NC_APP
76

87

98
if NC_APP is None or "app_ecosystem_v2" not in NC_APP.capabilities:
109
pytest.skip("app_ecosystem_v2 is not installed.", allow_module_level=True)
1110

1211

13-
@pytest.mark.parametrize("value", ("0", "1", "12 3", ""))
1412
@pytest.mark.parametrize("class_to_test", (NC_APP.appconfig_ex_api, NC_APP.preferences_ex_api))
15-
def test_preferences_ex_set_delete(value, class_to_test):
13+
def test_cfg_ex_set_empty_key(class_to_test):
14+
with pytest.raises(NextcloudException):
15+
class_to_test.set("", "some value")
16+
17+
18+
# @pytest.mark.parametrize("value", ("0", "1", "12 3", ""))
19+
@pytest.mark.parametrize("value", ("0", "1", "12 3"))
20+
@pytest.mark.parametrize("class_to_test", (NC_APP.appconfig_ex_api, NC_APP.preferences_ex_api))
21+
def test_cfg_ex_set_delete(value, class_to_test):
1622
class_to_test.delete("test_key")
1723
assert class_to_test.get_value("test_key") is None
1824
class_to_test.set("test_key", value)
@@ -24,15 +30,7 @@ def test_preferences_ex_set_delete(value, class_to_test):
2430

2531

2632
@pytest.mark.parametrize("class_to_test", (NC_APP.appconfig_ex_api, NC_APP.preferences_ex_api))
27-
def test_preferences_ex_set_empty_param(class_to_test):
28-
class_to_test.set("", "123")
29-
assert class_to_test.get_value("") == "123"
30-
class_to_test.delete("")
31-
assert class_to_test.get_value("") is None
32-
33-
34-
@pytest.mark.parametrize("class_to_test", (NC_APP.appconfig_ex_api, NC_APP.preferences_ex_api))
35-
def test_preferences_ex_delete(class_to_test):
33+
def test_cfg_ex_delete(class_to_test):
3634
class_to_test.set("test_key", "123")
3735
assert class_to_test.get_value("test_key")
3836
class_to_test.delete("test_key")
@@ -43,7 +41,7 @@ def test_preferences_ex_delete(class_to_test):
4341

4442

4543
@pytest.mark.parametrize("class_to_test", (NC_APP.appconfig_ex_api, NC_APP.preferences_ex_api))
46-
def test_preferences_ex_multiply_delete(class_to_test):
44+
def test_cfg_ex_multiply_delete(class_to_test):
4745
class_to_test.set("test_key", "123")
4846
class_to_test.set("test_key2", "123")
4947
assert len(class_to_test.get_values(["test_key", "test_key2"])) == 2
@@ -56,9 +54,9 @@ def test_preferences_ex_multiply_delete(class_to_test):
5654
assert len(class_to_test.get_values(["test_key", "test_key2"])) == 0
5755

5856

59-
@pytest.mark.parametrize("key", ("k", "k y", "", " "))
57+
@pytest.mark.parametrize("key", ("k", "k y", " "))
6058
@pytest.mark.parametrize("class_to_test", (NC_APP.appconfig_ex_api, NC_APP.preferences_ex_api))
61-
def test_preferences_ex_get_non_existing(key, class_to_test):
59+
def test_cfg_ex_get_non_existing(key, class_to_test):
6260
try:
6361
class_to_test.delete(key)
6462
except NextcloudException:
@@ -69,7 +67,7 @@ def test_preferences_ex_get_non_existing(key, class_to_test):
6967

7068

7169
@pytest.mark.parametrize("class_to_test", (NC_APP.appconfig_ex_api, NC_APP.preferences_ex_api))
72-
def test_preferences_ex_get(class_to_test):
70+
def test_cfg_ex_get(class_to_test):
7371
class_to_test.delete(["test key", "test key2"])
7472
assert len(class_to_test.get_values(["test key", "test key2"])) == 0
7573
class_to_test.set("test key", "123")
@@ -80,7 +78,7 @@ def test_preferences_ex_get(class_to_test):
8078

8179

8280
@pytest.mark.parametrize("class_to_test", (NC_APP.appconfig_ex_api, NC_APP.preferences_ex_api))
83-
def test_preferences_ex_get_typing(class_to_test):
81+
def test_cfg_ex_get_typing(class_to_test):
8482
class_to_test.set("test key", "123")
8583
class_to_test.set("test key2", "321")
8684
r = class_to_test.get_values(["test key", "test key2"])

tests/apps_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
22

3+
from nc_py_api import Nextcloud
4+
35
from gfixture import NC_TO_TEST
46

57
APP_NAME = "files_trashbin"
@@ -19,6 +21,7 @@ def test_list_apps(nc):
1921
assert APP_NAME in apps
2022

2123

24+
@pytest.mark.skipif(not isinstance(NC_TO_TEST[:1], Nextcloud), reason="Not available for NextcloudApp.")
2225
@pytest.mark.parametrize("nc", NC_TO_TEST[:1])
2326
def test_enable_disable_app(nc):
2427
assert nc.apps.is_installed(APP_NAME)

tests/gfixture.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
1313
environ["app_version"] = "1.0.0"
1414
environ["app_secret"] = secret
1515

16-
nc = Nextcloud()
17-
nc_app = NextcloudApp(user="admin")
18-
if "app_ecosystem_v2" not in nc_app.capabilities:
19-
nc_app = None
16+
NC = Nextcloud()
17+
if environ.get("SKIP_NC_WO_AE", False):
18+
NC = None
2019

21-
NC_TO_TEST = [nc]
22-
if nc_app:
23-
NC_TO_TEST.append(nc_app)
20+
NC_APP = NextcloudApp(user="admin")
21+
if "app_ecosystem_v2" not in NC_APP.capabilities:
22+
NC_APP = None
2423

25-
NC_VERSION = nc.srv_version
24+
NC_TO_TEST = []
25+
if NC:
26+
NC_TO_TEST.append(NC)
27+
if NC_APP:
28+
NC_TO_TEST.append(NC_APP)
29+
30+
NC_VERSION = NC_TO_TEST[0].srv_version if NC_TO_TEST else {}

tests/groups_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import pytest
22

3-
from nc_py_api import NextcloudException
3+
from nc_py_api import NextcloudException, Nextcloud
44

55
from gfixture import NC_TO_TEST
66

77
TEST_GROUP_NAME = "test_coverage_group"
88

99

10+
@pytest.mark.skipif(not isinstance(NC_TO_TEST[:1], Nextcloud), reason="Not available for NextcloudApp.")
1011
@pytest.mark.parametrize("nc", NC_TO_TEST[:1])
1112
def test_create_delete_group(nc):
1213
try:
@@ -21,6 +22,7 @@ def test_create_delete_group(nc):
2122
nc.users_groups.delete(TEST_GROUP_NAME)
2223

2324

25+
@pytest.mark.skipif(not isinstance(NC_TO_TEST[:1], Nextcloud), reason="Not available for NextcloudApp.")
2426
@pytest.mark.parametrize("nc", NC_TO_TEST[:1])
2527
def test_list_group(nc):
2628
try:
@@ -44,6 +46,7 @@ def test_list_group(nc):
4446
nc.users_groups.delete(TEST_GROUP_NAME + "2")
4547

4648

49+
@pytest.mark.skipif(not isinstance(NC_TO_TEST[:1], Nextcloud), reason="Not available for NextcloudApp.")
4750
@pytest.mark.parametrize("nc", NC_TO_TEST[:1])
4851
def test_group_members_promote_demote(nc):
4952
try:

tests/logs_test.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
from nc_py_api import LogLvl, NextcloudException
66

7-
from gfixture import NC_TO_TEST
8-
NC_APP = NC_TO_TEST[1] if len(NC_TO_TEST) > 1 else None
9-
7+
from gfixture import NC_APP
108

119
if NC_APP is None or "app_ecosystem_v2" not in NC_APP.capabilities:
1210
pytest.skip("app_ecosystem_v2 is not installed.", allow_module_level=True)
@@ -45,7 +43,7 @@ def test_loglvl_equal():
4543

4644
@pytest.mark.skipif(AE_CAPABILITIES.get("loglevel", LogLvl.FATAL) == LogLvl.DEBUG, reason="Log lvl to low")
4745
def test_loglvl_less():
48-
with mock.patch("gfixture.nc_app._session._ocs") as _ocs:
46+
with mock.patch("gfixture.NC_APP._session._ocs") as _ocs:
4947
NC_APP.log(int(AE_CAPABILITIES["loglevel"]) - 1, "will not be sent")
5048
_ocs.assert_not_called()
5149
NC_APP.log(AE_CAPABILITIES["loglevel"], "will be sent")
@@ -58,7 +56,7 @@ def test_log_without_app_ecosystem_v2():
5856
log_lvl = srv_capabilities["app_ecosystem_v2"].pop("loglevel")
5957
srv_capabilities.pop("app_ecosystem_v2")
6058
patched_capabilities = {"capabilities": srv_capabilities, "version": srv_version}
61-
with mock.patch.dict("gfixture.nc_app._session._capabilities", patched_capabilities, clear=True):
62-
with mock.patch("gfixture.nc_app._session._ocs") as _ocs:
59+
with mock.patch.dict("gfixture.NC_APP._session._capabilities", patched_capabilities, clear=True):
60+
with mock.patch("gfixture.NC_APP._session._ocs") as _ocs:
6361
NC_APP.log(log_lvl, "will not be sent")
6462
_ocs.assert_not_called()

0 commit comments

Comments
 (0)