Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSoC2024] - add/rest-api-tests-for-attribute-rename #7754

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

ritikraj26
Copy link
Contributor

Added rest-api tests for attribute rename feature.

Motivation and context

These rest-api tests are to validate the changes introduced in the PR here

How has this been tested?

Checklist

  • I submit my changes into the develop branch
    - [ ] I have created a changelog fragment
    - [ ] I have updated the documentation accordingly
  • I have added tests to cover my changes
    - [ ] I have linked related issues (see GitHub docs)
    - [ ] I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

@ritikraj26
Copy link
Contributor Author

Hi @Marishka17 @nmanovic
I have added the rest-api tests for the attribute rename feature here.

@ritikraj26
Copy link
Contributor Author

Hi @azhavoro,
Can you review this one?

Comment on lines 685 to 693
label = next(
iter(
self._labels_by_source(
self.labels, source_key=self._get_source_info(source).label_source_key
).values()
)
)[0]

if label.get("attributes"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a label with attributes should be selected here. Overwise the test will always pass if a label has no attributes and there will be no point in such a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

newvalue = label.get("attributes")

for value in newvalue:
if value.get("id"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since a label with attributes is selected from existing ones, each attribute must contain id.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 705 to 706
if "attributes.id" in ignore_fields:
ignore_fields.remove("attributes.id")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be handled in _get_patch_data function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ritikraj26
Copy link
Contributor Author

@Marishka17
A review of this 😅

Comment on lines 73 to 80
def _labels_with_attributes(labels: List[Dict], *,source_key: str) -> Dict[int, Dict]:
labels_with_attributes = {}
for label in labels:
label_source = label.get(source_key)
if label_source and label.get("attributes"):
labels_with_attributes.setdefault(label_source, []).append(label)

return labels_with_attributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, such a function should just keep labels with attributes and return a filtered list (without filtering by source_key). But I don't see now the real necessity to move this logic in a separate function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the function.

]
filtered_attributes = self._attributes_with_id(deepcopy(original_data.get("attributes", [])))

if overrides.get("attributes")[0].get("id") is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, it is not a good approach to rely only on the first attribute from the list. You can add some argument (which can determine whether new attributes are being added or updated) to _get_patch_data and rely on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Comment on lines 710 to 716
param = "attributes"
newvalue = label.get("attributes")

for value in newvalue:
value.update({"name": value["name"] + "_updated"})

expected_data, patch_data, ignore_fields = self._get_patch_data(label, **{param: newvalue})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
param = "attributes"
newvalue = label.get("attributes")
for value in newvalue:
value.update({"name": value["name"] + "_updated"})
expected_data, patch_data, ignore_fields = self._get_patch_data(label, **{param: newvalue})
attributes = label["attributes"]
for attribute in attributes:
attribute["name"] += "_updated"
expected_data, patch_data, ignore_fields = self._get_patch_data(label, attributes=attributes)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

payload["attributes"] = (original_data.get("attributes") or []) + overrides[
"attributes"
]
filtered_attributes = self._attributes_with_id(deepcopy(original_data.get("attributes", [])))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to use _attributes_with_id here? Since original_data represents a created label taken from assets, then if a label contains attributes -> each attribute has id.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this extra step.

@@ -656,6 +688,30 @@ def test_can_patch_label_field(self, source, admin_user, param, newvalue):
).values()
)
)[0]
print('label', label)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the debug code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ritikraj26
Copy link
Contributor Author

@Marishka17
A review of this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants