Skip to content

Commit 4e194eb

Browse files
committed
Fix tests
1 parent f27523a commit 4e194eb

File tree

13 files changed

+894
-844
lines changed

13 files changed

+894
-844
lines changed

.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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ 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

.gitlab-ci.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,59 @@ variables:
22
PRODUCT_NAME: lizmap_qgis_plugin
33

44
stages:
5+
- lint
6+
- test
57
- build
68
- deploy
79

10+
# ------------
11+
# Lint
12+
# ------------
13+
14+
lint:
15+
image: ${REGISTRY_URL}/factory-ci-runner:qgis-${QGIS_FLAVOR}
16+
tags:
17+
- factory-plain
18+
stage: lint
19+
script:
20+
# No need since we do not type checking atm
21+
#- pip install --quiet -r requirements/dev.txt
22+
- 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+
858
build:
959
image: $REGISTRY_URI/factory-ci-runner:qgis-plugin-ci
1060
stage: build

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, Optional, Tuple
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
QGIS_PLUGIN_MANAGER = False
103103

104104

105+
from .. import logger
105106
from ..qt_style_sheets import NEW_FEATURE_CSS
106107
from ..server_lwc import MAX_DAYS, ServerManager
107108
from ..toolbelt.convert import ambiguous_to_bool
@@ -122,9 +123,7 @@
122123
)
123124
from ..tooltip import Tooltip
124125
from ..version_checker import VersionChecker
125-
126-
from .. import logger
127-
126+
from . import helpers
128127
from .baselayers import BaseLayersManager
129128
from .config import ConfigFileManager
130129
from .dataviz import DatavizManager
@@ -137,9 +136,6 @@
137136
from .training import TrainingManager
138137
from .webdav import WebDavManager
139138

140-
from . import helpers
141-
142-
143139
VERSION_URL = "https://raw.githubusercontent.com/3liz/lizmap-web-client/versions/versions.json"
144140
# To try a local file
145141
# VERSION_URL = 'file:///home/etienne/.local/share/QGIS/QGIS3/profiles/default/Lizmap/released_versions.json'

lizmap/plugin/layer_tree.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
List,
1313
Optional,
1414
Protocol,
15-
Union,
15+
Tuple,
1616
)
1717

1818
from qgis.core import (
@@ -887,7 +887,7 @@ def _add_group_legend(
887887
root_group = project.layerTreeRoot()
888888

889889
qgis_group = self.existing_group(root_group, label)
890-
if qgis_group:
890+
if qgis_group is not None:
891891
return qgis_group
892892

893893
new_group = root_group.addGroup(label)
@@ -896,16 +896,15 @@ def _add_group_legend(
896896
return new_group
897897

898898
@staticmethod
899-
def existing_group(
900-
root_group: QgsLayerTree,
899+
def _existing_group(
900+
root_group: Optional[QgsLayerTree],
901901
label: str,
902-
index: bool = False,
903-
) -> Optional[Union[QgsLayerTreeGroup, int]]:
902+
) -> Optional[Tuple[QgsLayerTreeGroup, int]]:
904903
"""Return the existing group in the legend if existing.
905904
906905
It will either return the group itself if found, or its index.
907906
"""
908-
if not root_group:
907+
if root_group is None:
909908
return None
910909

911910
# Iterate over all child (layers and groups)
@@ -916,19 +915,34 @@ def existing_group(
916915
i += 1
917916
continue
918917

919-
qgis_group = cast_to_group(child)
920-
qgis_group: QgsLayerTreeGroup
918+
qgis_group: QgsLayerTreeGroup = cast_to_group(child)
921919
count_children = len(qgis_group.children())
922920
if count_children >= 1 or qgis_group.name() == label:
923921
# We do not want to count empty groups
924922
# Except for the one we are looking for
925923
i += 1
926924

927925
if qgis_group.name() == label:
928-
return i if index else qgis_group
926+
return (qgis_group, i)
929927

930928
return None
931929

930+
@staticmethod
931+
def existing_group(
932+
root_group: Optional[QgsLayerTree],
933+
label: str,
934+
) -> Optional[QgsLayerTreeGroup]:
935+
g = LayerTreeManager._existing_group(root_group, label)
936+
return g[0] if g is not None else None
937+
938+
@staticmethod
939+
def existing_group_index(
940+
root_group: Optional[QgsLayerTree],
941+
label: str,
942+
) -> Optional[QgsLayerTreeGroup]:
943+
g = LayerTreeManager._existing_group(root_group, label)
944+
return g[1] if g is not None else None
945+
932946
def _add_base_layer(
933947
self,
934948
source: str,

lizmap/plugin/project.py

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

541-
if base_layers_group:
541+
if base_layers_group is not None:
542542
base_layers_group: QgsLayerTreeGroup
543543
base_layers_group.setIsMutuallyExclusive(True, -1)
544544

545-
default_background_color_index = LayerTreeManager.existing_group(
545+
default_background_color_index = LayerTreeManager.existing_group_index(
546546
base_layers_group,
547547
GroupNames.BackgroundColor,
548-
index=True,
549548
)
550549

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

0 commit comments

Comments
 (0)