Skip to content

Commit adee742

Browse files
authored
py: coverage, get_mimetype_id fix (#5)
1 parent 129cbff commit adee742

13 files changed

+374
-8
lines changed

.codecov.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
comment:
2+
require_changes: true
3+
layout: "diff, files"
4+
5+
coverage:
6+
status:
7+
project:
8+
default:
9+
target: auto
10+
threshold: 2%
11+
patch:
12+
default:
13+
target: auto
14+
threshold: 2%

.github/workflows/py_analysis-coverage.yml

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ on:
1818
- 'pyproject.toml'
1919
workflow_dispatch:
2020

21+
env:
22+
APP_NAME: cloud_py_api
23+
2124
jobs:
2225
analysis:
2326
runs-on: macos-12
@@ -46,3 +49,271 @@ jobs:
4649
4750
- name: Run Analysis
4851
run: pre-commit run --all-files --verbose --show-diff-on-failure
52+
53+
tests-pgsql:
54+
needs: [analysis]
55+
runs-on: ubuntu-22.04
56+
name: ${{ matrix.nextcloud }} • PHP ${{ matrix.php-version }} • PgSQL ${{ matrix.pgsql-version }}
57+
if: "!contains(github.event.head_commit.message, '[docs]')"
58+
strategy:
59+
fail-fast: false
60+
matrix:
61+
nextcloud: [ "25.0.2" ]
62+
php-version: [ "7.4", "8.0" ]
63+
pgsql-version: [ "13", "14", "15" ]
64+
65+
services:
66+
postgres:
67+
image: postgres:${{ matrix.pgsql-version }}
68+
env:
69+
POSTGRES_USER: root
70+
POSTGRES_PASSWORD: rootpassword
71+
POSTGRES_DB: nextcloud
72+
options: >-
73+
--health-cmd pg_isready
74+
--health-interval 10s
75+
--health-timeout 5s
76+
--health-retries 5
77+
ports:
78+
- 5432:5432
79+
80+
steps:
81+
- name: Set up php ${{ matrix.php-version }}
82+
uses: shivammathur/setup-php@v2
83+
with:
84+
php-version: ${{ matrix.php-version }}
85+
extensions: mbstring, fileinfo, intl, pdo_pgsql, zip, gd
86+
87+
- uses: actions/setup-python@v4
88+
with:
89+
python-version: '3.9'
90+
91+
- name: cache-nextcloud
92+
id: nextcloud_setup
93+
uses: actions/cache@v3
94+
with:
95+
path: nextcloud-${{ matrix.nextcloud }}.tar.bz2
96+
key: ${{ matrix.nextcloud }}
97+
98+
- name: Download Nextcloud
99+
if: steps.nextcloud_setup.outputs.cache-hit != 'true'
100+
run: wget -q https://download.nextcloud.com/server/releases/nextcloud-${{ matrix.nextcloud }}.tar.bz2
101+
102+
- name: Set up Nextcloud
103+
run: |
104+
tar -xjf nextcloud-${{ matrix.nextcloud }}.tar.bz2 --strip-components 1
105+
mkdir data
106+
php occ maintenance:install --verbose --database=pgsql --database-name=nextcloud \
107+
--database-host=127.0.0.1 --database-user=root --database-pass=rootpassword \
108+
--admin-user admin --admin-pass adminpassword
109+
php occ config:system:set debug --value=true --type=boolean
110+
php -S localhost:8080 &
111+
112+
- uses: actions/checkout@v3
113+
with:
114+
path: apps/${{ env.APP_NAME }}
115+
116+
- name: Enable App
117+
run: php occ app:enable ${{ env.APP_NAME }}
118+
119+
- name: Generate coverage report
120+
working-directory: apps/${{ env.APP_NAME }}
121+
run: |
122+
python3 -m pip -v install ".[dev]"
123+
coverage run -m pytest -s && coverage xml && coverage html
124+
env:
125+
SERVER_ROOT: "../.."
126+
CPA_LOGLEVEL: debug
127+
128+
- name: HTML coverage to artifacts
129+
uses: actions/upload-artifact@v3
130+
with:
131+
name: coverage_${{ matrix.nextcloud }}_${{ matrix.php-version }}_${{ matrix.pgsql-version }}
132+
path: apps/${{ env.APP_NAME }}/htmlcov
133+
if-no-files-found: error
134+
135+
- name: Upload report to Codecov
136+
uses: codecov/codecov-action@v3
137+
with:
138+
token: ${{ secrets.CODECOV_TOKEN }}
139+
file: apps/${{ env.APP_NAME }}/coverage.xml
140+
fail_ci_if_error: true
141+
verbose: true
142+
143+
tests-mysql:
144+
needs: [analysis]
145+
runs-on: ubuntu-22.04
146+
name: ${{ matrix.nextcloud }} • PHP ${{ matrix.php-version }} • MySQL ${{ matrix.mysql-version }}
147+
if: "!contains(github.event.head_commit.message, '[docs]')"
148+
strategy:
149+
fail-fast: false
150+
matrix:
151+
nextcloud: [ "25.0.2" ]
152+
php-version: [ "7.4", "8.0" ]
153+
mysql-version: [ "8" ]
154+
155+
services:
156+
mysql:
157+
image: mysql:${{ matrix.mysql-version }}
158+
env:
159+
MYSQL_ROOT_PASSWORD: rootpassword
160+
MYSQL_DATABASE: nextcloud
161+
options: >-
162+
--health-cmd mysqladmin ping
163+
--health-interval 10s
164+
--health-timeout 5s
165+
--health-retries 5
166+
ports:
167+
- 3306:3306
168+
169+
steps:
170+
- name: Set up php ${{ matrix.php-version }}
171+
uses: shivammathur/setup-php@v2
172+
with:
173+
php-version: ${{ matrix.php-version }}
174+
extensions: mbstring, fileinfo, intl, pdo_mysql, zip, gd
175+
176+
- uses: actions/setup-python@v4
177+
with:
178+
python-version: '3.9'
179+
180+
- name: cache-nextcloud
181+
id: nextcloud_setup
182+
uses: actions/cache@v3
183+
with:
184+
path: nextcloud-${{ matrix.nextcloud }}.tar.bz2
185+
key: ${{ matrix.nextcloud }}
186+
187+
- name: Download Nextcloud
188+
if: steps.nextcloud_setup.outputs.cache-hit != 'true'
189+
run: wget -q https://download.nextcloud.com/server/releases/nextcloud-${{ matrix.nextcloud }}.tar.bz2
190+
191+
- name: Set up Nextcloud
192+
run: |
193+
tar -xjf nextcloud-${{ matrix.nextcloud }}.tar.bz2 --strip-components 1
194+
mkdir data
195+
php occ maintenance:install --verbose --database=mysql --database-name=nextcloud \
196+
--database-host=127.0.0.1 --database-user=root --database-pass=rootpassword \
197+
--admin-user admin --admin-pass adminpassword
198+
php occ config:system:set debug --value=true --type=boolean
199+
php -S localhost:8080 &
200+
201+
- uses: actions/checkout@v3
202+
with:
203+
path: apps/${{ env.APP_NAME }}
204+
205+
- name: Enable App
206+
run: php occ app:enable ${{ env.APP_NAME }}
207+
208+
- name: Generate coverage report
209+
working-directory: apps/${{ env.APP_NAME }}
210+
run: |
211+
python3 -m pip -v install ".[dev]"
212+
coverage run -m pytest -s && coverage xml && coverage html
213+
env:
214+
SERVER_ROOT: "../.."
215+
CPA_LOGLEVEL: debug
216+
217+
- name: HTML coverage to artifacts
218+
uses: actions/upload-artifact@v3
219+
with:
220+
name: coverage_${{ matrix.nextcloud }}_${{ matrix.php-version }}_${{ matrix.mysql-version }}
221+
path: apps/${{ env.APP_NAME }}/htmlcov
222+
if-no-files-found: error
223+
224+
- name: Upload report to Codecov
225+
uses: codecov/codecov-action@v3
226+
with:
227+
token: ${{ secrets.CODECOV_TOKEN }}
228+
file: apps/${{ env.APP_NAME }}/coverage.xml
229+
fail_ci_if_error: true
230+
verbose: true
231+
232+
tests-mariadb:
233+
needs: [analysis]
234+
runs-on: ubuntu-22.04
235+
name: ${{ matrix.nextcloud }} • PHP ${{ matrix.php-version }} • Maria ${{ matrix.mariadb-version }}
236+
if: "!contains(github.event.head_commit.message, '[docs]')"
237+
strategy:
238+
fail-fast: false
239+
matrix:
240+
nextcloud: [ "25.0.2" ]
241+
php-version: [ "7.4", "8.0" ]
242+
mariadb-version: [ "10.3", "10.6", "10.10" ]
243+
244+
services:
245+
mariadb:
246+
image: mariadb:${{ matrix.mariadb-version }}
247+
env:
248+
MARIADB_ROOT_PASSWORD: rootpassword
249+
MYSQL_DATABASE: nextcloud
250+
options: >-
251+
--health-cmd mysqladmin ping
252+
--health-interval 10s
253+
--health-timeout 5s
254+
--health-retries 5
255+
ports:
256+
- 3306:3306
257+
258+
steps:
259+
- name: Set up php ${{ matrix.php-version }}
260+
uses: shivammathur/setup-php@v2
261+
with:
262+
php-version: ${{ matrix.php-version }}
263+
extensions: mbstring, fileinfo, intl, pdo_mysql, zip, gd
264+
265+
- uses: actions/setup-python@v4
266+
with:
267+
python-version: '3.9'
268+
269+
- name: cache-nextcloud
270+
id: nextcloud_setup
271+
uses: actions/cache@v3
272+
with:
273+
path: nextcloud-${{ matrix.nextcloud }}.tar.bz2
274+
key: ${{ matrix.nextcloud }}
275+
276+
- name: Download Nextcloud
277+
if: steps.nextcloud_setup.outputs.cache-hit != 'true'
278+
run: wget -q https://download.nextcloud.com/server/releases/nextcloud-${{ matrix.nextcloud }}.tar.bz2
279+
280+
- name: Set up Nextcloud
281+
run: |
282+
tar -xjf nextcloud-${{ matrix.nextcloud }}.tar.bz2 --strip-components 1
283+
mkdir data
284+
php occ maintenance:install --verbose --database=mysql --database-name=nextcloud \
285+
--database-host=127.0.0.1 --database-user=root --database-pass=rootpassword \
286+
--admin-user admin --admin-pass adminpassword
287+
php occ config:system:set debug --value=true --type=boolean
288+
php -S localhost:8080 &
289+
290+
- uses: actions/checkout@v3
291+
with:
292+
path: apps/${{ env.APP_NAME }}
293+
294+
- name: Enable App
295+
run: php occ app:enable ${{ env.APP_NAME }}
296+
297+
- name: Generate coverage report
298+
working-directory: apps/${{ env.APP_NAME }}
299+
run: |
300+
python3 -m pip -v install ".[dev]"
301+
coverage run -m pytest -s && coverage xml && coverage html
302+
env:
303+
SERVER_ROOT: "../.."
304+
CPA_LOGLEVEL: debug
305+
306+
- name: HTML coverage to artifacts
307+
uses: actions/upload-artifact@v3
308+
with:
309+
name: coverage_${{ matrix.nextcloud }}_${{ matrix.php-version }}_${{ matrix.mariadb-version }}
310+
path: apps/${{ env.APP_NAME }}/htmlcov
311+
if-no-files-found: error
312+
313+
- name: Upload report to Codecov
314+
uses: codecov/codecov-action@v3
315+
with:
316+
token: ${{ secrets.CODECOV_TOKEN }}
317+
file: apps/${{ env.APP_NAME }}/coverage.xml
318+
fail_ci_if_error: true
319+
verbose: true

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ dist/
7979
downloads/
8080
eggs/
8181
.eggs/
82-
lib/
8382
lib64/
8483
parts/
8584
sdist/

.nextcloudignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ tests
3737
/proto
3838
/tmp
3939
.readthedocs.yaml
40+
.codecov.yml

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Nextcloud Python Framework
22

3+
[![(Py)Analysis & Coverage](https://github.com/cloud-py-api/cloud_py_api/actions/workflows/py_analysis-coverage.yml/badge.svg)](https://github.com/cloud-py-api/cloud_py_api/actions/workflows/py_analysis-coverage.yml)
4+
![PythonVersion](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11-blue)
5+
![impl](https://img.shields.io/pypi/implementation/nc_py_api)
6+
![pypi](https://img.shields.io/pypi/v/nc_py_api.svg)
7+
38
Framework(App) for Nextcloud to develop apps, that using Python.
49

510
Consists of PHP part(**cloud_py_api app**) and a Python module(**nc-py-api**).
@@ -19,7 +24,7 @@ In your Nextcloud, simply enable the `cloud_py_api` app through the Apps managem
1924

2025
The Nextcloud `cloud_py_api` app supports Nextcloud version 25 and higher.
2126

22-
#### More information can be found on [Wiki page](https://github.com/cloud_py_api/cloud_py_api/wiki)
27+
#### More information can be found on [Wiki page](https://github.com/cloud-py-api/cloud_py_api/wiki)
2328

2429
## Maintainers
2530

nc_py_api/db_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def execute_fetchall(query: str, args=None, connection_id: int = 0) -> list:
5454
break
5555
except Exception: # noqa # pylint: disable=broad-except
5656
log.exception("DB: Exception during executing fetchall.")
57+
log.debug(query)
5758
close_connection(connection_id)
5859
return result
5960

@@ -87,5 +88,6 @@ def execute_commit(query: str, args=None, connection_id: int = 0) -> int:
8788
break
8889
except Exception: # noqa # pylint: disable=broad-except
8990
log.exception("DB: Exception during executing commit.")
91+
log.debug(query)
9092
close_connection(connection_id)
9193
return result

nc_py_api/db_connectors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def create_connection(config: dict, log_errors=True):
5858

5959

6060
def connection_test(config: dict, log_errors=False) -> bool:
61-
if environ.get("LOGLEVEL", "").upper() == "DEBUG":
61+
if environ.get("CPA_LOGLEVEL", "").upper() == "DEBUG":
6262
log_errors = True
6363
connection = create_connection(config, log_errors=log_errors)
6464
if connection is not None:

nc_py_api/db_requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def get_storages_info(num_id: Optional[int] = None) -> list:
6060
def get_mimetype_id(mimetype: str) -> int:
6161
"""For string mimetype returns it number representation."""
6262

63-
query = f"SELECT id FROM {TABLES.mimetypes} WHERE mimetype = {mimetype};"
63+
query = f"SELECT id FROM {TABLES.mimetypes} WHERE mimetype = '{mimetype}';"
6464
result = execute_fetchall(query)
6565
if not result:
6666
return 0

nc_py_api/mimetype.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .db_requests import get_mimetype_id
22

3-
DIR = get_mimetype_id("'httpd/unix-directory'")
4-
IMAGE = get_mimetype_id("'image'")
5-
VIDEO = get_mimetype_id("'video'")
3+
DIR = get_mimetype_id("httpd/unix-directory")
4+
IMAGE = get_mimetype_id("image")
5+
VIDEO = get_mimetype_id("video")

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ strict_optional = true
5050
[tool.pytest.ini_options]
5151
minversion = "6.0"
5252
testpaths = [
53-
"tests",
53+
"tests/nc_py_api",
5454
]
5555
filterwarnings = [
5656
"ignore::DeprecationWarning",
5757
]
58+
log_cli = true

setup.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ install_requires =
3232
pg8000
3333
pymysql
3434

35+
[options.extras_require]
36+
dev =
37+
pytest
38+
pre-commit
39+
pylint
40+
coverage
41+
3542
[flake8]
3643
max-line-length = 120
3744
target-version = ["py39"]

0 commit comments

Comments
 (0)