Skip to content
Snippets Groups Projects
test_end_to_end.py 6.31 KiB
Newer Older
from source.simulation_parameters import *
import os

WRITE_IN_NAOS: bool = True
# change here to you personal token in order to run the test
NAOS_TOKEN = "my token"

os.environ["WRITE_IN_NAOS"] = str(WRITE_IN_NAOS)
os.environ["NAOS_TOKEN"] = NAOS_TOKEN


def test_end_to_end_3d_ok():
    simulation_parameters_3d = SimulationParameters(
        model="gironde-xl-3d",
        project_id=899,  # https://forge.naos-cluster.tech/gpmb/modeles-telemac/fork-target/do-not-use-tests-project
        sources=['open-meteo', 'magest', 'constants-3d', 'hub-eau-3d', 'copernicus-o2', 'copernicus-temp'],
        start_date="2024-06-23T00:00:00.000000Z",
        end_date="2024-06-24T00:00:00.000000Z",
        naos_token=NAOS_TOKEN,
        write_in_naos=WRITE_IN_NAOS,
    )

    result_creation = simulation_parameters_3d.create_simulation()["error"]
    assert result_creation == 0

    with open("data/forcage_FRLIQ_ST.dat", "r") as file:
        expected_forcage_frliq = file.read()
        result_forcage_frliq = get_project_file(899, "forcage_FRLIQ_ST.dat", NAOS_TOKEN)
        assert expected_forcage_frliq == result_forcage_frliq

    with open("data/forcage_atmos_OM.dat", "r") as file:
        expected_forcage_atmos = file.read()
        result_forcage_atmos = get_project_file(899, "forcage_atmos_OM.dat", NAOS_TOKEN)
        assert expected_forcage_atmos == result_forcage_atmos

    with open("data/t3d_hydro_R45_waqtel2-gaia_T6_26012023.dat", "r") as file:
        expected_t3d = file.read()
        result_t3d = get_project_file(899, "t3d_hydro_R45_waqtel2-gaia_T6_26012023.dat", NAOS_TOKEN)
        assert expected_t3d == result_t3d


def test_end_to_end_3d_ko():
    simulation_parameters_3d = SimulationParameters(
        model="gironde-xl-3d",
        project_id=899,  # https://forge.naos-cluster.tech/gpmb/modeles-telemac/fork-target/do-not-use-tests-project
        sources=['open-meteo', 'magest', 'constants-3d', 'hub-eau-3d', 'copernicus-o2', 'copernicus-temp'],
        start_date="2022-06-23T00:00:00.000000Z",
        end_date="2022-06-24T00:00:00.000000Z",
        naos_token=NAOS_TOKEN,
        write_in_naos=WRITE_IN_NAOS,
    )

    result_creation = simulation_parameters_3d.create_simulation()["error"]
    assert result_creation == 0

    with open("data/forcage_FRLIQ_ST.dat", "r") as file:
        expected_forcage_frliq = file.read()
        result_forcage_frliq = get_project_file(899, "forcage_FRLIQ_ST.dat", NAOS_TOKEN)
        assert expected_forcage_frliq != result_forcage_frliq

    with open("data/forcage_atmos_OM.dat", "r") as file:
        expected_forcage_atmos = file.read()
        result_forcage_atmos = get_project_file(899, "forcage_atmos_OM.dat", NAOS_TOKEN)
        assert expected_forcage_atmos != result_forcage_atmos

    with open("data/t3d_hydro_R45_waqtel2-gaia_T6_26012023.dat", "r") as file:
        expected_t3d = file.read()
        result_t3d = get_project_file(899, "t3d_hydro_R45_waqtel2-gaia_T6_26012023.dat", NAOS_TOKEN)
        assert expected_t3d != result_t3d


def test_end_to_end_2d_ok():
    simulation_parameters_2d = SimulationParameters(
        model="houle-2d",
        project_id=1045,  # https://forge.naos-cluster.tech/gpmb/modeles-telemac/fork-target/do-not-use-tests-project
        sources=["constants-2d", "copernicus-sea", "hub-eau-2d", "open-meteo"],
        start_date="2024-06-23T00:00:00.000000Z",
        end_date="2024-06-24T00:00:00.000000Z",
        naos_token=NAOS_TOKEN,
        write_in_naos=WRITE_IN_NAOS,
    )

    result_creation = simulation_parameters_2d.create_simulation()["error"]
    assert result_creation == 0

    with open("data/debits.dat", "r") as file:
        expected_debits = file.read()
        result_debits = get_project_file(1045, "debits.dat", NAOS_TOKEN)
        assert expected_debits == result_debits

    with open("data/meteo_estuaire.dat", "r") as file:
        expected_meteo_estuaire = file.read()
        result_meteo_estuaire = get_project_file(1045, "meteo_estuaire.dat", NAOS_TOKEN)
        assert expected_meteo_estuaire == result_meteo_estuaire

    with open("data/T2D_GXL_instat_v8p2.cas", "r") as file:
        expected_t2d = file.read()
        result_t2d = get_project_file(1045, "T2D_GXL_instat_v8p2.cas", NAOS_TOKEN)
        assert expected_t2d == result_t2d

    with open("data/TOM_GXL_instat_v8p2.cas", "r") as file:
        expected_tom = file.read()
        result_tom = get_project_file(1045, "TOM_GXL_instat_v8p2.cas", NAOS_TOKEN)
        assert expected_tom == result_tom

    with open("data/input_tomawac.dat", "r") as file:
        expected_tomawac = file.read()
        result_tomawac = get_project_file(1045, "input_tomawac.dat", NAOS_TOKEN)
        assert expected_tomawac == result_tomawac


def test_end_to_end_2d_ko():
    simulation_parameters_2d = SimulationParameters(
        model="houle-2d",
        project_id=1045,  # https://forge.naos-cluster.tech/gpmb/modeles-telemac/fork-target/do-not-use-tests-project
        sources=["constants-2d", "copernicus-sea", "hub-eau-2d", "open-meteo"],
        start_date="2022-06-23T00:00:00.000000Z",
        end_date="2022-06-24T00:00:00.000000Z",
        naos_token=NAOS_TOKEN,
        write_in_naos=WRITE_IN_NAOS,
    )

    result_creation = simulation_parameters_2d.create_simulation()["error"]
    assert result_creation == 0

    with open("data/debits.dat", "r") as file:
        expected_debits = file.read()
        result_debits = get_project_file(1045, "debits.dat", NAOS_TOKEN)
        assert expected_debits != result_debits

    with open("data/meteo_estuaire.dat", "r") as file:
        expected_meteo_estuaire = file.read()
        result_meteo_estuaire = get_project_file(1045, "meteo_estuaire.dat", NAOS_TOKEN)
        assert expected_meteo_estuaire != result_meteo_estuaire

    with open("data/T2D_GXL_instat_v8p2.cas", "r") as file:
        expected_t2d = file.read()
        result_t2d = get_project_file(1045, "T2D_GXL_instat_v8p2.cas", NAOS_TOKEN)
        assert expected_t2d != result_t2d

    with open("data/TOM_GXL_instat_v8p2.cas", "r") as file:
        expected_tom = file.read()
        result_tom = get_project_file(1045, "TOM_GXL_instat_v8p2.cas", NAOS_TOKEN)
        assert expected_tom != result_tom

    with open("data/input_tomawac.dat", "r") as file:
        expected_tomawac = file.read()
        result_tomawac = get_project_file(1045, "input_tomawac.dat", NAOS_TOKEN)
        assert expected_tomawac != result_tomawac