Correction du téléchargemnent buggé dans /tableau + test
This commit is contained in:
+3
-1
@@ -28,6 +28,7 @@ dev = [
|
||||
"selenium",
|
||||
"webdriver-manager",
|
||||
"dash[testing]",
|
||||
"fastexcel"
|
||||
]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
@@ -38,6 +39,7 @@ testpaths = [
|
||||
"tests"
|
||||
]
|
||||
env = [
|
||||
"DATA_FILE_PARQUET_PATH=tests/test.parquet"
|
||||
"DATA_FILE_PARQUET_PATH=tests/test.parquet",
|
||||
"DEVELOPMENT=true"
|
||||
]
|
||||
addopts = "-p no:warnings"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
from typing import Any
|
||||
|
||||
import dash_bootstrap_components as dbc
|
||||
import polars as pl
|
||||
@@ -352,7 +353,7 @@ def get_top_titulaires(data):
|
||||
)
|
||||
def download_acheteur_data(
|
||||
n_clicks,
|
||||
data: [dict],
|
||||
data: list[dict[str, Any]],
|
||||
acheteur_nom: str,
|
||||
annee: str,
|
||||
):
|
||||
|
||||
@@ -326,7 +326,7 @@ def download_data(n_clicks, filter_query, sort_by, hidden_columns: list = None):
|
||||
if filter_query:
|
||||
lff = filter_table_data(lff, filter_query, "tab download")
|
||||
|
||||
if len(sort_by) > 0:
|
||||
if sort_by and len(sort_by) > 0:
|
||||
lff = sort_table_data(lff, sort_by)
|
||||
|
||||
def to_bytes(buffer):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
from typing import Any
|
||||
|
||||
import dash_bootstrap_components as dbc
|
||||
import polars as pl
|
||||
@@ -366,7 +367,7 @@ def get_top_acheteurs(data):
|
||||
)
|
||||
def download_titulaire_data(
|
||||
n_clicks,
|
||||
data: [dict],
|
||||
data: list[dict[str, Any]],
|
||||
titulaire_nom: str,
|
||||
annee: str,
|
||||
):
|
||||
|
||||
+14
-1
@@ -43,8 +43,21 @@ def test_data():
|
||||
pl.DataFrame(data).write_parquet("tests/test.parquet")
|
||||
yield path
|
||||
|
||||
if os.path.exists(path):
|
||||
os.unlink(path)
|
||||
print(path, "deleted")
|
||||
|
||||
|
||||
def pytest_setup_options():
|
||||
options = Options()
|
||||
options.add_argument("--window-size=1200,800")
|
||||
options.add_argument("--window-size=1200,1200 ")
|
||||
options.add_experimental_option(
|
||||
"prefs",
|
||||
{
|
||||
"download.default_directory": "/home/colin/git/decp.info",
|
||||
"download.prompt_for_download": False,
|
||||
"download.directory_upgrade": True,
|
||||
"safebrowsing.enabled": True,
|
||||
},
|
||||
)
|
||||
return options
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import polars as pl
|
||||
from dash.testing.composite import DashComposite
|
||||
from selenium.webdriver import Keys
|
||||
from selenium.webdriver.common.by import By
|
||||
@@ -58,3 +59,31 @@ def test_002_filter_persistence(dash_duo: DashComposite):
|
||||
filter_input.send_keys(Keys.ENTER)
|
||||
filter_input = open_page_and_check_filter_input()
|
||||
assert filter_input.get_attribute("value") == "11"
|
||||
|
||||
|
||||
def test_003_tableau_download(dash_duo: DashComposite):
|
||||
from pages.acheteur import download_acheteur_data
|
||||
from pages.tableau import download_data
|
||||
from pages.titulaire import download_titulaire_data
|
||||
from src.app import app
|
||||
|
||||
# Juste pour instancier l'app
|
||||
print(app.server.name)
|
||||
|
||||
dicts = pl.read_parquet("tests/test.parquet").to_dicts()
|
||||
|
||||
outputs = [
|
||||
download_data(1, "", [], None),
|
||||
download_acheteur_data(1, dicts, "a1", "2025"),
|
||||
download_titulaire_data(1, dicts, "t1", "2025"),
|
||||
]
|
||||
for output in outputs:
|
||||
assert isinstance(output, dict)
|
||||
for f in ["content", "filename", "type", "base64"]:
|
||||
assert f in output
|
||||
assert isinstance(output["content"], str) and len(output["content"]) > 100
|
||||
assert isinstance(output["filename"], str) and output["filename"].startswith(
|
||||
"decp_"
|
||||
)
|
||||
assert output["type"] is None
|
||||
assert output["base64"] is True
|
||||
|
||||
Reference in New Issue
Block a user