Skip to content

Commit b15ca58

Browse files
committed
Fix tests
1 parent 9600da6 commit b15ca58

13 files changed

Lines changed: 935 additions & 886 deletions

File tree

.docker/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
qgis:
3-
user: ${UID}:${GID}
43
image: ${QGIS_IMAGE_TAG}
4+
user: ${UID}:${GID}
55
network_mode: host
66
container_name: qgis-lizmap-tests
77
environment:

.docker/run-tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ python3 -m venv $VENV --system-site-package
1313
echo "Installing requirements..."
1414
$VENV/bin/pip install -q --no-cache -r requirements/tests.txt
1515

16+
export PYTHONPATH="/usr/share/qgis/python/:$PYTHONPATH"
17+
1618
cd tests && $VENV/bin/python -m pytest -v
1719

1820

.github/workflows/tests.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ jobs:
1616
python-version: "3.12"
1717
architecture: x64
1818
cache: "pip"
19-
cache-dependency-path: "requirements/dev.txt"
19+
cache-dependency-path: "requirements/lint.txt"
2020

2121
- name: Install Python requirements
2222
run: pip install --quiet -r requirements/lint.txt
2323

2424
- name: Run linter
25-
run: ruff check --preview --output-format=concise lizmap
25+
run: ruff check --output-format=concise lizmap
2626

2727
- name: Run security check
2828
run: bandit -r lizmap -ll
@@ -39,6 +39,7 @@ jobs:
3939
"3.34",
4040
"3.40",
4141
"3.44",
42+
"4.0",
4243
]
4344
steps:
4445

.gitlab-ci.yml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,58 @@ variables:
33

44
stages:
55
- lint
6+
- test
67
- build
78
- deploy
89

10+
# ------------
11+
# Lint
12+
# ------------
13+
914
lint:
10-
image: $REGISTRY_URI/factory-ci-runner:qgis-ltr
11-
stage: lint
15+
image: ${REGISTRY_URL}/factory-ci-runner:qgis-${QGIS_FLAVOR}
1216
tags:
1317
- factory-plain
18+
stage: lint
1419
script:
20+
# No need since we do not type checking atm
21+
#- pip install --quiet -r requirements/dev.txt
1522
- make lint
23+
parallel:
24+
matrix:
25+
- QGIS_FLAVOR: [ "ltr", "release" ]
26+
27+
# ------------
28+
# Tests
29+
# ------------
30+
31+
.tests:
32+
image: ${REGISTRY_URL}/factory-ci-runner:factory-ci
33+
tags:
34+
- factory-dind
35+
stage: test
36+
script:
37+
- make docker-test QGIS_VERSION=$QGIS_FLAVOR
38+
39+
qgis-tests:
40+
extends: .tests
41+
parallel:
42+
matrix:
43+
- QGIS_FLAVOR: [
44+
"3.34",
45+
"3.40",
46+
"3.44",
47+
"4.0",
48+
]
49+
50+
51+
# NOTE: Following jobs are triggered only on RELEASE_BRANCH == "true"
52+
53+
#
54+
# Packages
55+
#
56+
57+
>>>>>>> 6c46c59 (Fix tests)
1658

1759
build:
1860
image: $REGISTRY_URI/factory-ci-runner:qgis-plugin-ci

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ test:
8686
ifdef REGISTRY_URL
8787
REGISTRY_PREFIX=$(REGISTRY_URL)/
8888
else
89-
REGISTRY_PREFIX=3liz
89+
REGISTRY_PREFIX=3liz/
9090
endif
9191

9292
QGIS_VERSION ?= 3.44
@@ -100,7 +100,7 @@ export GID=$(shell id -g)
100100

101101
docker-test:
102102
set -e; \
103-
cd .docker;
103+
cd .docker; \
104104
docker compose up \
105105
--quiet-pull \
106106
--abort-on-container-exit \

lizmap/dialogs/server_wizard.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import TYPE_CHECKING
99

1010
from qgis.core import (
11+
Qgis,
1112
QgsAbstractDatabaseProviderConnection,
1213
QgsApplication,
1314
QgsAuthMethodConfig,
@@ -874,6 +875,11 @@ def __init__(
874875
self.setPage(WizardPages.CreateNewFolderDav, CreateNewFolderDavPage())
875876
self.setPage(WizardPages.LizmapNewRepository, LizmapNewRepositoryPage())
876877

878+
# TODO: If these methods raises an exception while called
879+
# by the Qt framework this cause a "Fatal Python error"
880+
# These method should be bounded by try/except when used from
881+
# Qt framework.
882+
877883
@logger.log_function
878884
def validateCurrentPage(self):
879885
"""Specific rules for page validation. """
@@ -1090,7 +1096,12 @@ def request_check_url(self, url: str, login: str, password: str) -> tuple[bool,
10901096
net_req.setUrl(QUrl(url))
10911097
token = b64encode(f"{login}:{password}".encode())
10921098
net_req.setRawHeader(b"Authorization", b"Basic %s" % token)
1093-
net_req.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
1099+
# NOTE: According to QT6 doc this is enabled by default
1100+
# See https://doc.qt.io/archives/qt-5.15/qnetworkrequest.html#RedirectPolicy-enum
1101+
# See https://doc.qt.io/qt-6/network-changes-qt6.html#redirect-policies
1102+
if Qgis.versionInt() < 40000:
1103+
net_req.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
1104+
10941105
request = QgsBlockingNetworkRequest()
10951106
error = request.get(net_req)
10961107
if error == QgsBlockingNetworkRequest.ErrorCode.NetworkError:

lizmap/plugin/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def save_cfg_file(
322322
self.project.layerTreeRoot(),
323323
GroupNames.BaseLayers,
324324
)
325-
if qgis_group and self.lwc_version >= LwcVersions.Lizmap_3_7:
325+
if qgis_group is not None and self.lwc_version >= LwcVersions.Lizmap_3_7:
326326
self.disable_legacy_empty_base_layer()
327327

328328
if self.version_checker:

lizmap/plugin/core.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
QGIS_PLUGIN_MANAGER = False
108108

109109

110+
from .. import logger
110111
from ..qt_style_sheets import NEW_FEATURE_CSS
111112
from ..server_lwc import MAX_DAYS, ServerManager
112113
from ..toolbelt.convert import ambiguous_to_bool
@@ -127,9 +128,7 @@
127128
)
128129
from ..tooltip import Tooltip
129130
from ..version_checker import VersionChecker
130-
131-
from .. import logger
132-
131+
from . import helpers
133132
from .baselayers import BaseLayersManager
134133
from .config import ConfigFileManager
135134
from .dataviz import DatavizManager

lizmap/plugin/layer_tree.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
"""Layer tree panel configuration"""
2-
from __future__ import annotations
3-
42
import contextlib
53
import hashlib
64
import json
@@ -10,6 +8,7 @@
108
TYPE_CHECKING,
119
Any,
1210
Protocol,
11+
Tuple,
1312
)
1413

1514
from qgis.core import (
@@ -883,7 +882,7 @@ def _add_group_legend(
883882
root_group = project.layerTreeRoot()
884883

885884
qgis_group = self.existing_group(root_group, label)
886-
if qgis_group:
885+
if qgis_group is not None:
887886
return qgis_group
888887

889888
new_group = root_group.addGroup(label)
@@ -892,16 +891,16 @@ def _add_group_legend(
892891
return new_group
893892

894893
@staticmethod
895-
def existing_group(
896-
root_group: QgsLayerTree,
894+
def _existing_group(
895+
root_group: Optional[QgsLayerTree],
897896
label: str,
898897
index: bool = False,
899-
) -> QgsLayerTreeGroup | int | None:
898+
) -> Optional[Tuple[QgsLayerTreeGroup, int]]:
900899
"""Return the existing group in the legend if existing.
901900
902901
It will either return the group itself if found, or its index.
903902
"""
904-
if not root_group:
903+
if root_group is None:
905904
return None
906905

907906
# Iterate over all child (layers and groups)
@@ -912,19 +911,34 @@ def existing_group(
912911
i += 1
913912
continue
914913

915-
qgis_group = cast_to_group(child)
916-
qgis_group: QgsLayerTreeGroup
914+
qgis_group: QgsLayerTreeGroup = cast_to_group(child)
917915
count_children = len(qgis_group.children())
918916
if count_children >= 1 or qgis_group.name() == label:
919917
# We do not want to count empty groups
920918
# Except for the one we are looking for
921919
i += 1
922920

923921
if qgis_group.name() == label:
924-
return i if index else qgis_group
922+
return (qgis_group, i)
925923

926924
return None
927925

926+
@staticmethod
927+
def existing_group(
928+
root_group: Optional[QgsLayerTree],
929+
label: str,
930+
) -> Optional[QgsLayerTreeGroup]:
931+
g = LayerTreeManager._existing_group(root_group, label)
932+
return g[0] if g is not None else None
933+
934+
@staticmethod
935+
def existing_group_index(
936+
root_group: Optional[QgsLayerTree],
937+
label: str,
938+
) -> Optional[QgsLayerTreeGroup]:
939+
g = LayerTreeManager._existing_group(root_group, label)
940+
return g[1] if g is not None else None
941+
928942
def _add_base_layer(
929943
self,
930944
source: str,

lizmap/plugin/project.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,13 @@ def project_config_file(
536536
GroupNames.BaseLayers,
537537
)
538538

539-
if base_layers_group:
539+
if base_layers_group is not None:
540540
base_layers_group: QgsLayerTreeGroup
541541
base_layers_group.setIsMutuallyExclusive(True, -1)
542542

543-
default_background_color_index = LayerTreeManager.existing_group(
543+
default_background_color_index = LayerTreeManager.existing_group_index(
544544
base_layers_group,
545545
GroupNames.BackgroundColor,
546-
index=True,
547546
)
548547

549548
if default_background_color_index is not None and default_background_color_index >= 0:

0 commit comments

Comments
 (0)