1313
1414
1515class TestUserScoring (TestCase ):
16+ """
17+ Test using mock Multimodal form template with dynamically generated scores created during setup.
18+ """
19+
1620 PROJECT_NAME = "TestUserScoring"
1721 PROJECT_TYPE = "Multimodal"
1822 PROJECT_DESCRIPTION = "DESCRIPTION"
1923 EDITOR_TEMPLATE_PATH = os .path .join (
20- Path (__file__ ).parent .parent .parent , "data_set/editor_templates/form1.json"
24+ Path (__file__ ).parent .parent .parent ,
25+ "data_set/editor_templates/form_with_scores.json" ,
2126 )
2227 CLASSES_TEMPLATE_PATH = os .path .join (
2328 Path (__file__ ).parent .parent .parent ,
@@ -39,13 +44,20 @@ def setUpClass(cls, *args, **kwargs) -> None:
3944 project = sa .controller .get_project (cls .PROJECT_NAME )
4045 time .sleep (5 )
4146
42- for data in SCORE_TEMPLATES :
43- req = sa .controller .service_provider .work_management .create_score (** data )
44- assert req .status_code == 201
45-
47+ # setup form template from crated scores
4648 with open (cls .EDITOR_TEMPLATE_PATH ) as f :
49+ template_data = json .load (f )
50+ for data in SCORE_TEMPLATES :
51+ req = sa .controller .service_provider .work_management .create_score (
52+ ** data
53+ )
54+ assert req .status_code == 201
55+ for component in template_data ["components" ]:
56+ if "scoring" in component and component ["type" ] == req .data ["type" ]:
57+ component ["scoring" ]["id" ] = req .data ["id" ]
58+
4759 res = sa .controller .service_provider .projects .attach_editor_template (
48- team , project , template = json . load ( f )
60+ team , project , template = template_data
4961 )
5062 assert res .ok
5163 sa .create_annotation_classes_from_classes_json (
@@ -85,23 +97,23 @@ def _attach_item(path, name):
8597 sa .attach_items (path , [{"name" : name , "url" : "url" }])
8698
8799 def test_set_get_scores (self ):
88- scores_payload = [
89- {
90- "name " : SCORE_TEMPLATES [ 0 ][ "name" ],
100+ scores_name_payload_map = {
101+ "SDK-my-score-1" : {
102+ "component_id " : "r_34k7k7" , # rating type score
91103 "value" : 5 ,
92104 "weight" : 0.5 ,
93105 },
94- {
95- "name " : SCORE_TEMPLATES [ 1 ][ "name" ],
106+ "SDK-my-score-2" : {
107+ "component_id " : "r_ioc7wd" , # number type score
96108 "value" : 45 ,
97109 "weight" : 1.5 ,
98110 },
99- {
100- "name " : SCORE_TEMPLATES [ 2 ][ "name" ],
111+ "SDK-my-score-3" : {
112+ "component_id " : "r_tcof7o" , # radio type score
101113 "value" : None ,
102114 "weight" : None ,
103115 },
104- ]
116+ }
105117 item_name = f"test_item_{ uuid .uuid4 ()} "
106118 self ._attach_item (self .PROJECT_NAME , item_name )
107119
@@ -110,7 +122,7 @@ def test_set_get_scores(self):
110122 project = self .PROJECT_NAME ,
111123 item = item_name ,
112124 scored_user = self .scapegoat ["email" ],
113- scores = scores_payload ,
125+ scores = list ( scores_name_payload_map . values ()) ,
114126 )
115127 assert cm .output [0 ] == "INFO:sa:Scores successfully set."
116128
@@ -122,10 +134,8 @@ def test_set_get_scores(self):
122134 )
123135 assert len (created_scores ) == len (SCORE_TEMPLATES )
124136
125- score_name_payload_map = {s ["name" ]: s for s in scores_payload }
126137 for score in created_scores :
127- score_pyload = score_name_payload_map [score ["name" ]]
128- assert score ["name" ] == score_pyload ["name" ]
138+ score_pyload = scores_name_payload_map [score ["name" ]]
129139 assert score ["value" ] == score_pyload ["value" ]
130140 assert score ["weight" ] == score_pyload ["weight" ]
131141 assert score ["id" ]
@@ -172,7 +182,7 @@ def test_set_get_scores_negative_cases(self):
172182 scored_user = self .scapegoat ["email" ],
173183 scores = [
174184 {
175- "name " : SCORE_TEMPLATES [ 0 ][ "name" ] ,
185+ "component_id " : "r_34k7k7" ,
176186 "value" : None ,
177187 "weight" : 0.5 ,
178188 }
@@ -188,7 +198,7 @@ def test_set_get_scores_negative_cases(self):
188198 scored_user = self .scapegoat ["email" ],
189199 scores = [
190200 {
191- "name " : SCORE_TEMPLATES [ 1 ][ "name" ] ,
201+ "component_id " : "r_ioc7wd" ,
192202 "value" : 5 ,
193203 "weight" : None ,
194204 }
@@ -203,7 +213,7 @@ def test_set_get_scores_negative_cases(self):
203213 scored_user = self .scapegoat ["email" ],
204214 scores = [
205215 {
206- "name " : SCORE_TEMPLATES [ 0 ][ "name" ] ,
216+ "component_id " : "r_34k7k7" ,
207217 "value" : 5 ,
208218 "weight" : 1.2 ,
209219 "invalid_key" : 123 ,
@@ -212,14 +222,14 @@ def test_set_get_scores_negative_cases(self):
212222 )
213223
214224 # case with invalid score name
215- with self .assertRaisesRegexp (AppException , "Please provide valid score names. " ):
225+ with self .assertRaisesRegexp (AppException , "Invalid component_id provided " ):
216226 sa .set_user_scores (
217227 project = self .PROJECT_NAME ,
218228 item = item_name ,
219229 scored_user = self .scapegoat ["email" ],
220230 scores = [
221231 {
222- "name " : "test_score_invalid " ,
232+ "component_id " : "invalid_component_id " ,
223233 "value" : 5 ,
224234 "weight" : 0.8 ,
225235 }
@@ -234,26 +244,26 @@ def test_set_get_scores_negative_cases(self):
234244 scored_user = self .scapegoat ["email" ],
235245 scores = [
236246 {
237- "name " : SCORE_TEMPLATES [ 0 ][ "name" ] ,
247+ "component_id " : "r_34k7k7" ,
238248 "weight" : 1.2 ,
239249 }
240250 ],
241251 )
242252
243253 # case with duplicated acore names
244- with self .assertRaisesRegexp (AppException , "Invalid Scores ." ):
254+ with self .assertRaisesRegexp (AppException , "Component IDs in scores data must be unique ." ):
245255 sa .set_user_scores (
246256 project = self .PROJECT_NAME ,
247257 item = item_name ,
248258 scored_user = self .scapegoat ["email" ],
249259 scores = [
250260 {
251- "name " : SCORE_TEMPLATES [ 0 ][ "name" ] ,
261+ "component_id " : "r_34k7k7" ,
252262 "value" : 5 ,
253263 "weight" : 1.2 ,
254264 },
255265 {
256- "name " : SCORE_TEMPLATES [ 0 ][ "name" ] ,
266+ "component_id " : "r_34k7k7" ,
257267 "value" : 5 ,
258268 "weight" : 1.2 ,
259269 },
@@ -270,7 +280,7 @@ def test_set_get_scores_negative_cases(self):
270280 scored_user = self .scapegoat ["email" ],
271281 scores = [
272282 {
273- "name " : SCORE_TEMPLATES [ 0 ][ "name" ] ,
283+ "component_id " : "r_34k7k7" ,
274284 "value" : 5 ,
275285 "weight" : - 1 ,
276286 }
@@ -285,7 +295,7 @@ def test_set_get_scores_negative_cases(self):
285295 scored_user = "invalid_email@mail.com" ,
286296 scores = [
287297 {
288- "name " : SCORE_TEMPLATES [ 0 ][ "name" ] ,
298+ "component_id " : "r_34k7k7" ,
289299 "value" : 5 ,
290300 "weight" : 1 ,
291301 }
@@ -300,7 +310,7 @@ def test_set_get_scores_negative_cases(self):
300310 scored_user = self .scapegoat ["email" ],
301311 scores = [
302312 {
303- "name " : SCORE_TEMPLATES [ 0 ][ "name" ] ,
313+ "component_id " : "r_34k7k7" ,
304314 "value" : 5 ,
305315 "weight" : 1 ,
306316 }
@@ -315,7 +325,7 @@ def test_set_get_scores_negative_cases(self):
315325 scored_user = self .scapegoat ["email" ],
316326 scores = [
317327 {
318- "name " : SCORE_TEMPLATES [ 0 ][ "name" ] ,
328+ "component_id " : "r_34k7k7" ,
319329 "value" : 5 ,
320330 "weight" : 1 ,
321331 }
@@ -330,7 +340,7 @@ def test_set_get_scores_negative_cases(self):
330340 scored_user = self .scapegoat ["email" ],
331341 scores = [
332342 {
333- "name " : SCORE_TEMPLATES [ 0 ][ "name" ] ,
343+ "component_id " : "r_34k7k7" ,
334344 "value" : 5 ,
335345 "weight" : 1 ,
336346 }
0 commit comments