|
1 | 1 | import tempfile |
| 2 | +from copy import deepcopy |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 | from src.superannotate import AppException |
@@ -562,6 +563,97 @@ def test_update_annotation_class_no_changes(self): |
562 | 563 | len(classes[0]["attribute_groups"]), |
563 | 564 | ) |
564 | 565 |
|
| 566 | + def test_update_annotation_class_duplicated_groups(self): |
| 567 | + # Create annotation class |
| 568 | + sa.create_annotation_class( |
| 569 | + self.PROJECT_NAME, |
| 570 | + "test_update_nochange", |
| 571 | + "#00FFFF", |
| 572 | + attribute_groups=[ |
| 573 | + { |
| 574 | + "name": "Category", |
| 575 | + "group_type": "radio", |
| 576 | + "attributes": [{"name": "A"}, {"name": "B"}], |
| 577 | + } |
| 578 | + ], |
| 579 | + ) |
| 580 | + |
| 581 | + # Retrieve class |
| 582 | + classes = sa.search_annotation_classes( |
| 583 | + self.PROJECT_NAME, "test_update_nochange" |
| 584 | + ) |
| 585 | + |
| 586 | + # Update with same data |
| 587 | + new_group = deepcopy(classes[0]["attribute_groups"][0]) |
| 588 | + new_group["name"] = "New name" |
| 589 | + new_group["attributes"][0]["name"] = "New attr1" |
| 590 | + new_group["attributes"][1]["name"] = "New attr2" |
| 591 | + update_response = sa.update_annotation_class( |
| 592 | + self.PROJECT_NAME, |
| 593 | + "test_update_nochange", |
| 594 | + attribute_groups=[classes[0]["attribute_groups"][0], new_group], |
| 595 | + ) |
| 596 | + # not validated response, second class that contain ids ignored |
| 597 | + assert len(update_response["attribute_groups"]) == 1 |
| 598 | + assert True |
| 599 | + |
| 600 | + def test_update_annotation_class_invalid_group_type(self): |
| 601 | + # Create annotation class |
| 602 | + sa.create_annotation_class( |
| 603 | + self.PROJECT_NAME, |
| 604 | + "test_update_nochange", |
| 605 | + "#00FFFF", |
| 606 | + attribute_groups=[ |
| 607 | + { |
| 608 | + "name": "Category", |
| 609 | + "group_type": "radio", |
| 610 | + "attributes": [{"name": "A"}, {"name": "B"}], |
| 611 | + } |
| 612 | + ], |
| 613 | + ) |
| 614 | + |
| 615 | + # Retrieve class |
| 616 | + classes = sa.search_annotation_classes( |
| 617 | + self.PROJECT_NAME, "test_update_nochange" |
| 618 | + ) |
| 619 | + |
| 620 | + classes[0]["attribute_groups"][0]["group_type"] = "invalid" |
| 621 | + with self.assertRaisesRegexp(AppException, "Invalid group_type: invalid"): |
| 622 | + sa.update_annotation_class( |
| 623 | + self.PROJECT_NAME, |
| 624 | + "test_update_nochange", |
| 625 | + attribute_groups=classes[0]["attribute_groups"], |
| 626 | + ) |
| 627 | + |
| 628 | + def test_update_annotation_class_without_group_type(self): |
| 629 | + # Create annotation class |
| 630 | + sa.create_annotation_class( |
| 631 | + self.PROJECT_NAME, |
| 632 | + "test_update_nochange", |
| 633 | + "#00FFFF", |
| 634 | + attribute_groups=[ |
| 635 | + { |
| 636 | + "name": "Category", |
| 637 | + "group_type": "radio", |
| 638 | + "attributes": [{"name": "A"}, {"name": "B"}], |
| 639 | + } |
| 640 | + ], |
| 641 | + ) |
| 642 | + |
| 643 | + # Retrieve class |
| 644 | + classes = sa.search_annotation_classes( |
| 645 | + self.PROJECT_NAME, "test_update_nochange" |
| 646 | + ) |
| 647 | + |
| 648 | + del classes[0]["attribute_groups"][0]["group_type"] |
| 649 | + with self.assertRaisesRegexp(AppException, "Invalid group_type: invalid"): |
| 650 | + res = sa.update_annotation_class( |
| 651 | + self.PROJECT_NAME, |
| 652 | + "test_update_nochange", |
| 653 | + attribute_groups=classes[0]["attribute_groups"], |
| 654 | + ) |
| 655 | + assert res["attribute_groups"][0]["group_type"] == "radio" |
| 656 | + |
565 | 657 |
|
566 | 658 | class TestVideoCreateAnnotationClasses(BaseTestCase): |
567 | 659 | PROJECT_NAME = "TestVideoCreateAnnotationClasses" |
|
0 commit comments