11import logging
2+ from typing import Dict
23
34from starlette import status
45
1112from tests .test_import import DATA_DIR , do_import
1213from tests .test_jobs import get_job_and_wait_until_ok
1314from tests .test_objectset_query import _prj_query
15+ from tests .test_update_prj import PROJECT_UPDATE_URL
1416
1517formulae = {"subsample_coef" : "1/ssm.sub_part" ,
1618 "total_water_volume" : "sam.tot_vol" , # Volumes are in m3 already for this data
1719 "individual_volume" : "4.0/3.0*math.pi*(math.sqrt(obj.area/math.pi)*ssm.pixel)**3" }
1820
1921
20- def test_export_sci (config , database , fastapi , caplog ):
22+ def set_formulae_in_project (fastapi , prj_id : int , prj_formulae : Dict ):
23+ from tests .test_project_vars import BODC_VARS_KEY
24+ read_url = PROJECT_QUERY_URL .format (project_id = prj_id , manage = True )
25+ rsp = fastapi .get (read_url , headers = ADMIN_AUTH )
26+ assert rsp .status_code == status .HTTP_200_OK
27+ prj_json = rsp .json ()
28+ prj_json [BODC_VARS_KEY ] = prj_formulae
29+ upd_url = PROJECT_UPDATE_URL .format (project_id = prj_id )
30+ rsp = fastapi .put (upd_url , headers = ADMIN_AUTH , json = prj_json )
31+ assert rsp .status_code == status .HTTP_200_OK
32+
33+
34+ def test_export_abundances (config , database , fastapi , caplog ):
2135 caplog .set_level (logging .FATAL )
2236
2337 # Admin imports the project, which is an export expected result
2438 from tests .test_import import test_import
2539 path = str (DATA_DIR / "ref_exports" / "bak_all_images" )
2640 prj_id = test_import (config , database , caplog , "TSV sci export" , path = path )
41+ set_formulae_in_project (fastapi , prj_id , formulae ) # Note: This is _not_ needed for abundances
2742
2843 # Validate all, otherwise empty report
2944 obj_ids = _prj_query (fastapi , CREATOR_AUTH , prj_id )
@@ -106,6 +121,8 @@ def test_export_conc_biovol(config, database, fastapi, caplog):
106121 prj_id = test_import (config , database , caplog , "SCISUM project" )
107122 # Add a sample spanning 2 days
108123 test_import_a_bit_more_skipping (config , database , caplog , "SCISUM project" )
124+ # Store computation variables
125+ set_formulae_in_project (fastapi , prj_id , formulae )
109126 # Add some data for calculations
110127 add_concentration_data (fastapi , prj_id )
111128 # Add a sample with weird data in free columns
@@ -129,8 +146,7 @@ def test_export_conc_biovol(config, database, fastapi, caplog):
129146 req = _req_tmpl .copy ()
130147 req .update ({"project_id" : prj_id ,
131148 "exp_type" : "CNC" ,
132- "sum_subtotal" : "S" ,
133- "formulae" : formulae })
149+ "sum_subtotal" : "S" })
134150 req_and_filters = {"filters" : filters ,
135151 "request" : req }
136152 rsp = fastapi .post (OBJECT_SET_EXPORT_URL , headers = ADMIN_AUTH , json = req_and_filters )
@@ -144,8 +160,7 @@ def test_export_conc_biovol(config, database, fastapi, caplog):
144160 req = _req_tmpl .copy ()
145161 req .update ({"project_id" : prj_id ,
146162 "exp_type" : "BIV" ,
147- "sum_subtotal" : "S" ,
148- "formulae" : formulae })
163+ "sum_subtotal" : "S" })
149164 req_and_filters = {"filters" : filters ,
150165 "request" : req }
151166 rsp = fastapi .post (OBJECT_SET_EXPORT_URL , headers = ADMIN_AUTH , json = req_and_filters )
@@ -163,7 +178,7 @@ def test_export_conc_biovol(config, database, fastapi, caplog):
163178 # log = get_log_file(fastapi, job_id)
164179
165180
166- def test_export_sci_filtered_by_taxo (config , database , fastapi , caplog ):
181+ def test_export_abundances_filtered_by_taxo (config , database , fastapi , caplog ):
167182 """ Simulate calls to export with an active filter """
168183 caplog .set_level (logging .FATAL )
169184
@@ -172,6 +187,7 @@ def test_export_sci_filtered_by_taxo(config, database, fastapi, caplog):
172187 from tests .test_import import test_import
173188 path = str (DATA_DIR / "ref_exports" / "bak_all_images" )
174189 prj_id = test_import (config , database , caplog , "TSV sci export filtered" , path = path )
190+ set_formulae_in_project (fastapi , prj_id , formulae ) # Not needed
175191
176192 # Validate all, otherwise empty report
177193 obj_ids = _prj_query (fastapi , CREATOR_AUTH , prj_id )
@@ -198,7 +214,7 @@ def test_export_sci_filtered_by_taxo(config, database, fastapi, caplog):
198214 download_and_check (fastapi , job_id , "abundances_by_sample_filtered_on_cat" , only_hdr = True )
199215
200216
201- def test_export_sci_filtered_by_sample (config , database , fastapi , caplog ):
217+ def test_export_abundances_filtered_by_sample (config , database , fastapi , caplog ):
202218 """ Simulate calls to export with an active filter """
203219 caplog .set_level (logging .FATAL )
204220
@@ -207,6 +223,7 @@ def test_export_sci_filtered_by_sample(config, database, fastapi, caplog):
207223 from tests .test_import import test_import
208224 path = str (DATA_DIR / "ref_exports" / "bak_all_images" )
209225 prj_id = test_import (config , database , caplog , "TSV sci export filtered" , path = path )
226+ set_formulae_in_project (fastapi , prj_id , formulae )
210227
211228 # Validate all, otherwise empty report
212229 obj_ids = _prj_query (fastapi , CREATOR_AUTH , prj_id )
0 commit comments