Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

standalone(as nc client) usage #57

Merged
merged 10 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/.codecov.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
codecov:
notify:
after_n_builds: 4
after_n_builds: 7

comment:
require_changes: true
Expand All @@ -11,8 +11,5 @@ coverage:
project:
default:
target: auto
threshold: 2%
threshold: 1%
patch: off

fixes:
- "nc_py_api/::"
120 changes: 112 additions & 8 deletions .github/workflows/analysis-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ jobs:
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: nc_py_api/coverage.xml
name: coverage_maria_${{ matrix.nextcloud }}_${{ matrix.python }}_${{ matrix.php-version }}
file: coverage.xml
fail_ci_if_error: true
verbose: true
working-directory: nc_py_api

- name: Upload NC logs
if: always()
Expand Down Expand Up @@ -275,9 +277,11 @@ jobs:
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: nc_py_api/coverage.xml
name: coverage_pgsql_${{ matrix.nextcloud }}_${{ matrix.python }}_${{ matrix.php-version }}
file: coverage.xml
fail_ci_if_error: true
verbose: true
working-directory: nc_py_api

- name: Upload NC logs
if: always()
Expand Down Expand Up @@ -384,7 +388,7 @@ jobs:
working-directory: nc_py_api
run: coverage run --data-file=.coverage.ci -m pytest && coverage combine && coverage xml && coverage html
env:
SKIP_NC_WO_AE: 1
SKIP_NC_CLIENT_TESTS: 1

- name: HTML coverage to artifacts
uses: actions/upload-artifact@v3
Expand All @@ -397,9 +401,11 @@ jobs:
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: nc_py_api/coverage.xml
name: coverage_oci_${{ matrix.nextcloud }}_${{ matrix.python }}_${{ matrix.php-version }}
file: coverage.xml
fail_ci_if_error: true
verbose: true
working-directory: nc_py_api

- name: Upload NC logs
if: always()
Expand All @@ -409,7 +415,7 @@ jobs:
path: data/nextcloud.log
if-no-files-found: warn

tests-latest:
tests-latest-maria-full:
needs: [analysis]
runs-on: ubuntu-22.04
name: Latest • 🐘8.2 • 🐍3.12 • Maria
Expand Down Expand Up @@ -506,9 +512,11 @@ jobs:
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: nc_py_api/coverage.xml
name: coverage_maria_latest
file: coverage.xml
fail_ci_if_error: true
verbose: true
working-directory: nc_py_api

- name: Upload NC logs
if: always()
Expand All @@ -518,6 +526,99 @@ jobs:
path: data/nextcloud.log
if-no-files-found: warn

test-latest-pgsql-client:
needs: [analysis]
runs-on: ubuntu-22.04
name: Latest • 🐘8.2 • 🐍3.12 • PgSQL
env:
NC_dbname: nextcloud_abz

services:
postgres:
image: postgres:15
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: rootpassword
POSTGRES_DB: ${{ env.NC_dbname }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Set up php
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: mbstring, fileinfo, intl, pdo_mysql, zip, gd

- uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Checkout server
uses: actions/checkout@v3
with:
submodules: true
repository: nextcloud/server
ref: "master"

- name: Set up & run Nextcloud
env:
DB_PORT: 4444
run: |
mkdir data
./occ maintenance:install --verbose --database=pgsql --database-name=${{ env.NC_dbname }} \
--database-host=127.0.0.1 --database-user=root --database-pass=rootpassword \
--admin-user admin --admin-pass ${{ env.NC_AUTH_PASS }}
./occ config:system:set loglevel --value=0 --type=integer
./occ config:system:set debug --value=true --type=boolean
./occ config:system:set allow_local_remote_servers --value true
php -S localhost:8080 &

- name: Checkout NcPyApi
uses: actions/checkout@v3
with:
path: nc_py_api

- name: Install NcPyApi
working-directory: nc_py_api
run: python3 -m pip -v install . pytest coverage pillow

- name: Generate coverage report
working-directory: nc_py_api
run: coverage run -m pytest && coverage xml && coverage html
env:
SKIP_AE_TESTS: 1

- name: HTML coverage to artifacts
uses: actions/upload-artifact@v3
with:
name: coverage_pgsql_latest
path: nc_py_api/htmlcov
if-no-files-found: error

- name: Upload report to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: coverage_pgsql_latest
file: coverage.xml
fail_ci_if_error: true
verbose: true
working-directory: nc_py_api

- name: Upload NC logs
if: always()
uses: actions/upload-artifact@v3
with:
name: nc_log_pgsql_latest
path: data/nextcloud.log
if-no-files-found: warn

tests-sqlite:
needs: [analysis]
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -607,9 +708,11 @@ jobs:
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: nc_py_api/coverage.xml
name: coverage_sqlite_${{ matrix.nextcloud }}
file: coverage.xml
fail_ci_if_error: true
verbose: true
working-directory: nc_py_api

- name: Upload NC logs
if: always()
Expand All @@ -623,7 +726,8 @@ jobs:
permissions:
contents: none
runs-on: ubuntu-22.04
needs: [tests-maria, tests-pgsql, tests-oci, tests-latest, tests-sqlite]
needs: [tests-maria, tests-pgsql, tests-oci, tests-latest-maria-full]
# needs: [tests-maria, tests-pgsql, tests-oci, tests-sqlite, tests-latest-maria-full, test-latest-pgsql-client]
name: Tests-OK
steps:
- run: echo "Tests passed successfully"
11 changes: 11 additions & 0 deletions nc_py_api/_deffered_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""DeferredError class taken from PIL._util.py file."""


class DeferredError: # pylint: disable=too-few-public-methods
"""Allow failing import when using it in the client mode, without `app` dependencies."""

def __init__(self, ex):
self.ex = ex

def __getattr__(self, elt):
raise self.ex
9 changes: 8 additions & 1 deletion nc_py_api/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@

from fastapi import Request
from httpx import Client, Limits, ReadTimeout, Response
from xxhash import xxh64

try:
from xxhash import xxh64
except ImportError as ex:
from ._deffered_error import DeferredError

xxh64 = DeferredError(ex)


from . import options
from .constants import OCSRespond
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ dynamic = [
"version",
]
dependencies = [
"fastapi==0.100.1",
"httpx==0.24.1",
"pydantic==2.1.1",
"requests==2.31",
"xmltodict==0.13",
]
[project.optional-dependencies]
app = [
"fastapi==0.100.1",
"httpx==0.24.1",
"pydantic==2.1.1",
"uvicorn[standard]==0.23.2",
"xxhash==3.3",
]
Expand Down Expand Up @@ -113,7 +113,7 @@ select = ["A", "B", "C", "D212", "E", "F", "UP", "W"]
"benchmarks/**/*.py" = ['D']
"docs/**/*.py" = ['D']
"examples/**/*.py" = ['D']
"tests/**/*.py" = ['D']
"tests/**/*.py" = ["D", "E402"]

[tool.ruff.mccabe]
max-complexity = 16
Expand Down
9 changes: 6 additions & 3 deletions tests/gfixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
environ["APP_VERSION"] = "1.0.0"
environ["APP_SECRET"] = "12345"

if environ.get("SKIP_NC_WO_AE", False):
if environ.get("SKIP_NC_CLIENT_TESTS", False):
NC = None
else:
NC = Nextcloud()

NC_APP = NextcloudApp(user="admin")
if "app_ecosystem_v2" not in NC_APP.capabilities:
if environ.get("SKIP_AE_TESTS", False):
NC_APP = None
else:
NC_APP = NextcloudApp(user="admin")
if "app_ecosystem_v2" not in NC_APP.capabilities:
NC_APP = None

NC_TO_TEST = []
if NC:
Expand Down
11 changes: 11 additions & 0 deletions tests/misc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gfixture import NC_APP

from nc_py_api import NextcloudException, check_error, misc
from nc_py_api._deffered_error import DeferredError # noqa
from nc_py_api._session import BasicConfig # noqa


Expand Down Expand Up @@ -42,3 +43,13 @@ def test_config_get_value():
with pytest.raises(ValueError):
BasicConfig()._get_value("non_exist_value")
assert BasicConfig()._get_value("non_exist_value", non_exist_value=123) == 123


def test_deffered_error():
try:
import unknown_non_exist_module
except ImportError as ex:
unknown_non_exist_module = DeferredError(ex)

with pytest.raises(ModuleNotFoundError):
unknown_non_exist_module.some_class_or_func()
3 changes: 3 additions & 0 deletions tests/ui_file_actions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import pytest
from gfixture import NC_APP
from PIL import Image

pytest.importorskip("selenium", reason="Selenium is not installed")

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
Expand Down