-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] SDK - Add support for response status (#4977)
<!-- Thanks for your contribution! As part of our Community Growers initiative 🌱, we're donating Justdiggit bunds in your name to reforest sub-Saharan Africa. To claim your Community Growers certificate, please contact David Berenstein in our Slack community or fill in this form https://tally.so/r/n9XrxK once your PR has been merged. --> # Description This PR adds support to provide the status for record responses. This is quite important to admin users when restoring annotated data from external sources. Also, the migration script from the legacy dataset can benefit the change. When several statuses are found for the same user before sending data to the server, a warning is shown to the users and the `draft` status is selected. **Type of change** (Please delete options that are not relevant. Remember to title the PR according to the type of change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Refactor (change restructuring the codebase without changing functionality) - [ ] Improvement (change adding some improvement to an existing functionality) **How Has This Been Tested** (Please describe the tests that you ran to verify your changes. And ideally, reference `tests`) - [ ] Test A - [ ] Test B **Checklist** - [ ] I added relevant documentation - [ ] I followed the style guidelines of this project - [ ] I did a self-review of my code - [ ] I made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I filled out [the contributor form](https://tally.so/r/n9XrxK) (see text above) - [ ] I have added relevant notes to the `CHANGELOG.md` file (See https://keepachangelog.com/)
- Loading branch information
1 parent
aa2cbe6
commit 279ff4e
Showing
4 changed files
with
162 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Copyright 2024-present, Argilla, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import uuid | ||
|
||
import pytest | ||
|
||
from argilla_sdk import UserResponse, Response | ||
|
||
|
||
class TestResponses: | ||
def test_create_user_response(self): | ||
user_id = uuid.uuid4() | ||
response = UserResponse( | ||
answers=[ | ||
Response(question_name="question", value="answer", user_id=user_id), | ||
Response(question_name="other-question", value="answer", user_id=user_id), | ||
], | ||
) | ||
|
||
assert response.to_dict() == { | ||
"values": { | ||
"question": {"value": "answer"}, | ||
"other-question": {"value": "answer"}, | ||
}, | ||
"status": "draft", | ||
"user_id": str(user_id), | ||
} | ||
|
||
def test_create_submitted_user_responses(self): | ||
user_id = uuid.uuid4() | ||
response = UserResponse( | ||
answers=[ | ||
Response(question_name="question", value="answer", user_id=user_id, status="submitted"), | ||
Response(question_name="other-question", value="answer", user_id=user_id, status="submitted"), | ||
], | ||
) | ||
|
||
assert response.to_dict() == { | ||
"values": { | ||
"question": {"value": "answer"}, | ||
"other-question": {"value": "answer"}, | ||
}, | ||
"status": "submitted", | ||
"user_id": str(user_id), | ||
} | ||
|
||
def test_create_user_response_with_multiple_status(self): | ||
user_id = uuid.uuid4() | ||
response = UserResponse( | ||
answers=[ | ||
Response(question_name="question", value="answer", user_id=user_id, status="draft"), | ||
Response(question_name="other-question", value="answer", user_id=user_id, status="submitted"), | ||
], | ||
) | ||
|
||
assert response.to_dict() == { | ||
"values": { | ||
"question": {"value": "answer"}, | ||
"other-question": {"value": "answer"}, | ||
}, | ||
"status": "draft", | ||
"user_id": str(user_id), | ||
} | ||
|
||
def test_create_user_response_with_multiple_user_id(self): | ||
user_id = uuid.uuid4() | ||
other_user_id = uuid.uuid4() | ||
|
||
with pytest.raises(ValueError, match="Multiple user_ids found in user answers"): | ||
UserResponse( | ||
answers=[ | ||
Response(question_name="question", value="answer", user_id=user_id), | ||
Response(question_name="other-question", value="answer", user_id=other_user_id), | ||
], | ||
) |