Skip to content

Commit 688c3fa

Browse files
committed
test launch test with bdd
1 parent 8e91bdc commit 688c3fa

File tree

9 files changed

+194
-118
lines changed

9 files changed

+194
-118
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ htmlcov/
4242
.coverage
4343
.coverage.*
4444
.cache
45+
cache
4546
nosetests.xml
4647
coverage.xml
4748
*.cover
@@ -106,6 +107,7 @@ venv.bak/
106107

107108
# vscode
108109
.vscode/
110+
.idea
109111
# config module
110112
frontend/app/module.config.ts
111113

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ create_venv:
2828
install_geonature: create_venv
2929
$(call display_cmd, Install Geonature)
3030
ifeq "$(wildcard .venv/lib/python3.12/site-packages/geonature)" ""
31-
. .venv/bin/activate && pip install "geonature[tests] @ git+https://github.com/PnX-SI/GeoNature.git@develop"
31+
.venv/bin/pip install "geonature[tests] @ git+https://github.com/PnX-SI/GeoNature.git@develop"
3232
endif
3333

3434
###########################
@@ -38,7 +38,10 @@ endif
3838
.PHONY: tests
3939
tests: install_geonature
4040
$(call display_cmd, Launch tests)
41-
. .venv/bin/activate && GEONATURE_CONFIG_FILE="config/test_config.toml" pytest -v --cov --cov-report xml
41+
.venv/bin/pip install -e .
42+
GEONATURE_CONFIG_FILE="config/test_config.toml" ./install_db_test/03b_populate_db.sh
43+
GEONATURE_CONFIG_FILE="config/test_config.toml" geonature upgrade-modules-db
44+
GEONATURE_CONFIG_FILE="config/test_config.toml" .venv/bin/pytest -vs --cov --cov-report xml
4245

4346
###########################
4447
# Run project #
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
from geonature.tests.fixtures import *
2-
from geonature.tests.fixtures import _session, app, users
2+
from geonature.tests.fixtures import _session, app, users, _app
33
from geonature.tests.test_permissions import g_permissions
4-

backend/gn_module_zh/tests/fixtures.py

Lines changed: 27 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,11 @@
11
import datetime
22
import pytest
3-
from geonature.tests.fixtures import users
43
from geonature.utils.env import db
5-
from geonature import create_app
64

7-
from gn_module_zh.model.zh_schema import TZH
8-
from shapely.geometry import Polygon
5+
from shapely import Polygon
6+
import geoalchemy2
97

10-
11-
from geonature.tests.fixtures import GeoNatureClient
12-
@pytest.fixture(scope="session", autouse=True)
13-
def app():
14-
# config["CELERY"]["task_always_eager"] = True
15-
app = create_app()
16-
app.testing = True
17-
app.test_client_class = GeoNatureClient
18-
app.config["SERVER_NAME"] = "test.geonature.fr" # required by url_for
19-
20-
# @app.before_request
21-
# def get_endpoint():
22-
# pytest.endpoint = request.endpoint
23-
24-
with app.app_context():
25-
"""
26-
Note: This may seem redundant with 'temporary_transaction' fixture.
27-
It is not as 'temporary_transaction' has a function scope.
28-
This nested transaction is useful to rollback class-scoped fixtures.
29-
Note: As we does not have a complex savepoint restart mechanism here,
30-
fixtures must commit their database changes in a nested transaction
31-
(i.e. in a with db.session.begin_nested() block).
32-
"""
33-
transaction = db.session.begin_nested() # execute tests in a savepoint
34-
yield app
35-
transaction.rollback() # rollback all database changes
8+
import uuid
369

3710
def create_zh(
3811
main_name,
@@ -41,13 +14,14 @@ def create_zh(
4114
id_role,
4215
zh_date,
4316
uuid_id_lim_list,
44-
sdage,
17+
id_sdage,
4518
polygon,
4619
zh_area,
47-
main_id_rb,
4820
**kwargs,
4921
):
50-
return TZH(
22+
# Import here because TZH class need to be imported after "app instanced"
23+
from gn_module_zh.model.zh_schema import TZH
24+
zh = TZH(
5125
main_name=main_name,
5226
code=code,
5327
id_org=id_org,
@@ -56,101 +30,55 @@ def create_zh(
5630
create_date=zh_date,
5731
update_date=zh_date,
5832
id_lim_list=uuid_id_lim_list,
59-
id_sdage=sdage,
33+
id_sdage=id_sdage,
6034
geom=polygon,
6135
area=zh_area,
62-
main_id_rb=main_id_rb,
6336
)
37+
return zh
6438

65-
@pytest.fixture()
66-
def zh_data(app, users, datasets, source, sources_modules):
67-
polygon1 = Polygon([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
68-
polygon2 = Polygon([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
69-
polygon3 = Polygon([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
70-
date_1 = datetime.datetime(2024, 10, 2, 11, 22, 33)
71-
date_2 = datetime.datetime(2024, 10, 3, 8, 9, 10)
72-
date_3 = datetime.datetime(2024, 10, 4, 17, 4, 9)
73-
date_4 = datetime.datetime(2024, 10, 5, 22, 22, 22)
74-
altitude_1 = 800
75-
altitude_2 = 900
76-
altitude_3 = 1000
77-
altitude_4 = 1100
78-
39+
@pytest.fixture(scope="function")
40+
def zh_data(users):
41+
coords = ((0., 0.), (0., 1.), (1., 1.), (1., 0.), (0., 0.))
42+
polygon = Polygon(coords)
43+
date = datetime.datetime(2024, 10, 2, 11, 22, 33)
44+
id_sdage = 967
45+
user = users["self_user"]
7946
data = {}
8047
with db.session.begin_nested():
8148
for (
8249
main_name,
8350
code,
8451
id_org,
85-
# id_role,
52+
id_role,
8653
zh_date,
8754
uuid_id_lim_list,
88-
# sdage,
55+
id_sdage,
8956
geom,
9057
zh_area,
91-
main_id_rb,
9258
) in [
9359
(
9460
"zh1",
9561
"05CEN0189",
96-
polygon1,
97-
# datasets["own_dataset"],
98-
"zh1",
99-
# sources_modules[0],
100-
date_1,
101-
date_1,
102-
altitude_1,
103-
altitude_1,
104-
),
105-
(
106-
"zh2",
107-
"05CEEP0163",
108-
polygon2,
109-
# datasets["own_dataset"],
110-
"zh2",
111-
# sources_modules[0],
112-
date_1,
113-
date_4,
114-
altitude_1,
115-
altitude_4,
116-
),
117-
(
118-
"zh3",
119-
"83CEEV0001",
120-
polygon3,
121-
# datasets["own_dataset"],
122-
"zh3",
123-
# sources_modules[1],
124-
date_2,
125-
date_3,
126-
altitude_2,
127-
altitude_3,
128-
),
129-
(
130-
"zh4",
131-
"84PNRL0296",
132-
polygon3,
133-
# datasets["own_dataset"],
134-
"zh3",
135-
sources_modules[1],
136-
date_2,
137-
date_3,
138-
altitude_2,
139-
altitude_3,
62+
2, # id_org = 2 (not dynamic) because not same table bib_organismes used with the users
63+
user.id_role,
64+
date,
65+
uuid.uuid4(),
66+
id_sdage,
67+
geoalchemy2.shape.from_shape(polygon),
68+
polygon.area,
14069
),
14170
]:
14271
kwargs = {}
14372
s = create_zh(
14473
main_name,
14574
code,
14675
id_org,
147-
# id_role,
76+
id_role,
14877
zh_date,
14978
uuid_id_lim_list,
150-
# sdage,
79+
id_sdage,
15180
geom,
15281
zh_area,
153-
main_id_rb,
15482
**kwargs,
15583
)
15684
db.session.add(s)

backend/gn_module_zh/tests/test_bdd.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@
33
from flask import url_for
44

55
from geonature.tests.fixtures import *
6-
76
from .fixtures import *
87

9-
@pytest.mark.usefixtures("client_class", "temporary_transaction")
8+
@pytest.mark.usefixtures("client_class")
109
class TestBdd:
11-
def test_no_zh(self, app, users):
12-
print("user => ", users)
10+
def test_no_zh(self, users):
1311
set_logged_user(self.client, users["self_user"])
1412
response = self.client.get(url_for("pr_zh.get_zh"))
1513
assert response.status_code == 200
1614
data = response.get_json()
1715
assert len(data["items"]["features"]) == 0
1816

1917

20-
def test_add_zh(self, app, users, synthese_data):
18+
def test_add_zh(self, users, zh_data):
2119
set_logged_user(self.client, users["self_user"])
22-
2320
response = self.client.get(url_for("pr_zh.get_zh"))
2421
assert response.status_code == 200
2522
data = response.get_json()
26-
assert len(data["items"]["features"]) == 0
23+
assert len(data["items"]["features"]) > 0

config/settings.ini

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
## Fichier de configuration utilisé lors de l'installation de GeoNature
2+
3+
# Set mode to 'dev' to install GeoNature in dev mode
4+
MODE=dev
5+
6+
# Langue du serveur
7+
# valeur possible : fr_FR.UTF-8, en_US.utf8
8+
# locale -a pour voir la liste des locales disponible
9+
my_local=en_US.utf8
10+
11+
# URL Configuration
12+
###################
13+
14+
# My host URL or IP, starting with http and with / at the end
15+
my_url=http://127.0.0.1:4200/
16+
17+
18+
# PostgreSQL Configuration
19+
##########################
20+
21+
# Drop eventual existing database during installation
22+
drop_apps_db=true
23+
24+
# DB host
25+
# Attention les scripts d'installation automatique (install_db.sh et install_all.sh) ne fonctionneront
26+
# que si votre BDD est installée en local (localhost). Si vous souhaitez installer votre BDD sur un autre serveur,
27+
# les scripts n'auront pas les droits suffisants pour créer la BDD sur un autre serveur et cela devra être fait manuellement.
28+
db_host=127.0.0.1
29+
30+
# PostgreSQL port
31+
db_port=5432
32+
33+
# GeoNature database name
34+
db_name=geonature2db
35+
#geonatureTestInstall
36+
37+
# GeoNature database owner username
38+
user_pg=geonatadmin
39+
40+
# GeoNature database owner password
41+
user_pg_pass=geonatpasswd
42+
43+
# Local projection SRID
44+
srid_local=2154
45+
46+
# Default language (locale)
47+
# Availaible language value : fr
48+
default_language=fr
49+
50+
# Permet l'installation des couches SIG des communes et départements
51+
# Seules les couches de métropole en 2154 sont fournies (false conseillé hors métropole)
52+
install_sig_layers=false
53+
54+
# Installe les grilles INPN (1, 5 et 10km)
55+
install_grid_layer=false
56+
57+
# Install default French DEM (Mainland France only - BD alti 250m))
58+
install_default_dem=false
59+
60+
# Vectorise dem raster for more performance. This will increse installation duration and take more disk space
61+
vectorise_dem=false
62+
63+
# Insert sample data (available only in Mainland France with srid_local=2154
64+
add_sample_data=true
65+
66+
# Insert INPN sensitivity referential (will force installation of departments and regions)
67+
install_ref_sensitivity=false
68+
69+
#### Modules GeoNature ####
70+
71+
# Installer le module validation
72+
install_module_validation=true
73+
# Installer le module Occurrence d'habitat
74+
install_module_occhab=true
75+
76+
77+
# Taxonomy, Users and Nomenclatures configuration
78+
#################################################
79+
80+
# Les scripts SQL de création des schémas 'utilisateurs', 'taxonomie' et 'nomenclature' de GeoNature sont téléchargés depuis le dépôt github des projets UsersHub et TaxHub
81+
# Les trois paramètres ci-dessous visent à indiquer dans quelle version (release, branche ou tag) les scripts doivent être récupérés
82+
83+
# Est ce que le schéma utilisateurs doit être installé ? (mettre à 'non' que si vos avez un schéma utilisateur dans une autre BDD et que vous avez déjàmis en place un mecanisme de foreign data wrapper)
84+
install_usershub_schema=true
85+
# Définir dans quelle version de UsersHub (release, branche ou tag) prendre le code SQL permettant la création du schéma utilisateurs de la base de données de GeoNature
86+
usershub_release=2.2.2
87+
88+
;# Définir dans quelle version de TaxHub (release, branche ou tag) prendre le code SQL permettant la création du schéma taxonomie de la base de données de GeoNature
89+
;taxhub_release=1.9.4
90+
91+
# Proxy - si le serveur sur lequel se trouve GeoNature se trouve derrière un proxy
92+
# laisser vide si vous n'avez pas de proxy
93+
proxy_http=
94+
proxy_https=

docker-compose.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
services:
2+
postgres:
3+
image: postgis/postgis:13-3.2
4+
# env_file:
5+
# - .env
6+
environment:
7+
- POSTGRES_HOST_AUTH_METHOD=trust
8+
- POSTGRES_DB=geonature2db
9+
- POSTGRES_PASSWORD=geonatpasswd
10+
- POSTGRES_USER=geonatadmin
11+
ports:
12+
- "5432:5432"
13+
volumes:
14+
- postgres:/var/lib/postgresql/data
15+
healthcheck:
16+
test: ["CMD", "pg_isready", "-U", "geonatadmin", "-d", "geonature2db"]
17+
interval: 10s
18+
retries: 5
19+
start_period: 30s
20+
timeout: 5s
21+
22+
volumes:
23+
postgres:

0 commit comments

Comments
 (0)