@@ -20,14 +20,20 @@ pub mod tests {
20
20
use postgis_diesel:: types:: LineString ;
21
21
use rstest:: * ;
22
22
use serde_json:: json;
23
+ use std:: fmt;
23
24
24
- #[ derive( Debug ) ]
25
25
pub struct TestFixture < T : Delete + Identifiable + Send > {
26
26
pub model : T ,
27
27
pub db_pool : Data < DbPool > ,
28
28
pub infra : Option < Infra > ,
29
29
}
30
30
31
+ impl < T : fmt:: Debug + Delete + Identifiable + Send > fmt:: Debug for TestFixture < T > {
32
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
33
+ write ! ( f, "Fixture {:?} {:?}" , self . model, self . infra)
34
+ }
35
+ }
36
+
31
37
impl < T : Delete + Identifiable + Send > TestFixture < T > {
32
38
pub fn id ( & self ) -> i64 {
33
39
self . model . get_id ( )
@@ -62,52 +68,47 @@ pub mod tests {
62
68
}
63
69
64
70
#[ fixture]
65
- pub async fn db_pool ( ) -> Data < DbPool > {
71
+ pub fn db_pool ( ) -> Data < DbPool > {
66
72
let url = PostgresConfig :: default ( ) . url ( ) ;
67
73
let config = AsyncDieselConnectionManager :: < diesel_async:: AsyncPgConnection > :: new ( url) ;
68
- let pool = DbPool :: builder ( ) . build ( config ) . await . unwrap ( ) ;
74
+ let pool = DbPool :: builder ( config ) . build ( ) . unwrap ( ) ;
69
75
Data :: new ( pool)
70
76
}
71
77
72
78
#[ fixture]
73
- pub async fn fast_rolling_stock (
74
- #[ future] db_pool : Data < DbPool > ,
75
- ) -> TestFixture < RollingStockModel > {
79
+ pub async fn fast_rolling_stock ( db_pool : Data < DbPool > ) -> TestFixture < RollingStockModel > {
76
80
TestFixture :: create (
77
81
serde_json:: from_str :: < RollingStockModel > ( include_str ! (
78
82
"./tests/example_rolling_stock_1.json"
79
83
) )
80
84
. expect ( "Unable to parse" ) ,
81
- db_pool. await ,
85
+ db_pool,
82
86
)
83
87
. await
84
88
}
85
89
86
90
#[ fixture]
87
- pub async fn other_rolling_stock (
88
- #[ future] db_pool : Data < DbPool > ,
89
- ) -> TestFixture < RollingStockModel > {
91
+ pub async fn other_rolling_stock ( db_pool : Data < DbPool > ) -> TestFixture < RollingStockModel > {
90
92
TestFixture :: create (
91
93
serde_json:: from_str :: < RollingStockModel > ( include_str ! (
92
94
"./tests/example_rolling_stock_2_energy_sources.json"
93
95
) )
94
96
. expect ( "Unable to parse" ) ,
95
- db_pool. await ,
97
+ db_pool,
96
98
)
97
99
. await
98
100
}
99
101
100
102
#[ fixture]
101
103
pub async fn train_schedule (
102
- # [ future ] db_pool : Data < DbPool > ,
104
+ db_pool : Data < DbPool > ,
103
105
#[ future] pathfinding : TestFixture < Pathfinding > ,
104
106
#[ future] timetable : TestFixture < Timetable > ,
105
107
#[ future] fast_rolling_stock : TestFixture < RollingStockModel > ,
106
108
) -> TestFixture < TrainSchedule > {
107
109
let pathfinding = pathfinding. await ;
108
110
let timetable = timetable. await ;
109
111
let rolling_stock = fast_rolling_stock. await ;
110
- let db_pool = db_pool. await ;
111
112
let train_schedule = make_train_schedule (
112
113
db_pool. clone ( ) ,
113
114
pathfinding. id ( ) ,
@@ -159,14 +160,13 @@ pub mod tests {
159
160
let pathfinding = pathfinding ( db_pool ( ) ) . await ;
160
161
let rolling_stock = fast_rolling_stock ( db_pool ( ) ) . await ;
161
162
let ts_model = make_train_schedule (
162
- db_pool ( ) . await ,
163
+ db_pool ( ) ,
163
164
pathfinding. id ( ) ,
164
165
timetable. id ( ) ,
165
166
rolling_stock. id ( ) ,
166
167
)
167
168
. await ;
168
- let train_schedule: TestFixture < TrainSchedule > =
169
- TestFixture :: new ( ts_model, db_pool ( ) . await ) ;
169
+ let train_schedule: TestFixture < TrainSchedule > = TestFixture :: new ( ts_model, db_pool ( ) ) ;
170
170
TrainScheduleFixtureSet {
171
171
train_schedule,
172
172
project,
@@ -201,7 +201,7 @@ pub mod tests {
201
201
creation_date : Some ( Utc :: now ( ) . naive_utc ( ) ) ,
202
202
..Scenario :: default ( )
203
203
} ;
204
- let scenario = TestFixture :: create ( scenario_model, db_pool ( ) . await ) . await ;
204
+ let scenario = TestFixture :: create ( scenario_model, db_pool ( ) ) . await ;
205
205
ScenarioFixtureSet {
206
206
project,
207
207
study,
@@ -218,7 +218,7 @@ pub mod tests {
218
218
219
219
#[ fixture]
220
220
pub async fn study_fixture_set (
221
- # [ future ] db_pool : Data < DbPool > ,
221
+ db_pool : Data < DbPool > ,
222
222
#[ future] project : TestFixture < Project > ,
223
223
) -> StudyFixtureSet {
224
224
let project = project. await ;
@@ -237,12 +237,12 @@ pub mod tests {
237
237
} ;
238
238
StudyFixtureSet {
239
239
project,
240
- study : TestFixture :: create ( study_model, db_pool. await ) . await ,
240
+ study : TestFixture :: create ( study_model, db_pool) . await ,
241
241
}
242
242
}
243
243
244
244
#[ fixture]
245
- pub async fn project ( # [ future ] db_pool : Data < DbPool > ) -> TestFixture < Project > {
245
+ pub async fn project ( db_pool : Data < DbPool > ) -> TestFixture < Project > {
246
246
let project_model = Project {
247
247
name : Some ( "test_project" . into ( ) ) ,
248
248
objectives : Some ( "" . into ( ) ) ,
@@ -253,20 +253,20 @@ pub mod tests {
253
253
creation_date : Some ( Utc :: now ( ) . naive_utc ( ) ) ,
254
254
..Default :: default ( )
255
255
} ;
256
- TestFixture :: create ( project_model, db_pool. await ) . await
256
+ TestFixture :: create ( project_model, db_pool) . await
257
257
}
258
258
259
259
#[ fixture]
260
- pub async fn timetable ( # [ future ] db_pool : Data < DbPool > ) -> TestFixture < Timetable > {
260
+ pub async fn timetable ( db_pool : Data < DbPool > ) -> TestFixture < Timetable > {
261
261
let timetable_model = Timetable {
262
262
id : None ,
263
263
name : Some ( String :: from ( "with_electrical_profiles" ) ) ,
264
264
} ;
265
- TestFixture :: create ( timetable_model, db_pool. await ) . await
265
+ TestFixture :: create ( timetable_model, db_pool) . await
266
266
}
267
267
268
268
#[ fixture]
269
- pub async fn document_example ( # [ future ] db_pool : Data < DbPool > ) -> TestFixture < Document > {
269
+ pub async fn document_example ( db_pool : Data < DbPool > ) -> TestFixture < Document > {
270
270
let img = image:: open ( "src/tests/example_rolling_stock_image_1.gif" ) . unwrap ( ) ;
271
271
let mut img_bytes: Vec < u8 > = Vec :: new ( ) ;
272
272
assert ! ( img
@@ -275,16 +275,12 @@ pub mod tests {
275
275
image:: ImageOutputFormat :: Png
276
276
)
277
277
. is_ok( ) ) ;
278
- TestFixture :: create (
279
- Document :: new ( String :: from ( "image/png" ) , img_bytes) ,
280
- db_pool. await ,
281
- )
282
- . await
278
+ TestFixture :: create ( Document :: new ( String :: from ( "image/png" ) , img_bytes) , db_pool) . await
283
279
}
284
280
285
281
#[ fixture]
286
282
pub async fn rolling_stock_livery (
287
- # [ future ] db_pool : Data < DbPool > ,
283
+ db_pool : Data < DbPool > ,
288
284
#[ future] fast_rolling_stock : TestFixture < RollingStockModel > ,
289
285
#[ future] document_example : TestFixture < Document > ,
290
286
) -> TestFixture < RollingStockLiveryModel > {
@@ -296,29 +292,29 @@ pub mod tests {
296
292
rolling_stock_id : Some ( rolling_stock. id ( ) ) ,
297
293
compound_image_id : Some ( Some ( image. id ( ) ) ) ,
298
294
} ;
299
- TestFixture :: create ( rolling_stock_livery, db_pool. await ) . await
295
+ TestFixture :: create ( rolling_stock_livery, db_pool) . await
300
296
}
301
297
302
298
#[ fixture]
303
299
pub async fn electrical_profile_set (
304
- # [ future ] db_pool : Data < DbPool > ,
300
+ db_pool : Data < DbPool > ,
305
301
) -> TestFixture < ElectricalProfileSet > {
306
302
TestFixture :: create (
307
303
serde_json:: from_str :: < ElectricalProfileSet > ( include_str ! (
308
304
"./tests/electrical_profile_set.json"
309
305
) )
310
306
. expect ( "Unable to parse" ) ,
311
- db_pool. await ,
307
+ db_pool,
312
308
)
313
309
. await
314
310
}
315
311
316
312
#[ fixture]
317
- pub async fn empty_infra ( # [ future ] db_pool : Data < DbPool > ) -> TestFixture < Infra > {
313
+ pub async fn empty_infra ( db_pool : Data < DbPool > ) -> TestFixture < Infra > {
318
314
let infra_form = InfraForm {
319
315
name : String :: from ( "test_infra" ) ,
320
316
} ;
321
- TestFixture :: create ( Infra :: from ( infra_form) , db_pool. await ) . await
317
+ TestFixture :: create ( Infra :: from ( infra_form) , db_pool) . await
322
318
}
323
319
324
320
async fn make_small_infra ( db_pool : Data < DbPool > ) -> Infra {
@@ -341,14 +337,12 @@ pub mod tests {
341
337
/// is made, the `editoast/tests/small_infra/small_infra.json` file should be updated
342
338
/// to the latest infra description.
343
339
#[ fixture]
344
- pub async fn small_infra ( #[ future] db_pool : Data < DbPool > ) -> TestFixture < Infra > {
345
- let db_pool = db_pool. await ;
340
+ pub async fn small_infra ( db_pool : Data < DbPool > ) -> TestFixture < Infra > {
346
341
TestFixture :: new ( make_small_infra ( db_pool. clone ( ) ) . await , db_pool)
347
342
}
348
343
349
344
#[ fixture]
350
- pub async fn pathfinding ( #[ future] db_pool : Data < DbPool > ) -> TestFixture < Pathfinding > {
351
- let db_pool = db_pool. await ;
345
+ pub async fn pathfinding ( db_pool : Data < DbPool > ) -> TestFixture < Pathfinding > {
352
346
let small_infra = make_small_infra ( db_pool. clone ( ) ) . await ;
353
347
let pf_cs = PathfindingChangeset {
354
348
infra_id : small_infra. id ,
@@ -400,11 +394,10 @@ pub mod tests {
400
394
timetable,
401
395
infra,
402
396
} = scenario_fixture_set ( ) . await ;
403
- let pathfinding = pathfinding. await ;
404
- let rolling_stock = fast_rolling_stock. await ;
405
- let db_pool = db_pool. await ;
397
+ let rolling_stock = fast_rolling_stock ( db_pool ( ) ) . await ;
398
+ let pathfinding = pathfinding ( db_pool ( ) ) . await ;
406
399
let train_schedule = make_train_schedule (
407
- db_pool. clone ( ) ,
400
+ db_pool ( ) . clone ( ) ,
408
401
pathfinding. id ( ) ,
409
402
timetable. id ( ) ,
410
403
rolling_stock. id ( ) ,
@@ -443,13 +436,13 @@ pub mod tests {
443
436
..Default :: default ( )
444
437
} ;
445
438
let simulation_output: SimulationOutput = simulation_output
446
- . create ( db_pool. clone ( ) )
439
+ . create ( db_pool ( ) . clone ( ) )
447
440
. await
448
441
. unwrap ( )
449
442
. into ( ) ;
450
443
451
- let train_schedule = TestFixture :: new ( train_schedule, db_pool. clone ( ) ) ;
452
- let simulation_output = TestFixture :: new ( simulation_output, db_pool) ;
444
+ let train_schedule = TestFixture :: new ( train_schedule, db_pool ( ) . clone ( ) ) ;
445
+ let simulation_output = TestFixture :: new ( simulation_output, db_pool ( ) ) ;
453
446
TrainScheduleWithSimulationOutputFixtureSet {
454
447
project,
455
448
study,
0 commit comments