|
7 | 7 |
|
8 | 8 | from labelbox import DataRow |
9 | 9 | from labelbox.schema.data_row_metadata import DataRowMetadataField |
| 10 | +from labelbox.exceptions import MalformedQueryException |
10 | 11 | import labelbox.exceptions |
11 | 12 |
|
12 | 13 | SPLIT_SCHEMA_ID = "cko8sbczn0002h2dkdaxb5kal" |
@@ -645,3 +646,52 @@ def test_data_row_bulk_creation_with_same_global_keys(dataset, sample_image): |
645 | 646 | assert task.status == "COMPLETE" |
646 | 647 | assert len(list(dataset.data_rows())) == 1 |
647 | 648 | assert list(dataset.data_rows())[0].global_key == global_key_1 |
| 649 | + |
| 650 | + |
| 651 | +def test_data_row_bulk_creation_sync_with_unique_global_keys( |
| 652 | + dataset, sample_image): |
| 653 | + global_key_1 = str(uuid.uuid4()) |
| 654 | + global_key_2 = str(uuid.uuid4()) |
| 655 | + global_key_3 = str(uuid.uuid4()) |
| 656 | + |
| 657 | + dataset.create_data_rows_sync([ |
| 658 | + { |
| 659 | + DataRow.row_data: sample_image, |
| 660 | + DataRow.global_key: global_key_1 |
| 661 | + }, |
| 662 | + { |
| 663 | + DataRow.row_data: sample_image, |
| 664 | + DataRow.global_key: global_key_2 |
| 665 | + }, |
| 666 | + { |
| 667 | + DataRow.row_data: sample_image, |
| 668 | + DataRow.global_key: global_key_3 |
| 669 | + }, |
| 670 | + ]) |
| 671 | + |
| 672 | + assert {row.global_key for row in dataset.data_rows() |
| 673 | + } == {global_key_1, global_key_2, global_key_3} |
| 674 | + |
| 675 | + |
| 676 | +def test_data_row_rulk_creation_sync_with_same_global_keys( |
| 677 | + dataset, sample_image): |
| 678 | + global_key_1 = str(uuid.uuid4()) |
| 679 | + |
| 680 | + with pytest.raises(labelbox.exceptions.MalformedQueryException): |
| 681 | + dataset.create_data_rows_sync([{ |
| 682 | + DataRow.row_data: sample_image, |
| 683 | + DataRow.global_key: global_key_1 |
| 684 | + }, { |
| 685 | + DataRow.row_data: sample_image, |
| 686 | + DataRow.global_key: global_key_1 |
| 687 | + }]) |
| 688 | + |
| 689 | + assert len(list(dataset.data_rows())) == 0 |
| 690 | + |
| 691 | + dataset.create_data_rows_sync([{ |
| 692 | + DataRow.row_data: sample_image, |
| 693 | + DataRow.global_key: global_key_1 |
| 694 | + }]) |
| 695 | + |
| 696 | + assert len(list(dataset.data_rows())) == 1 |
| 697 | + assert list(dataset.data_rows())[0].global_key == global_key_1 |
0 commit comments