File: options_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 (71 lines) | stat: -rw-r--r-- 3,371 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
import os
import sys
from subprocess import PIPE, run
from unittest import mock

import nc_py_api


def test_timeouts():
    project_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    env_file = os.path.join(project_dir, ".env")
    env_backup_file = os.path.join(project_dir, ".env.backup")
    if os.path.exists(env_file):
        os.rename(env_file, env_backup_file)
    try:
        check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_TIMEOUT is None"]
        with open(env_file, "w") as env_f:
            env_f.write("NPA_TIMEOUT=None")
        r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False)
        assert not r.stderr
        check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_TIMEOUT == 11"]
        with open(env_file, "w") as env_f:
            env_f.write("NPA_TIMEOUT=11")
        r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False)
        assert not r.stderr
        check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_TIMEOUT_DAV is None"]
        with open(env_file, "w") as env_f:
            env_f.write("NPA_TIMEOUT_DAV=None")
        r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False)
        assert not r.stderr
        check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_TIMEOUT_DAV == 11"]
        with open(env_file, "w") as env_f:
            env_f.write("NPA_TIMEOUT_DAV=11")
        r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False)
        assert not r.stderr
        check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_NC_CERT is False"]
        with open(env_file, "w") as env_f:
            env_f.write("NPA_NC_CERT=False")
        r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False)
        assert not r.stderr
        check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_NC_CERT == ''"]
        with open(env_file, "w") as env_f:
            env_f.write('NPA_NC_CERT=""')
        r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False)
        assert not r.stderr
    finally:
        if os.path.exists(env_backup_file):
            os.rename(env_backup_file, env_file)


def test_xdebug_session(nc_any):
    nc_py_api.options.XDEBUG_SESSION = "12345"
    new_nc = nc_py_api.Nextcloud() if isinstance(nc_any, nc_py_api.Nextcloud) else nc_py_api.NextcloudApp()
    assert new_nc._session.adapter.cookies["XDEBUG_SESSION"] == "12345"


@mock.patch("nc_py_api.options.CHUNKED_UPLOAD_V2", False)
def test_chunked_upload(nc_any):
    new_nc = nc_py_api.Nextcloud() if isinstance(nc_any, nc_py_api.Nextcloud) else nc_py_api.NextcloudApp()
    assert new_nc._session.cfg.options.upload_chunk_v2 is False


def test_chunked_upload2(nc_any):
    new_nc = (
        nc_py_api.Nextcloud(chunked_upload_v2=False)
        if isinstance(nc_any, nc_py_api.Nextcloud)
        else nc_py_api.NextcloudApp(chunked_upload_v2=False)
    )
    assert new_nc._session.cfg.options.upload_chunk_v2 is False
    new_nc = nc_py_api.Nextcloud() if isinstance(nc_any, nc_py_api.Nextcloud) else nc_py_api.NextcloudApp()
    assert new_nc._session.cfg.options.upload_chunk_v2 is True