Skip to content

Commit 4e04a73

Browse files
committed
editoast: remove test fixtures
1 parent c180ab9 commit 4e04a73

File tree

5 files changed

+52
-190
lines changed

5 files changed

+52
-190
lines changed

editoast/src/fixtures.rs

-166
This file was deleted.

editoast/src/main.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ extern crate diesel;
44
mod client;
55
mod core;
66
mod error;
7-
mod fixtures;
87
mod generated_data;
98
mod infra_cache;
109
mod map;
@@ -896,12 +895,12 @@ impl CliError {
896895
mod tests {
897896
use super::*;
898897

899-
use crate::fixtures::tests::get_fast_rolling_stock_schema;
900-
use crate::fixtures::tests::get_trainschedule_json_array;
901898
use crate::modelsv2::fixtures::create_electrical_profile_set;
902899
use crate::modelsv2::RollingStockModel;
903900

904901
use editoast_models::DbConnectionPoolV2;
902+
use modelsv2::fixtures::get_fast_rolling_stock_schema;
903+
use modelsv2::fixtures::get_trainschedule_json_array;
905904
use modelsv2::DeleteStatic;
906905
use rand::distributions::Alphanumeric;
907906
use rand::{thread_rng, Rng};

editoast/src/modelsv2/fixtures.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ use std::io::Cursor;
22
use std::ops::DerefMut;
33

44
use chrono::Utc;
5+
use editoast_models::DbConnection;
6+
use editoast_models::DbConnectionPool;
7+
use editoast_models::DbConnectionPoolV2;
58
use editoast_schemas::infra::Direction;
69
use editoast_schemas::infra::DirectionalTrackRange;
710
use editoast_schemas::infra::InfraObject;
811
use editoast_schemas::infra::RailJson;
912
use editoast_schemas::primitives::OSRDObject;
13+
use editoast_schemas::rolling_stock::RollingStock;
1014
use editoast_schemas::train_schedule::TrainScheduleBase;
1115
use postgis_diesel::types::LineString;
1216

1317
use crate::infra_cache::operation::create::apply_create_operation;
14-
1518
use crate::modelsv2::prelude::*;
1619
use crate::modelsv2::rolling_stock_livery::RollingStockLiveryModel;
1720
use crate::modelsv2::timetable::Timetable;
@@ -27,9 +30,6 @@ use crate::modelsv2::Tags;
2730
use crate::views::rolling_stocks::rolling_stock_form::RollingStockForm;
2831
use crate::views::v2::train_schedule::TrainScheduleForm;
2932
use crate::ElectricalProfileSet;
30-
use editoast_models::DbConnection;
31-
use editoast_models::DbConnectionPool;
32-
use editoast_models::DbConnectionPoolV2;
3333

3434
pub fn project_changeset(name: &str) -> Changeset<Project> {
3535
Project::changeset()
@@ -308,3 +308,15 @@ pub async fn create_work_schedule_group(conn: &mut DbConnection) -> WorkSchedule
308308
.await
309309
.expect("Failed to create empty work schedule group")
310310
}
311+
312+
pub fn get_trainschedule_json_array() -> &'static str {
313+
include_str!("../tests/train_schedules/simple_array.json")
314+
}
315+
316+
pub fn get_fast_rolling_stock_schema(name: &str) -> RollingStock {
317+
let mut rolling_stock_form: RollingStock =
318+
serde_json::from_str(include_str!("../tests/example_rolling_stock_1.json"))
319+
.expect("Unable to parse");
320+
rolling_stock_form.name = name.to_string();
321+
rolling_stock_form
322+
}

editoast/src/views/infra/edition.rs

+33-16
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,6 @@ pub mod tests {
922922
use rstest::rstest;
923923

924924
use super::*;
925-
use crate::fixtures::tests::db_pool;
926-
use crate::fixtures::tests::small_infra;
927925
use crate::generated_data::infra_error::InfraError;
928926
use crate::generated_data::infra_error::InfraErrorType;
929927
use crate::modelsv2::fixtures::create_small_infra;
@@ -1032,10 +1030,13 @@ pub mod tests {
10321030
#[rstest]
10331031
async fn apply_edit_transaction_should_work() {
10341032
// Init
1035-
let pg_db_pool = db_pool();
1036-
let conn = &mut pg_db_pool.get().await.unwrap();
1037-
let mut small_infra = small_infra(pg_db_pool.clone()).await;
1038-
let mut infra_cache = InfraCache::load(conn, &small_infra.model).await.unwrap();
1033+
let app = TestAppBuilder::default_app();
1034+
let db_pool = app.db_pool();
1035+
1036+
let mut small_infra = create_small_infra(&mut db_pool.get_ok()).await;
1037+
let mut infra_cache = InfraCache::load(&mut db_pool.get_ok(), &small_infra)
1038+
.await
1039+
.unwrap();
10391040

10401041
// Calling "apply_edit" with a OK operation
10411042
let operations: Vec<Operation> = [
@@ -1053,10 +1054,14 @@ pub mod tests {
10531054
}),
10541055
]
10551056
.to_vec();
1056-
let result: Vec<InfraObject> =
1057-
apply_edit(conn, &mut small_infra.model, &operations, &mut infra_cache)
1058-
.await
1059-
.unwrap();
1057+
let result: Vec<InfraObject> = apply_edit(
1058+
&mut db_pool.get_ok(),
1059+
&mut small_infra,
1060+
&operations,
1061+
&mut infra_cache,
1062+
)
1063+
.await
1064+
.unwrap();
10601065

10611066
// Check that the updated track has the new length
10621067
assert_eq!(1234.0, result[0].get_data()["length"]);
@@ -1065,9 +1070,12 @@ pub mod tests {
10651070
#[rstest]
10661071
async fn apply_edit_transaction_should_rollback() {
10671072
// Init
1068-
let conn = &mut db_pool().get().await.unwrap();
1069-
let mut small_infra = small_infra(db_pool().clone()).await;
1070-
let mut infra_cache = InfraCache::load(conn, &small_infra.model).await.unwrap();
1073+
let app = TestAppBuilder::default_app();
1074+
let db_pool = app.db_pool();
1075+
let mut small_infra = create_small_infra(&mut db_pool.get_ok()).await;
1076+
let mut infra_cache = InfraCache::load(&mut db_pool.get_ok(), &small_infra)
1077+
.await
1078+
.unwrap();
10711079

10721080
// Calling "apply_edit" with a first OK operation and a KO second one
10731081
let operations: Vec<Operation> = [
@@ -1097,15 +1105,24 @@ pub mod tests {
10971105
}),
10981106
]
10991107
.to_vec();
1100-
let result = apply_edit(conn, &mut small_infra.model, &operations, &mut infra_cache).await;
1108+
let result = apply_edit(
1109+
&mut db_pool.get_ok(),
1110+
&mut small_infra,
1111+
&operations,
1112+
&mut infra_cache,
1113+
)
1114+
.await;
11011115

11021116
// Check that we have an error
11031117
assert!(result.is_err());
11041118

11051119
// Check that TA0 length is not changed
11061120
let res: Vec<ObjectQueryable> = small_infra
1107-
.model
1108-
.get_objects(conn, ObjectType::TrackSection, &vec!["TA0".to_string()])
1121+
.get_objects(
1122+
&mut db_pool.get_ok(),
1123+
ObjectType::TrackSection,
1124+
&vec!["TA0".to_string()],
1125+
)
11091126
.await
11101127
.unwrap();
11111128
assert_eq!(2000.0, res[0].railjson.as_object().unwrap()["length"]);

editoast/src/views/infra/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -754,14 +754,14 @@ pub async fn fetch_all_infra_states(
754754

755755
#[cfg(test)]
756756
pub mod tests {
757-
use std::ops::DerefMut;
758757
use axum::http::StatusCode;
759758
use diesel::sql_query;
760759
use diesel::sql_types::BigInt;
761760
use diesel_async::RunQueryDsl;
762761
use pretty_assertions::assert_eq;
763762
use rstest::rstest;
764763
use serde_json::json;
764+
use std::ops::DerefMut;
765765
use strum::IntoEnumIterator;
766766

767767
use super::*;

0 commit comments

Comments
 (0)