Skip to content

Commit 8ebfe52

Browse files
committed
front: add categories to e2e tests
Signed-off-by: hamz2a <atrari.hamza@gmail.com>
1 parent 5504391 commit 8ebfe52

File tree

7 files changed

+49
-25
lines changed

7 files changed

+49
-25
lines changed

editoast/editoast_models/src/rolling_stock/rolling_stock_category.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::io::Write;
2+
use std::ops::Deref;
23
use std::str::FromStr;
34

45
use diesel::deserialize::FromSql;
@@ -32,6 +33,14 @@ impl ToSql<crate::tables::sql_types::RollingStockCategory, Pg> for RollingStockC
3233
}
3334
}
3435

36+
impl Deref for RollingStockCategory {
37+
type Target = editoast_schemas::rolling_stock::RollingStockCategory;
38+
39+
fn deref(&self) -> &Self::Target {
40+
&self.0
41+
}
42+
}
43+
3544
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
3645
pub struct RollingStockCategories(pub Vec<RollingStockCategory>);
3746

@@ -46,3 +55,11 @@ impl From<RollingStockCategories> for Vec<Option<RollingStockCategory>> {
4655
categories.0.into_iter().map(Some).collect()
4756
}
4857
}
58+
59+
impl Deref for RollingStockCategories {
60+
type Target = Vec<RollingStockCategory>;
61+
62+
fn deref(&self) -> &Self::Target {
63+
&self.0
64+
}
65+
}

editoast/src/models/rolling_stock_model.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod power_restrictions;
22

33
use std::collections::HashMap;
4+
use std::ops::Deref;
45

56
use editoast_common::units;
67
use editoast_common::units::quantities::{
@@ -195,11 +196,10 @@ impl RollingStockModelChangeset {
195196
if other_categories
196197
.iter()
197198
.flatten()
198-
.collect::<Vec<_>>()
199-
.contains(&primary_category)
199+
.any(|category| category == primary_category)
200200
{
201201
let mut error = ValidationError::new("primary_category");
202-
error.message = Some("The primary_category cannot be listed in other_categories for rolling stocks.".into(),);
202+
error.message = Some("The primary_category cannot be listed in other_categories for rolling stocks.".into());
203203
validation_errors.add("primary_category", error);
204204
}
205205
}
@@ -237,13 +237,12 @@ impl From<RollingStockModel> for RollingStock {
237237
electrical_power_startup_time: rolling_stock_model.electrical_power_startup_time,
238238
raise_pantograph_time: rolling_stock_model.raise_pantograph_time,
239239
supported_signaling_systems: rolling_stock_model.supported_signaling_systems,
240-
primary_category: rolling_stock_model.primary_category.0,
240+
primary_category: rolling_stock_model.primary_category.deref().clone(),
241241
other_categories: editoast_schemas::rolling_stock::RollingStockCategories(
242242
rolling_stock_model
243243
.other_categories
244-
.0
245-
.into_iter()
246-
.map(|x| x.0)
244+
.iter()
245+
.map(|c| c.deref().clone())
247246
.collect::<Vec<_>>(),
248247
),
249248
}

front/tests/assets/rollingStock/dual-mode_rolling_stock.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"railjson_version": "3.2",
2+
"railjson_version": "3.3",
33
"name": "DUAL-MODE_RS_E2Ee",
44
"effort_curves": {
55
"modes": {
@@ -440,5 +440,7 @@
440440
"raise_pantograph_time": 16.0,
441441
"version": 1,
442442
"supported_signaling_systems": ["BAL", "BAPR", "TVM300", "TVM430"],
443-
"liveries": []
443+
"liveries": [],
444+
"primary_category": "FREIGHT_TRAIN",
445+
"other_categories": []
444446
}

front/tests/assets/rollingStock/fast_rolling_stock.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": 480,
3-
"railjson_version": "3.2",
3+
"railjson_version": "3.3",
44
"name": "fast_rolling_stock",
55
"effort_curves": {
66
"modes": {
@@ -116,5 +116,7 @@
116116
"raise_pantograph_time": null,
117117
"version": 1,
118118
"supported_signaling_systems": ["BAL", "BAPR"],
119-
"liveries": []
119+
"liveries": [],
120+
"primary_category": "FREIGHT_TRAIN",
121+
"other_categories": []
120122
}

front/tests/assets/rollingStock/improbable_rolling_stock.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": 789,
3-
"railjson_version": "3.2",
3+
"railjson_version": "3.3",
44
"name": "IMPROBABLE_RS_E2E",
55
"effort_curves": {
66
"modes": {
@@ -938,5 +938,7 @@
938938
"raise_pantograph_time": 15.0,
939939
"version": 0,
940940
"supported_signaling_systems": ["BAL", "BAPR", "TVM300", "TVM430"],
941-
"liveries": []
941+
"liveries": [],
942+
"primary_category": "FREIGHT_TRAIN",
943+
"other_categories": []
942944
}

front/tests/assets/rollingStock/slow_rolling_stock.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": 479,
3-
"railjson_version": "3.2",
3+
"railjson_version": "3.3",
44
"name": "slow_rolling_stock",
55
"effort_curves": {
66
"modes": {
@@ -75,5 +75,7 @@
7575
"raise_pantograph_time": null,
7676
"version": 1,
7777
"supported_signaling_systems": ["BAL", "BAPR"],
78-
"liveries": []
78+
"liveries": [],
79+
"primary_category": "FREIGHT_TRAIN",
80+
"other_categories": []
7981
}

python/osrd_schemas/osrd_schemas/rolling_stock.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ class RollingStockCategory(str, Enum):
2121
The list of categories that can be assigned to a rolling stock.
2222
"""
2323

24-
HIGH_SPEED_TRAIN = "High Speed Train"
25-
INTERCITY_TRAIN = "Intercity Train"
26-
REGIONAL_TRAIN = "Regional Train"
27-
NIGHT_TRAIN = "Night Train"
28-
COMMUTER_TRAIN = "Commuter Train"
29-
FREIGHT_TRAIN = "Freight Train"
30-
FAST_FREIGHT_TRAIN = "Fast Freight Train"
31-
TRAM_TRAIN = "Tram Train"
32-
TOURISTIC_TRAIN = "Touristic Train"
33-
WORK_TRAIN = "Work Train"
24+
HIGH_SPEED_TRAIN = "HIGH_SPEED_TRAIN"
25+
INTERCITY_TRAIN = "INTERCITY_TRAIN"
26+
REGIONAL_TRAIN = "REGIONAL_TRAIN"
27+
NIGHT_TRAIN = "NIGHT_TRAIN"
28+
COMMUTER_TRAIN = "COMMUTER_TRAIN"
29+
FREIGHT_TRAIN = "FREIGHT_TRAIN"
30+
FAST_FREIGHT_TRAIN = "FAST_FREIGHT_TRAIN"
31+
TRAM_TRAIN = "TRAM_TRAIN"
32+
TOURISTIC_TRAIN = "TOURISTIC_TRAIN"
33+
WORK_TRAIN = "WORK_TRAIN"
3434

3535

3636
class ComfortType(str, Enum):

0 commit comments

Comments
 (0)