|
| 1 | +import os |
| 2 | +import sys |
| 3 | +from subprocess import PIPE, run |
| 4 | + |
| 5 | +import pytest |
| 6 | +from gfixture import NC_TO_TEST |
| 7 | + |
| 8 | +import nc_py_api |
| 9 | + |
| 10 | + |
| 11 | +def test_timeouts(): |
| 12 | + project_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 13 | + env_file = os.path.join(project_dir, ".env") |
| 14 | + env_backup_file = os.path.join(project_dir, ".env.backup") |
| 15 | + if os.path.exists(env_file): |
| 16 | + os.rename(env_file, env_backup_file) |
| 17 | + try: |
| 18 | + check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_TIMEOUT is None"] |
| 19 | + with open(env_file, "w") as env_f: |
| 20 | + env_f.write("NPA_TIMEOUT=None") |
| 21 | + r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False) |
| 22 | + assert not r.stderr |
| 23 | + check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_TIMEOUT == 11"] |
| 24 | + with open(env_file, "w") as env_f: |
| 25 | + env_f.write("NPA_TIMEOUT=11") |
| 26 | + r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False) |
| 27 | + assert not r.stderr |
| 28 | + check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_TIMEOUT_DAV is None"] |
| 29 | + with open(env_file, "w") as env_f: |
| 30 | + env_f.write("NPA_TIMEOUT_DAV=None") |
| 31 | + r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False) |
| 32 | + assert not r.stderr |
| 33 | + check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_TIMEOUT_DAV == 11"] |
| 34 | + with open(env_file, "w") as env_f: |
| 35 | + env_f.write("NPA_TIMEOUT_DAV=11") |
| 36 | + r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False) |
| 37 | + assert not r.stderr |
| 38 | + finally: |
| 39 | + if os.path.exists(env_backup_file): |
| 40 | + os.rename(env_backup_file, env_file) |
| 41 | + |
| 42 | + |
| 43 | +@pytest.mark.skipif(not NC_TO_TEST, reason="Need Nextcloud or NextcloudApp.") |
| 44 | +def test_xdebug_session(): |
| 45 | + nc_py_api.options.XDEBUG_SESSION = "12345" |
| 46 | + if isinstance(NC_TO_TEST, nc_py_api.Nextcloud): |
| 47 | + new_nc = nc_py_api.Nextcloud() |
| 48 | + else: |
| 49 | + new_nc = nc_py_api.NextcloudApp() |
| 50 | + assert new_nc._session.adapter.cookies["XDEBUG_SESSION"] == "12345" |
0 commit comments