9
9
from src .model .observed_variable import ObservedVariable , ObservedVariableDataclass
10
10
from src .model .vocabulary import Vocabulary
11
11
from tests .helpers import delete_fixture , post_fixture , put_fixture
12
+ from tests .router .method .fixture import AllMethodFixtureResponse
12
13
from tests .router .study .fixture import AllStudyFixtureResponse
14
+ from tests .router .unit .fixture import AllUnitFixtureResponse
13
15
14
16
15
17
@dataclass
16
18
class ObservedVariableResponse :
19
+ trait_response : Response
17
20
observed_variable_response : Response
18
21
study_response : list [Response ]
19
-
20
-
21
- @dataclass
22
- class AllObservedVariableFixtureResponse :
23
- projected_shoot_area : ObservedVariableResponse
24
- zn_concentration : ObservedVariableResponse
25
-
26
-
27
- @dataclass
28
- class VariableReferenceResponse :
29
- anthesis : Response
22
+ method_response : Response
23
+ unit_response : Response
30
24
31
25
32
26
@dataclass
@@ -37,76 +31,159 @@ class VariableTraitResponse:
37
31
zn_concentration : Response
38
32
39
33
40
- PATH = "observed_variable"
34
+ @dataclass
35
+ class AllObservedVariableFixtureResponse :
36
+ anthesis : ObservedVariableResponse
37
+ reproductive_growth_time : ObservedVariableResponse
38
+ projected_shoot_area : ObservedVariableResponse
39
+ zn_concentration : ObservedVariableResponse
40
+ trait_response : VariableTraitResponse
41
+ study_response : AllStudyFixtureResponse
42
+ method_response : AllMethodFixtureResponse
43
+ unit_response : AllUnitFixtureResponse
44
+
45
+
46
+ PATH = "observedVariable"
41
47
ANTHESIS_TRAIT = Vocabulary (title = "Anthesis time" , accession_number = "CO_322:0000030" )
42
48
REPRODUCTIVE_GROWTH_TIME_TRAIT = Vocabulary (title = "Reproductive growth time" , accession_number = "TO:0000366" )
43
49
PROJECTED_SHOOT_AREA_TRAIT = Vocabulary (title = "Projected shoot area" )
44
50
ZN_CONCENTRATION_TRAIT = Vocabulary (title = "Zn concentration" , accession_number = "CDNO_0200170" )
45
51
46
- ANTHESIS_VARIABLE = ObservedVariable (title = "Ant_Cmp_Cday" , description = "Anthesis computed in growing degree days" )
52
+ ANTHESIS_VARIABLE = ObservedVariable (
53
+ title = "Ant_Cmp_Cday" ,
54
+ description = "Anthesis computed in growing degree days" ,
55
+ time_interval = "day" ,
56
+ )
57
+ REPRODUCTIVE_GROWTH_TIME_VARIABLE = ObservedVariable (
58
+ title = "Reproductive Growth Time" ,
59
+ description = "Reproductive growth time" ,
60
+ time_interval = "day" ,
61
+ )
47
62
PROJECTED_SHOOT_AREA_VARIABLE = ObservedVariable (title = "PSA_img_kpixels" )
48
63
ZN_CONCENTRATION_VARIABLE = ObservedVariable (title = "Zn_conc" )
49
64
50
65
51
66
async def get_observed_variable_fixture (
52
- data : ObservedVariable , studies : list [Response ], test_client : AsyncTestClient , id : UUID | None = None
67
+ data : ObservedVariable ,
68
+ studies : list [Response ],
69
+ method : Response ,
70
+ trait : Response ,
71
+ unit : Response ,
72
+ test_client : AsyncTestClient ,
73
+ id : UUID | None = None ,
53
74
) -> ObservedVariableResponse :
54
75
study_id = [item .json ()["id" ] for item in studies ]
55
- send_data = ObservedVariableDataclass (study_id = study_id , ** data .to_dict ())
76
+ method_id = method .json ()["id" ]
77
+ trait_reference_id = trait .json ()["id" ]
78
+ unit_id = unit .json ()["id" ]
79
+ send_data = ObservedVariableDataclass (
80
+ method_id = method_id ,
81
+ trait_reference_id = trait_reference_id ,
82
+ study_id = study_id ,
83
+ unit_id = unit_id ,
84
+ ** data .to_dict (),
85
+ )
56
86
if id is None :
57
87
send_data .updated_at = None
58
88
response = await post_fixture (PATH , send_data , test_client )
59
89
else :
60
90
response = await put_fixture (PATH , send_data , test_client , id )
61
- return ObservedVariableResponse (study_response = studies , observed_variable_response = response )
91
+ return ObservedVariableResponse (
92
+ study_response = studies ,
93
+ method_response = method ,
94
+ unit_response = unit ,
95
+ trait_response = trait ,
96
+ observed_variable_response = response ,
97
+ )
98
+
99
+
100
+ @pytest .fixture (scope = "function" )
101
+ async def setup_trait (test_client : AsyncTestClient ) -> AsyncGenerator [VariableTraitResponse , None ]:
102
+ PATH = "vocabulary"
103
+ anthesis_trait = await post_fixture (PATH , ANTHESIS_TRAIT , test_client )
104
+ projected_shoot_area_trait = await post_fixture (PATH , PROJECTED_SHOOT_AREA_TRAIT , test_client )
105
+ zn_concentration_trait = await post_fixture (PATH , ZN_CONCENTRATION_TRAIT , test_client )
106
+ reproductive_growth_time_trait = await post_fixture (PATH , REPRODUCTIVE_GROWTH_TIME_TRAIT , test_client )
107
+ yield VariableTraitResponse (
108
+ anthesis = anthesis_trait ,
109
+ reproductive_growth_time = reproductive_growth_time_trait ,
110
+ projected_shoot_area = projected_shoot_area_trait ,
111
+ zn_concentration = zn_concentration_trait ,
112
+ )
113
+ await delete_fixture (PATH , anthesis_trait .json ()["id" ], test_client )
114
+ await delete_fixture (PATH , reproductive_growth_time_trait .json ()["id" ], test_client )
115
+ await delete_fixture (PATH , projected_shoot_area_trait .json ()["id" ], test_client )
116
+ await delete_fixture (PATH , zn_concentration_trait .json ()["id" ], test_client )
62
117
63
118
64
119
@pytest .fixture (scope = "function" )
65
120
async def setup_observed_variable (
66
- setup_study : AllStudyFixtureResponse , test_client : AsyncTestClient
121
+ setup_study : AllStudyFixtureResponse ,
122
+ setup_method : AllMethodFixtureResponse ,
123
+ setup_unit : AllUnitFixtureResponse ,
124
+ setup_trait : VariableTraitResponse ,
125
+ test_client : AsyncTestClient ,
67
126
) -> AsyncGenerator [AllObservedVariableFixtureResponse , None ]:
127
+ first_study = setup_study .first .study_response
68
128
maize_study = setup_study .maize .study_response
69
- barley_study = setup_study .barley .study_response
70
- maize_sowing_density = await get_observed_variable_fixture (
71
- MAIZE_SOWING_DENSITY , [maize_study , barley_study ], test_client
129
+ barley_study = setup_study .maize .study_response
130
+
131
+ projected_shoot_area_method = setup_method .projected_shoot_area .method_response
132
+ zn_concentration_method = setup_method .zn_concentration .method_response
133
+ day_to_anthesis_method = setup_method .day_to_anthesis .method_response
134
+
135
+ growing_degree_day = setup_unit .degree_day .unit_response
136
+ kilopixel = setup_unit .kilo_pixel .unit_response
137
+ microgram = setup_unit .microgram .unit_response
138
+
139
+ anthesis_trait = setup_trait .anthesis
140
+ projected_shoot_area_trait = setup_trait .projected_shoot_area
141
+ zn_concentration_trait = setup_trait .zn_concentration
142
+ reproductive_growth_time_trait = setup_trait .reproductive_growth_time
143
+
144
+ anthesis_variable = await get_observed_variable_fixture (
145
+ data = ANTHESIS_VARIABLE ,
146
+ studies = [first_study ],
147
+ method = day_to_anthesis_method ,
148
+ trait = anthesis_trait ,
149
+ unit = growing_degree_day ,
150
+ test_client = test_client ,
151
+ )
152
+ reproductive_growth_time_variable = await get_observed_variable_fixture (
153
+ data = REPRODUCTIVE_GROWTH_TIME_VARIABLE ,
154
+ studies = [maize_study ],
155
+ method = day_to_anthesis_method ,
156
+ trait = reproductive_growth_time_trait ,
157
+ unit = growing_degree_day ,
158
+ test_client = test_client ,
72
159
)
73
- maize_rooting_medium = await get_observed_variable_fixture (MAIZE_ROOTING_MEDIUM , [ maize_study ], test_client )
74
- maize_ph = await get_observed_variable_fixture ( MAIZE_PH , [ maize_study ], test_client )
75
- barley_sowing_density = await get_observed_variable_fixture ( BARLEY_SOWING_DENSITY , [barley_study ], test_client )
76
- barley_rooting_medium = await get_observed_variable_fixture ( BARLEY_ROOTING_MEDIUM , [ barley_study ], test_client )
77
- barley_ferterlizer = await get_observed_variable_fixture ( BARLEY_FERTILIZER , [ barley_study ], test_client )
78
- barley_watering_exposure = await get_observed_variable_fixture (
79
- BARLEY_WATERING_EXPOSURE , [ barley_study ], test_client
160
+ projected_shoot_area_variable = await get_observed_variable_fixture (
161
+ data = PROJECTED_SHOOT_AREA_VARIABLE ,
162
+ studies = [barley_study ],
163
+ method = projected_shoot_area_method ,
164
+ trait = projected_shoot_area_trait ,
165
+ unit = kilopixel ,
166
+ test_client = test_client ,
80
167
)
81
- barley_light_intensity = await get_observed_variable_fixture (BARLEY_LIGHT_INTENSITY , [barley_study ], test_client )
82
- barley_relative_humidity = await get_observed_variable_fixture (
83
- BARLEY_RELATIVE_HUMIDITY , [barley_study ], test_client
168
+ zn_concentration_variable = await get_observed_variable_fixture (
169
+ data = ZN_CONCENTRATION_VARIABLE ,
170
+ studies = [barley_study ],
171
+ method = zn_concentration_method ,
172
+ trait = zn_concentration_trait ,
173
+ unit = microgram ,
174
+ test_client = test_client ,
84
175
)
85
- barley_temperature = await get_observed_variable_fixture (BARLEY_TEMPERATURE , [barley_study ], test_client )
86
176
87
177
yield AllObservedVariableFixtureResponse (
88
- maize_sowing_density = maize_sowing_density ,
89
- maize_rooting_medium = maize_rooting_medium ,
90
- maize_ph = maize_ph ,
91
- barley_sowing_density = barley_sowing_density ,
92
- barley_rooting_medium = barley_rooting_medium ,
93
- barley_fertilizer = barley_ferterlizer ,
94
- barley_watering_exposure = barley_watering_exposure ,
95
- barley_light_intensity = barley_light_intensity ,
96
- barley_relative_humidity = barley_relative_humidity ,
97
- barley_temperature = barley_temperature ,
178
+ reproductive_growth_time = reproductive_growth_time_variable ,
179
+ projected_shoot_area = projected_shoot_area_variable ,
180
+ zn_concentration = zn_concentration_variable ,
181
+ anthesis = anthesis_variable ,
98
182
study_response = setup_study ,
183
+ method_response = setup_method ,
184
+ trait_response = setup_trait ,
185
+ unit_response = setup_unit ,
99
186
)
100
- await delete_fixture (PATH , maize_sowing_density .observed_variable_response .json ()["id" ], test_client )
101
- await delete_fixture (PATH , maize_rooting_medium .observed_variable_response .json ()["id" ], test_client )
102
- await delete_fixture (PATH , maize_ph .observed_variable_response .json ()["id" ], test_client )
103
- await delete_fixture (PATH , barley_sowing_density .observed_variable_response .json ()["id" ], test_client )
104
- await delete_fixture (PATH , barley_rooting_medium .observed_variable_response .json ()["id" ], test_client )
105
- await delete_fixture (PATH , barley_ferterlizer .observed_variable_response .json ()["id" ], test_client )
106
- await delete_fixture (PATH , barley_watering_exposure .observed_variable_response .json ()["id" ], test_client )
107
- await delete_fixture (PATH , barley_light_intensity .observed_variable_response .json ()["id" ], test_client )
108
- await delete_fixture (PATH , barley_relative_humidity .observed_variable_response .json ()["id" ], test_client )
109
- await delete_fixture (PATH , barley_temperature .observed_variable_response .json ()["id" ], test_client )
110
187
111
188
112
189
@pytest .fixture (scope = "function" )
@@ -115,9 +192,15 @@ async def update_observed_variable(
115
192
) -> AsyncGenerator [AllObservedVariableFixtureResponse , None ]:
116
193
all_responses = setup_observed_variable
117
194
maize_study = all_responses .study_response .maize .study_response
118
- maize_sowing_density = all_responses .maize_sowing_density
119
- maize_sowing_density_response = await get_observed_variable_fixture (
120
- MAIZE_SOWING_DENSITY , [maize_study ], test_client , maize_sowing_density .observed_variable_response .json ()["id" ]
195
+ anthesis = all_responses .anthesis
196
+ anthesis_response = await get_observed_variable_fixture (
197
+ data = ANTHESIS_VARIABLE ,
198
+ studies = [maize_study ],
199
+ test_client = test_client ,
200
+ id = anthesis .observed_variable_response .json ()["id" ],
201
+ method = anthesis .method_response ,
202
+ trait = anthesis .trait_response ,
203
+ unit = anthesis .unit_response ,
121
204
)
122
- all_responses .maize_sowing_density = maize_sowing_density_response
205
+ all_responses .anthesis = anthesis_response
123
206
yield all_responses
0 commit comments