Skip to content

Commit

Permalink
front: add categories to e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: hamz2a <[email protected]>
  • Loading branch information
hamz2a committed Feb 19, 2025
1 parent bf88b05 commit 24f3814
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::io::Write;
use std::ops::Deref;
use std::str::FromStr;

use diesel::deserialize::FromSql;
Expand Down Expand Up @@ -32,6 +33,14 @@ impl ToSql<crate::tables::sql_types::RollingStockCategory, Pg> for RollingStockC
}
}

impl Deref for RollingStockCategory {
type Target = editoast_schemas::rolling_stock::RollingStockCategory;

fn deref(&self) -> &Self::Target {
&self.0
}
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct RollingStockCategories(pub Vec<RollingStockCategory>);

Expand All @@ -46,3 +55,11 @@ impl From<RollingStockCategories> for Vec<Option<RollingStockCategory>> {
categories.0.into_iter().map(Some).collect()
}
}

impl Deref for RollingStockCategories {
type Target = Vec<RollingStockCategory>;

fn deref(&self) -> &Self::Target {
&self.0
}
}
13 changes: 6 additions & 7 deletions editoast/src/models/rolling_stock_model.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod power_restrictions;

use std::collections::HashMap;
use std::ops::Deref;

use editoast_common::units;
use editoast_common::units::quantities::{
Expand Down Expand Up @@ -195,11 +196,10 @@ impl RollingStockModelChangeset {
if other_categories
.iter()
.flatten()
.collect::<Vec<_>>()
.contains(&primary_category)
.any(|category| category == primary_category)
{
let mut error = ValidationError::new("primary_category");
error.message = Some("The primary_category cannot be listed in other_categories for rolling stocks.".into(),);
error.message = Some("The primary_category cannot be listed in other_categories for rolling stocks.".into());
validation_errors.add("primary_category", error);
}
}
Expand Down Expand Up @@ -237,13 +237,12 @@ impl From<RollingStockModel> for RollingStock {
electrical_power_startup_time: rolling_stock_model.electrical_power_startup_time,
raise_pantograph_time: rolling_stock_model.raise_pantograph_time,
supported_signaling_systems: rolling_stock_model.supported_signaling_systems,
primary_category: rolling_stock_model.primary_category.0,
primary_category: rolling_stock_model.primary_category.deref().clone(),
other_categories: editoast_schemas::rolling_stock::RollingStockCategories(
rolling_stock_model
.other_categories
.0
.into_iter()
.map(|x| x.0)
.iter()
.map(|c| c.deref().clone())
.collect::<Vec<_>>(),
),
}
Expand Down
6 changes: 4 additions & 2 deletions front/tests/assets/rollingStock/dual-mode_rolling_stock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"railjson_version": "3.2",
"railjson_version": "3.3",
"name": "DUAL-MODE_RS_E2Ee",
"effort_curves": {
"modes": {
Expand Down Expand Up @@ -440,5 +440,7 @@
"raise_pantograph_time": 16.0,
"version": 1,
"supported_signaling_systems": ["BAL", "BAPR", "TVM300", "TVM430"],
"liveries": []
"liveries": [],
"primary_category": "FREIGHT_TRAIN",
"other_categories": []
}
6 changes: 4 additions & 2 deletions front/tests/assets/rollingStock/fast_rolling_stock.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": 480,
"railjson_version": "3.2",
"railjson_version": "3.3",
"name": "fast_rolling_stock",
"effort_curves": {
"modes": {
Expand Down Expand Up @@ -116,5 +116,7 @@
"raise_pantograph_time": null,
"version": 1,
"supported_signaling_systems": ["BAL", "BAPR"],
"liveries": []
"liveries": [],
"primary_category": "FREIGHT_TRAIN",
"other_categories": []
}
6 changes: 4 additions & 2 deletions front/tests/assets/rollingStock/improbable_rolling_stock.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": 789,
"railjson_version": "3.2",
"railjson_version": "3.3",
"name": "IMPROBABLE_RS_E2E",
"effort_curves": {
"modes": {
Expand Down Expand Up @@ -938,5 +938,7 @@
"raise_pantograph_time": 15.0,
"version": 0,
"supported_signaling_systems": ["BAL", "BAPR", "TVM300", "TVM430"],
"liveries": []
"liveries": [],
"primary_category": "FREIGHT_TRAIN",
"other_categories": []
}
6 changes: 4 additions & 2 deletions front/tests/assets/rollingStock/slow_rolling_stock.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": 479,
"railjson_version": "3.2",
"railjson_version": "3.3",
"name": "slow_rolling_stock",
"effort_curves": {
"modes": {
Expand Down Expand Up @@ -75,5 +75,7 @@
"raise_pantograph_time": null,
"version": 1,
"supported_signaling_systems": ["BAL", "BAPR"],
"liveries": []
"liveries": [],
"primary_category": "FREIGHT_TRAIN",
"other_categories": []
}
20 changes: 10 additions & 10 deletions python/osrd_schemas/osrd_schemas/rolling_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ class RollingStockCategory(str, Enum):
The list of categories that can be assigned to a rolling stock.
"""

HIGH_SPEED_TRAIN = "High Speed Train"
INTERCITY_TRAIN = "Intercity Train"
REGIONAL_TRAIN = "Regional Train"
NIGHT_TRAIN = "Night Train"
COMMUTER_TRAIN = "Commuter Train"
FREIGHT_TRAIN = "Freight Train"
FAST_FREIGHT_TRAIN = "Fast Freight Train"
TRAM_TRAIN = "Tram Train"
TOURISTIC_TRAIN = "Touristic Train"
WORK_TRAIN = "Work Train"
HIGH_SPEED_TRAIN = "HIGH_SPEED_TRAIN"
INTERCITY_TRAIN = "INTERCITY_TRAIN"
REGIONAL_TRAIN = "REGIONAL_TRAIN"
NIGHT_TRAIN = "NIGHT_TRAIN"
COMMUTER_TRAIN = "COMMUTER_TRAIN"
FREIGHT_TRAIN = "FREIGHT_TRAIN"
FAST_FREIGHT_TRAIN = "FAST_FREIGHT_TRAIN"
TRAM_TRAIN = "TRAM_TRAIN"
TOURISTIC_TRAIN = "TOURISTIC_TRAIN"
WORK_TRAIN = "WORK_TRAIN"


class ComfortType(str, Enum):
Expand Down

0 comments on commit 24f3814

Please sign in to comment.