Skip to content

Commit

Permalink
[GSoC2024] - add/rest-api-tests-for-attribute-rename (#7754)
Browse files Browse the repository at this point in the history
Added rest-api tests for attribute rename feature.

These rest-api tests are to validate the changes introduced in the PR
[here](#7670)

---------

Co-authored-by: Maria Khrustaleva <maria@cvat.ai>
  • Loading branch information
ritikraj26 and Marishka17 committed Jun 28, 2024
1 parent b6159aa commit 6d49b89
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions tests/python/rest_api/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,25 @@ def _get_patch_data(
if overrides:
payload = deepcopy(overrides)

if overrides.get("attributes"):
payload["attributes"] = (original_data.get("attributes") or []) + overrides[
"attributes"
]
result["attributes"] = deepcopy(payload["attributes"])
ignore_fields.append("attributes.id")
if overridden_attributes := deepcopy(overrides.get("attributes", [])):
combined_attributes = deepcopy(original_data.get("attributes", []))

mapping = {attr["id"]: attr for attr in overridden_attributes if "id" in attr}

# no attributes to update
if not mapping:
ignore_fields.append("attributes.id")

for attr in combined_attributes:
if attr["id"] in mapping:
attr.update(mapping[attr["id"]])

for attr in overridden_attributes:
if attr not in combined_attributes:
combined_attributes.append(attr)

payload["attributes"] = deepcopy(combined_attributes)
result["attributes"] = deepcopy(combined_attributes)

# Changing skeletons is not supported
if overrides.get("type") == "skeleton":
Expand Down Expand Up @@ -663,6 +676,34 @@ def test_can_patch_label_field(self, source, admin_user, param, newvalue):
user, label["id"], patch_data, expected_data=expected_data, ignore_fields=ignore_fields
)

@parametrize("source", _TestLabelsPermissionsBase.source_types)
def test_can_patch_attribute_name(self, source: str, admin_user: str):
source_key = self._get_source_info(source).label_source_key
label = next(
(
l
for l in self.labels
if l.get(source_key) and not l["has_parent"] and l.get("attributes")
)
)

attributes = deepcopy(label["attributes"])

for attribute in attributes:
attribute["name"] += "_updated"

expected_data, patch_data, ignore_fields = self._get_patch_data(
label, attributes=attributes
)

self._test_update_ok(
admin_user,
label["id"],
patch_data,
expected_data=expected_data,
ignore_fields=ignore_fields,
)

@parametrize("source", _TestLabelsPermissionsBase.source_types)
def test_cannot_patch_sublabel_directly(self, admin_user, source):
user = admin_user
Expand Down

0 comments on commit 6d49b89

Please sign in to comment.