File: apps_test.py

package info (click to toggle)
nc-py-api 0.19.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,320 kB
  • sloc: python: 12,415; makefile: 238; xml: 100; javascript: 56; sh: 14
file content (143 lines) | stat: -rw-r--r-- 5,090 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import pytest

from nc_py_api.apps import ExAppInfo

APP_NAME = "files_trashbin"


def test_list_apps_types(nc):
    assert isinstance(nc.apps.get_list(), list)
    assert isinstance(nc.apps.get_list(enabled=True), list)
    assert isinstance(nc.apps.get_list(enabled=False), list)


@pytest.mark.asyncio(scope="session")
async def test_list_apps_types_async(anc):
    assert isinstance(await anc.apps.get_list(), list)
    assert isinstance(await anc.apps.get_list(enabled=True), list)
    assert isinstance(await anc.apps.get_list(enabled=False), list)


def test_list_apps(nc):
    apps = nc.apps.get_list()
    assert apps
    assert APP_NAME in apps


@pytest.mark.asyncio(scope="session")
async def test_list_apps_async(anc):
    apps = await anc.apps.get_list()
    assert apps
    assert APP_NAME in apps


def test_app_enable_disable(nc_client):
    assert nc_client.apps.is_installed(APP_NAME) is True
    if nc_client.apps.is_enabled(APP_NAME):
        nc_client.apps.disable(APP_NAME)
    assert nc_client.apps.is_disabled(APP_NAME) is True
    assert nc_client.apps.is_enabled(APP_NAME) is False
    assert nc_client.apps.is_installed(APP_NAME) is True
    nc_client.apps.enable(APP_NAME)
    assert nc_client.apps.is_enabled(APP_NAME) is True
    assert nc_client.apps.is_installed(APP_NAME) is True


@pytest.mark.asyncio(scope="session")
async def test_app_enable_disable_async(anc_client):
    assert await anc_client.apps.is_installed(APP_NAME) is True
    if await anc_client.apps.is_enabled(APP_NAME):
        await anc_client.apps.disable(APP_NAME)
    assert await anc_client.apps.is_disabled(APP_NAME) is True
    assert await anc_client.apps.is_enabled(APP_NAME) is False
    assert await anc_client.apps.is_installed(APP_NAME) is True
    await anc_client.apps.enable(APP_NAME)
    assert await anc_client.apps.is_enabled(APP_NAME) is True
    assert await anc_client.apps.is_installed(APP_NAME) is True


def test_is_installed_enabled(nc):
    assert nc.apps.is_enabled(APP_NAME) != nc.apps.is_disabled(APP_NAME)
    assert nc.apps.is_installed(APP_NAME)


@pytest.mark.asyncio(scope="session")
async def test_is_installed_enabled_async(anc):
    assert await anc.apps.is_enabled(APP_NAME) != await anc.apps.is_disabled(APP_NAME)
    assert await anc.apps.is_installed(APP_NAME)


def test_invalid_param(nc_any):
    with pytest.raises(ValueError):
        nc_any.apps.is_enabled("")
    with pytest.raises(ValueError):
        nc_any.apps.is_installed("")
    with pytest.raises(ValueError):
        nc_any.apps.is_disabled("")
    with pytest.raises(ValueError):
        nc_any.apps.enable("")
    with pytest.raises(ValueError):
        nc_any.apps.disable("")
    with pytest.raises(ValueError):
        nc_any.apps.ex_app_is_enabled("")
    with pytest.raises(ValueError):
        nc_any.apps.ex_app_is_disabled("")
    with pytest.raises(ValueError):
        nc_any.apps.ex_app_disable("")
    with pytest.raises(ValueError):
        nc_any.apps.ex_app_enable("")


@pytest.mark.asyncio(scope="session")
async def test_invalid_param_async(anc_any):
    with pytest.raises(ValueError):
        await anc_any.apps.is_enabled("")
    with pytest.raises(ValueError):
        await anc_any.apps.is_installed("")
    with pytest.raises(ValueError):
        await anc_any.apps.is_disabled("")
    with pytest.raises(ValueError):
        await anc_any.apps.enable("")
    with pytest.raises(ValueError):
        await anc_any.apps.disable("")
    with pytest.raises(ValueError):
        await anc_any.apps.ex_app_is_enabled("")
    with pytest.raises(ValueError):
        await anc_any.apps.ex_app_is_disabled("")
    with pytest.raises(ValueError):
        await anc_any.apps.ex_app_disable("")
    with pytest.raises(ValueError):
        await anc_any.apps.ex_app_enable("")


def _test_ex_app_get_list(ex_apps: list[ExAppInfo], enabled_ex_apps: list[ExAppInfo]):
    assert isinstance(ex_apps, list)
    assert "nc_py_api" in [i.app_id for i in ex_apps]
    assert len(ex_apps) >= len(enabled_ex_apps)
    for app in ex_apps:
        assert isinstance(app.app_id, str)
        assert isinstance(app.name, str)
        assert isinstance(app.version, str)
        assert isinstance(app.enabled, bool)
        assert str(app).find("id=") != -1 and str(app).find("ver=") != -1


def test_ex_app_get_list(nc, nc_app):
    enabled_ex_apps = nc.apps.ex_app_get_list(enabled=True)
    assert isinstance(enabled_ex_apps, list)
    for i in enabled_ex_apps:
        assert i.enabled is True
    assert "nc_py_api" in [i.app_id for i in enabled_ex_apps]
    ex_apps = nc.apps.ex_app_get_list()
    _test_ex_app_get_list(ex_apps, enabled_ex_apps)


@pytest.mark.asyncio(scope="session")
async def test_ex_app_get_list_async(anc, anc_app):
    enabled_ex_apps = await anc.apps.ex_app_get_list(enabled=True)
    assert isinstance(enabled_ex_apps, list)
    for i in enabled_ex_apps:
        assert i.enabled is True
    assert "nc_py_api" in [i.app_id for i in enabled_ex_apps]
    ex_apps = await anc.apps.ex_app_get_list()
    _test_ex_app_get_list(ex_apps, enabled_ex_apps)