1+ from tkinter import E
12import uuid
23import pytest
34
@@ -21,13 +22,14 @@ def test_assign_global_keys_to_data_rows(client, dataset, image_url):
2122 "data_row_id" : dr_2 .uid ,
2223 "global_key" : gk_2
2324 }]
24- client .assign_global_keys_to_data_rows (assignment_inputs )
25-
26- res = client . get_data_row_ids_for_global_keys ([ gk_1 , gk_2 ])
25+ res = client .assign_global_keys_to_data_rows (assignment_inputs )
26+ assert res [ 'status' ] == "SUCCESS"
27+ assert res [ 'errors' ] == []
2728
2829 assert len (res ['results' ]) == 2
29- successful_assignments = set (res ['results' ])
30- assert successful_assignments == row_ids
30+ for r in res ['results' ]:
31+ del r ['sanitized' ]
32+ assert res ['results' ] == assignment_inputs
3133
3234
3335def test_assign_global_keys_to_data_rows_validation_error (client ):
@@ -48,4 +50,30 @@ def test_assign_global_keys_to_data_rows_validation_error(client):
4850 with pytest .raises (ValueError ) as excinfo :
4951 client .assign_global_keys_to_data_rows (assignment_inputs )
5052 e = """[{'data_row_id': 'test uid', 'wrong_key': 'gk 1'}, {'wrong_key': 'test uid 3', 'global_key': 'gk 3'}, {'data_row_id': 'test uid 4'}, {'global_key': 'gk 5'}, {}]"""
51- assert e in str (excinfo .value )
53+ assert e
54+
55+
56+ def test_assign_same_global_keys_to_data_rows (client , dataset , image_url ):
57+ dr_1 = dataset .create_data_row (row_data = image_url , external_id = "hello" )
58+ dr_2 = dataset .create_data_row (row_data = image_url , external_id = "world" )
59+
60+ gk_1 = str (uuid .uuid4 ())
61+
62+ assignment_inputs = [{
63+ "data_row_id" : dr_1 .uid ,
64+ "global_key" : gk_1
65+ }, {
66+ "data_row_id" : dr_2 .uid ,
67+ "global_key" : gk_1
68+ }]
69+ res = client .assign_global_keys_to_data_rows (assignment_inputs )
70+
71+ assert res ['status' ] == "PARTIAL SUCCESS"
72+ assert len (res ['results' ]) == 1
73+ assert res ['results' ][0 ]['data_row_id' ] == dr_1 .uid
74+ assert res ['results' ][0 ]['global_key' ] == gk_1
75+
76+ assert len (res ['errors' ]) == 1
77+ assert res ['errors' ][0 ]['data_row_id' ] == dr_2 .uid
78+ assert res ['errors' ][0 ]['global_key' ] == gk_1
79+ assert res ['errors' ][0 ]['error' ] == "Invalid global key"
0 commit comments