Skip to content

Commit 8ecea1c

Browse files
committed
editoast: refactor rolling stock fixtures
1 parent 2c7717e commit 8ecea1c

File tree

4 files changed

+28
-36
lines changed

4 files changed

+28
-36
lines changed

editoast/src/fixtures.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,19 @@ pub mod tests {
7777
Data::new(pool)
7878
}
7979

80+
pub fn get_fast_rolling_stock(name: &str) -> RollingStockModel {
81+
let mut rs: RollingStockModel =
82+
serde_json::from_str(include_str!("./tests/example_rolling_stock_1.json"))
83+
.expect("Unable to parse");
84+
rs.name = Some(name.to_string());
85+
rs
86+
}
87+
8088
pub async fn named_fast_rolling_stock(
8189
name: &str,
8290
db_pool: Data<DbPool>,
8391
) -> TestFixture<RollingStockModel> {
84-
let mut rs = serde_json::from_str::<RollingStockModel>(include_str!(
85-
"./tests/example_rolling_stock_1.json"
86-
))
87-
.expect("Unable to parse");
88-
rs.name = Some(name.to_string());
92+
let rs = get_fast_rolling_stock(name);
8993
TestFixture::create(rs, db_pool).await
9094
}
9195

@@ -95,15 +99,20 @@ pub mod tests {
9599
named_fast_rolling_stock("fast_rolling_stock", db_pool).await
96100
}
97101

98-
pub async fn named_other_rolling_stock(
99-
name: &str,
100-
db_pool: Data<DbPool>,
101-
) -> TestFixture<RollingStockModel> {
102-
let mut rs = serde_json::from_str::<RollingStockModel>(include_str!(
102+
pub fn get_other_rolling_stock(name: &str) -> RollingStockModel {
103+
let mut rs: RollingStockModel = serde_json::from_str(include_str!(
103104
"./tests/example_rolling_stock_2_energy_sources.json"
104105
))
105106
.expect("Unable to parse");
106107
rs.name = Some(name.to_string());
108+
rs
109+
}
110+
111+
pub async fn named_other_rolling_stock(
112+
name: &str,
113+
db_pool: Data<DbPool>,
114+
) -> TestFixture<RollingStockModel> {
115+
let rs = get_other_rolling_stock(name);
107116
TestFixture::create(rs, db_pool).await
108117
}
109118

editoast/src/models/rolling_stock/mod.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ impl From<RollingStockModel> for RollingStock {
241241
#[cfg(test)]
242242
pub mod tests {
243243
use crate::error::InternalError;
244-
use crate::fixtures::tests::{db_pool, named_fast_rolling_stock, named_other_rolling_stock};
244+
use crate::fixtures::tests::{
245+
db_pool, get_other_rolling_stock, named_fast_rolling_stock, named_other_rolling_stock,
246+
};
245247
use crate::models::{Retrieve, Update};
246248
use crate::views::rolling_stocks::RollingStockError;
247249
use crate::DbPool;
@@ -251,23 +253,6 @@ pub mod tests {
251253
use super::RollingStockModel;
252254
use actix_web::web::Data;
253255

254-
pub fn get_fast_rolling_stock(name: &str) -> RollingStockModel {
255-
let mut rs: RollingStockModel =
256-
serde_json::from_str(include_str!("../../tests/example_rolling_stock_1.json"))
257-
.expect("Unable to parse");
258-
rs.name = Some(name.to_string());
259-
rs
260-
}
261-
262-
pub fn get_other_rolling_stock(name: &str) -> RollingStockModel {
263-
let mut rs: RollingStockModel = serde_json::from_str(include_str!(
264-
"../../tests/example_rolling_stock_2_energy_sources.json"
265-
))
266-
.expect("Unable to parse");
267-
rs.name = Some(name.to_string());
268-
rs
269-
}
270-
271256
pub fn get_invalid_effort_curves() -> &'static str {
272257
include_str!("../../tests/example_rolling_stock_3.json")
273258
}

editoast/src/views/rolling_stocks/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,10 @@ pub mod tests {
487487
UsageResponse,
488488
};
489489
use crate::fixtures::tests::{
490-
db_pool, named_fast_rolling_stock, named_other_rolling_stock, train_schedule_with_scenario,
491-
};
492-
use crate::models::rolling_stock::tests::{
493-
get_fast_rolling_stock, get_invalid_effort_curves, get_other_rolling_stock,
490+
db_pool, get_fast_rolling_stock, get_other_rolling_stock, named_fast_rolling_stock,
491+
named_other_rolling_stock, train_schedule_with_scenario,
494492
};
493+
use crate::models::rolling_stock::tests::get_invalid_effort_curves;
495494
use crate::models::{Delete, RollingStockModel};
496495
use crate::views::tests::create_test_service;
497496
use crate::{assert_editoast_error_type, assert_status_and_read, DbPool};

editoast/src/views/timetable.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,10 @@ pub mod test {
498498

499499
use crate::{
500500
assert_status_and_read,
501-
fixtures::tests::{db_pool, train_with_simulation_output_fixture_set},
502-
models::{
503-
rolling_stock::tests::get_other_rolling_stock, train_schedule::TrainScheduleValidation,
504-
TimetableWithSchedulesDetails,
501+
fixtures::tests::{
502+
db_pool, get_other_rolling_stock, train_with_simulation_output_fixture_set,
505503
},
504+
models::{train_schedule::TrainScheduleValidation, TimetableWithSchedulesDetails},
506505
views::tests::create_test_service,
507506
};
508507

0 commit comments

Comments
 (0)