Repository: Avaiga/taipy
File: tests/core/scenario/test_scenario_manager.py (Python)

Code before:

    _ScenarioManager._set_primary(scenario_1)
    scenario_1.tags = ["banana", "kiwi"]
    _ScenarioManager._set_primary(scenario_2)
    scenario_2.tags = ["apple", "banana"]
    _ScenarioManager._set_primary(scenario_3)
    scenario_3.tags = ["banana", "kiwi"]
    _ScenarioManager._set_primary(scenario_4)

    all_scenarios = tp.get_scenarios()
    assert not_primary_scenario in all_scenarios

    primary_scenarios = _ScenarioManager._get_primary_scenarios()
    assert not_primary_scenario not in primary_scenarios

    primary_scenarios_sorted_by_name = [scenario_2, scenario_1, scenario_3, scenario_4]
    assert primary_scenarios_sorted_by_name == _ScenarioManager._sort_scenarios(primary_scenarios, descending=False, sort_key="name")

    scenarios_with_same_config_id = [scenario_2, scenario_3, scenario_4]
    scenarios_with_same_config_id.sort(key=lambda x: x.id)
    primary_scenarios_sorted_by_config_id = [scenario_1, scenarios_with_same_config_id[0], scenarios_with_same_config_id[1], scenarios_with_same_config_id[2]]
    assert primary_scenarios_sorted_by_config_id == _ScenarioManager._sort_scenarios(primary_scenarios, descending=False, sort_key="config_id")

    scenarios_sorted_by_id = [scenario_1, scenario_2, scenario_3, scenario_4]
    scenarios_sorted_by_id.sort(key=lambda x: x.id)
    assert scenarios_sorted_by_id == _ScenarioManager._sort_scenarios(primary_scenarios, descending=False, sort_key="id")

    primary_scenarios_sorted_by_creation_date = [scenario_1, scenario_2, scenario_4,scenario_3]
    assert primary_scenarios_sorted_by_creation_date == _ScenarioManager._sort_scenarios(primary_scenarios, descending=False,
                                                                                         sort_key="creation_date")

    scenarios_with_same_tags = [scenario_1, scenario_3]
    scenarios_with_same_tags.sort(key=lambda x: x.id)
    primary_scenarios_sorted_by_tags = [scenario_4, scenario_2, scenarios_with_same_tags[0], scenarios_with_same_tags[1]]
    assert primary_scenarios_sorted_by_tags == _ScenarioManager._sort_scenarios(primary_scenarios, descending=False, sort_key="tags")

    primary_scenarios_sorted_by_name_descending_order = [scenario_4, scenario_3, scenario_1, scenario_2]
    assert primary_scenarios_sorted_by_name_descending_order == _ScenarioManager._sort_scenarios(
        primary_scenarios, descending=True, sort_key="name"
    )


def test_hard_delete_one_single_scenario_with_scenario_data_nodes():
    dn_input_config = Config.configure_data_node("my_input", "in_memory", scope=Scope.SCENARIO, default_data="testing")
    dn_output_config = Config.configure_data_node("my_output", "in_memory", scope=Scope.SCENARIO)
    task_config = Config.configure_task("task_config", print, dn_input_config, dn_output_config)
    scenario_config = Config.configure_scenario("scenario_config", [task_config])
    scenario_config.add_sequences({"sequence_config": [task_config]})

    scenario = _ScenarioManager._create(scenario_config)
    _ScenarioManager._submit(scenario.id)

Review comment (refactor):
E501 Line too long

```suggestion
    assert scenarios_sorted_by_id == _ScenarioManager._sort_scenarios(primary_scenarios,
                                                                      descending=False,
                                                                      sort_key="id")
```

Code after:
    scenario_4 = _ScenarioManager._create(scenario_2_cfg, now + timedelta(days=3), "D_scenario")

    _ScenarioManager._set_primary(scenario_1)
    scenario_1.tags = ["banana", "kiwi"]
    _ScenarioManager._set_primary(scenario_2)
    scenario_2.tags = ["apple", "banana"]
    _ScenarioManager._set_primary(scenario_3)
    scenario_3.tags = ["banana", "kiwi"]
    _ScenarioManager._set_primary(scenario_4)

    all_scenarios = tp.get_scenarios()
    assert not_primary_scenario in all_scenarios

    primary_scenarios = _ScenarioManager._get_primary_scenarios()
    assert not_primary_scenario not in primary_scenarios

    primary_scenarios_sorted_by_name = [scenario_2, scenario_1, scenario_3, scenario_4]
    assert primary_scenarios_sorted_by_name == _ScenarioManager._sort_scenarios(
        primary_scenarios, descending=False, sort_key="name"
    )

    scenarios_with_same_config_id = [scenario_2, scenario_3, scenario_4]
    scenarios_with_same_config_id.sort(key=lambda x: x.id)
    primary_scenarios_sorted_by_config_id = [
        scenario_1,
        scenarios_with_same_config_id[0],
        scenarios_with_same_config_id[1],
        scenarios_with_same_config_id[2],
    ]
    assert primary_scenarios_sorted_by_config_id == _ScenarioManager._sort_scenarios(
        primary_scenarios, descending=False, sort_key="config_id"
    )

    scenarios_sorted_by_id = [scenario_1, scenario_2, scenario_3, scenario_4]
    scenarios_sorted_by_id.sort(key=lambda x: x.id)
    assert scenarios_sorted_by_id == _ScenarioManager._sort_scenarios(
        primary_scenarios, descending=False, sort_key="id"
    )

    primary_scenarios_sorted_by_creation_date = [scenario_1, scenario_2, scenario_4, scenario_3]
    assert primary_scenarios_sorted_by_creation_date == _ScenarioManager._sort_scenarios(
        primary_scenarios, descending=False, sort_key="creation_date"
    )

    scenarios_with_same_tags = [scenario_1, scenario_3]
    scenarios_with_same_tags.sort(key=lambda x: x.id)
    primary_scenarios_sorted_by_tags = [
        scenario_4,
        scenario_2,
        scenarios_with_same_tags[0],
        scenarios_with_same_tags[1],