3
3
from cg .services .orders .validation .model_validator .model_validator import ModelValidator
4
4
from cg .services .orders .validation .models .order import Order
5
5
from cg .services .orders .validation .workflows .fluffy .models .order import FluffyOrder
6
+ from cg .services .orders .validation .workflows .mutant .models .order import MutantOrder
6
7
from cg .services .orders .validation .workflows .rml .models .order import RmlOrder
8
+ from cg .services .orders .validation .workflows .tomte .models .order import TomteOrder
7
9
8
10
9
11
@pytest .mark .parametrize (
@@ -21,12 +23,110 @@ def test_validate_pool_sample_default_index(
21
23
model_validator : ModelValidator ,
22
24
request : pytest .FixtureRequest ,
23
25
):
26
+ """Test the default index sequence is set for a pool sample without index sequence."""
24
27
# GIVEN a pool raw order with a sample without index sequence but correct index and index number
25
28
raw_order : dict = request .getfixturevalue (order_fixture )
26
- assert raw_order ["samples" ][0 ]["index_sequence" ] == ""
29
+ assert not raw_order ["samples" ][0 ]["index_sequence" ]
27
30
28
31
# WHEN validating the order
29
32
order , _ = model_validator .validate (order = raw_order , model = order_model )
30
33
31
34
# THEN the index sequence should be set to the default index sequence
32
35
assert order .samples [0 ].index_sequence == expected_index_sequence
36
+
37
+
38
+ def test_validate_mutant_sample_gets_lab_and_region (
39
+ sarscov2_order_to_submit : dict , model_validator : ModelValidator
40
+ ):
41
+ """Test the lab address and region code are set for a mutant sample without these fields."""
42
+ # GIVEN a Mutant order with a sample without lab address and region code
43
+ assert not sarscov2_order_to_submit ["samples" ][0 ]["original_lab_address" ]
44
+ assert not sarscov2_order_to_submit ["samples" ][0 ]["region_code" ]
45
+
46
+ # WHEN validating the order
47
+ order , _ = model_validator .validate (order = sarscov2_order_to_submit , model = MutantOrder )
48
+
49
+ # THEN the lab address and region code should be set
50
+ assert order .samples [0 ].original_lab_address == "171 76 Stockholm"
51
+ assert order .samples [0 ].region_code == "01"
52
+
53
+
54
+ def test_order_field_error (valid_order : TomteOrder , model_validator : ModelValidator ):
55
+ # GIVEN a Tomte order with an order field error
56
+ valid_order .name = ""
57
+ raw_order : dict = valid_order .model_dump (by_alias = True )
58
+
59
+ # WHEN validating the order
60
+ _ , errors = model_validator .validate (order = raw_order , model = TomteOrder )
61
+
62
+ # THEN there should be an order error
63
+ assert errors .order_errors
64
+
65
+ # THEN the error should concern the missing name
66
+ assert errors .order_errors [0 ].field == "name"
67
+
68
+
69
+ def test_case_field_error (valid_order : TomteOrder , model_validator : ModelValidator ):
70
+ # GIVEN a Tomte order with a case field error
71
+ valid_order .cases [0 ].priority = None
72
+ raw_order : dict = valid_order .model_dump ()
73
+
74
+ # WHEN validating the order
75
+ _ , errors = model_validator .validate (order = raw_order , model = TomteOrder )
76
+
77
+ # THEN there should be a case error
78
+ assert errors .case_errors
79
+
80
+ # THEN the error should concern the missing name
81
+ assert errors .case_errors [0 ].field == "priority"
82
+
83
+
84
+ def test_case_sample_field_error (valid_order : TomteOrder , model_validator : ModelValidator ):
85
+
86
+ # GIVEN a Tomte order with a case sample error
87
+ valid_order .cases [0 ].samples [0 ].well_position = 1.8
88
+ raw_order : dict = valid_order .model_dump ()
89
+
90
+ # WHEN validating the order
91
+ _ , errors = model_validator .validate (order = raw_order , model = TomteOrder )
92
+
93
+ # THEN a case sample error should be returned
94
+ assert errors .case_sample_errors
95
+
96
+ # THEN the case sample error should concern the invalid data type
97
+ assert errors .case_sample_errors [0 ].field == "well_position"
98
+
99
+
100
+ def test_order_case_and_case_sample_field_error (
101
+ valid_order : TomteOrder , model_validator : ModelValidator
102
+ ):
103
+ # GIVEN a Tomte order with an order, case and case sample error
104
+ valid_order .name = None
105
+ valid_order .cases [0 ].priority = None
106
+ valid_order .cases [0 ].samples [0 ].well_position = 1.8
107
+ raw_order : dict = valid_order .model_dump (by_alias = True )
108
+
109
+ # WHEN validating the order
110
+ _ , errors = model_validator .validate (order = raw_order , model = TomteOrder )
111
+
112
+ # THEN all errors should be returned
113
+ assert errors .order_errors
114
+ assert errors .case_errors
115
+ assert errors .case_sample_errors
116
+
117
+ # THEN the errors should concern the relevant fields
118
+ assert errors .order_errors [0 ].field == "name"
119
+ assert errors .case_errors [0 ].field == "priority"
120
+ assert errors .case_sample_errors [0 ].field == "well_position"
121
+
122
+
123
+ def test_null_conversion (valid_order : TomteOrder , model_validator : ModelValidator ):
124
+ # GIVEN a Tomte order with a sample with empty concentration
125
+ valid_order .cases [0 ].samples [0 ].concentration_ng_ul = ""
126
+ raw_order : dict = valid_order .model_dump (by_alias = True )
127
+
128
+ # WHEN validating the order
129
+ order , _ = model_validator .validate (order = raw_order , model = TomteOrder )
130
+
131
+ # THEN the empty concentration should be converted to None
132
+ assert order .cases [0 ].samples [0 ].concentration_ng_ul is None
0 commit comments