Repository navigation
[PLT-4664] Add Project.clear_queue_reservations #2087
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
85 changes: 85 additions & 0 deletions
85
libs/labelbox/tests/unit/test_unit_project_clear_queue_reservations.py
This file contains hidden or 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,85 @@ | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
| from lbox.exceptions import LabelboxError | ||
|
|
||
| from labelbox.schema.project import Project | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_client(): | ||
| return MagicMock() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def project(mock_client): | ||
| return Project( | ||
| mock_client, | ||
| { | ||
| "id": "test_project_id", | ||
| "name": "test", | ||
| "createdAt": "2021-06-01T00:00:00.000Z", | ||
| "updatedAt": "2021-06-01T00:00:00.000Z", | ||
| "autoAuditNumberOfLabels": 1, | ||
| "autoAuditPercentage": 100, | ||
| "dataRowCount": 1, | ||
| "description": "test", | ||
| "editorTaskType": "MODEL_CHAT_EVALUATION", | ||
| "lastActivityTime": "2021-06-01T00:00:00.000Z", | ||
| "allowedMediaType": "IMAGE", | ||
| "setupComplete": "2021-06-01T00:00:00.000Z", | ||
| "modelSetupComplete": None, | ||
| "uploadType": "Auto", | ||
| "isBenchmarkEnabled": False, | ||
| "isConsensusEnabled": False, | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
| def test_clear_queue_reservations_sends_mutation_and_returns_count( | ||
| project, mock_client | ||
| ): | ||
| mock_client.execute.return_value = { | ||
| "clearQueueReservations": { | ||
| "success": True, | ||
| "clearedReservationCount": 12, | ||
| } | ||
| } | ||
|
|
||
| result = project.clear_queue_reservations("queue_1") | ||
|
|
||
| assert result == 12 | ||
| mock_client.execute.assert_called_once() | ||
| query_str, params = mock_client.execute.call_args[0] | ||
| assert "ClearQueueReservationsPyApi" in query_str | ||
| assert "clearedReservationCount" in query_str | ||
| assert params == { | ||
| "input": {"projectId": "test_project_id", "queueId": "queue_1"} | ||
| } | ||
|
|
||
|
|
||
| def test_clear_queue_reservations_returns_none_when_count_unknown( | ||
| project, mock_client | ||
| ): | ||
| mock_client.execute.return_value = { | ||
| "clearQueueReservations": { | ||
| "success": True, | ||
| "clearedReservationCount": None, | ||
| } | ||
| } | ||
|
|
||
| assert project.clear_queue_reservations("queue_1") is None | ||
|
|
||
|
|
||
| def test_clear_queue_reservations_raises_on_server_failure( | ||
| project, mock_client | ||
| ): | ||
| mock_client.execute.return_value = { | ||
| "clearQueueReservations": { | ||
| "success": False, | ||
| "clearedReservationCount": None, | ||
| } | ||
| } | ||
|
|
||
| with pytest.raises(LabelboxError, match="queue_1"): | ||
| project.clear_queue_reservations("queue_1") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing queue raises TypeError
Medium Severity
When the queue is not in the project,
client.executereturnsNonefor aRESOURCE_NOT_FOUNDGraphQL error. Indexing that result then raisesTypeErrorinstead of the documentedResourceNotFoundError, so callers catching that exception miss the failure.Additional Locations (1)
libs/labelbox/src/labelbox/schema/project.py#L1567-L1569Reviewed by Cursor Bugbot for commit 9c9c3ce. Configure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid:
executereturnsNoneonRESOURCE_NOT_FOUNDwithoutraise_return_resource_not_found=True. This PR merged before the fix; fixed in #2090.