-
Notifications
You must be signed in to change notification settings - Fork 358
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
feat: add dataset support to be updated using distribution settings #5028
Merged
jfcalvo
merged 8 commits into
feat/create-datasets-with-distribution
from
feat/update-datasets-distribution
Jul 1, 2024
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5eb30fc
feat: add dataset support to update distribution settings
jfcalvo cf60aaa
Merge branch 'feat/create-datasets-with-distribution' into feat/updat…
jfcalvo f1090d5
chore: update CHANGELOG.md
jfcalvo 8e5a7c0
Merge branch 'feat/create-datasets-with-distribution' into feat/updat…
jfcalvo 1ffe9c8
Merge branch 'feat/create-datasets-with-distribution' into feat/updat…
jfcalvo b23f3d8
Merge branch 'feat/create-datasets-with-distribution' into feat/updat…
jfcalvo c8aa1a9
feat: raise an error when dataset is ready and distribution settings …
jfcalvo 58c8257
feat: add `count_submitted_responses` as property to `Records` databa…
jfcalvo 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 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
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
178 changes: 178 additions & 0 deletions
178
argilla-server/tests/unit/api/handlers/v1/datasets/test_update_dataset.py
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,178 @@ | ||
# Copyright 2021-present, the Recognai S.L. team. | ||
# | ||
# 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. | ||
|
||
from uuid import UUID | ||
|
||
import pytest | ||
from argilla_server.enums import DatasetDistributionStrategy, DatasetStatus | ||
from httpx import AsyncClient | ||
|
||
from tests.factories import DatasetFactory | ||
|
||
|
||
@pytest.mark.asyncio | ||
class TestUpdateDataset: | ||
def url(self, dataset_id: UUID) -> str: | ||
return f"/api/v1/datasets/{dataset_id}" | ||
|
||
async def test_update_dataset_distribution(self, async_client: AsyncClient, owner_auth_header: dict): | ||
dataset = await DatasetFactory.create() | ||
|
||
response = await async_client.patch( | ||
self.url(dataset.id), | ||
headers=owner_auth_header, | ||
json={ | ||
"distribution": { | ||
"strategy": DatasetDistributionStrategy.overlap, | ||
"min_submitted": 4, | ||
}, | ||
}, | ||
) | ||
|
||
assert response.status_code == 200 | ||
assert response.json()["distribution"] == { | ||
"strategy": DatasetDistributionStrategy.overlap, | ||
"min_submitted": 4, | ||
} | ||
|
||
assert dataset.distribution == { | ||
"strategy": DatasetDistributionStrategy.overlap, | ||
"min_submitted": 4, | ||
} | ||
|
||
async def test_update_dataset_without_distribution(self, async_client: AsyncClient, owner_auth_header: dict): | ||
dataset = await DatasetFactory.create() | ||
|
||
response = await async_client.patch( | ||
self.url(dataset.id), | ||
headers=owner_auth_header, | ||
json={"name": "Dataset updated name"}, | ||
) | ||
|
||
assert response.status_code == 200 | ||
assert response.json()["distribution"] == { | ||
"strategy": DatasetDistributionStrategy.overlap, | ||
"min_submitted": 1, | ||
} | ||
|
||
assert dataset.name == "Dataset updated name" | ||
assert dataset.distribution == { | ||
"strategy": DatasetDistributionStrategy.overlap, | ||
"min_submitted": 1, | ||
} | ||
|
||
async def test_update_dataset_without_distribution_for_published_dataset( | ||
self, async_client: AsyncClient, owner_auth_header: dict | ||
): | ||
dataset = await DatasetFactory.create(status=DatasetStatus.ready) | ||
|
||
response = await async_client.patch( | ||
self.url(dataset.id), | ||
headers=owner_auth_header, | ||
json={"name": "Dataset updated name"}, | ||
) | ||
|
||
assert response.status_code == 200 | ||
assert response.json()["distribution"] == { | ||
"strategy": DatasetDistributionStrategy.overlap, | ||
"min_submitted": 1, | ||
} | ||
|
||
assert dataset.name == "Dataset updated name" | ||
assert dataset.distribution == { | ||
"strategy": DatasetDistributionStrategy.overlap, | ||
"min_submitted": 1, | ||
} | ||
|
||
async def test_update_dataset_distribution_for_published_dataset( | ||
self, async_client: AsyncClient, owner_auth_header: dict | ||
): | ||
dataset = await DatasetFactory.create(status=DatasetStatus.ready) | ||
|
||
response = await async_client.patch( | ||
self.url(dataset.id), | ||
headers=owner_auth_header, | ||
json={ | ||
"distribution": { | ||
"strategy": DatasetDistributionStrategy.overlap, | ||
"min_submitted": 4, | ||
}, | ||
}, | ||
) | ||
|
||
assert response.status_code == 422 | ||
assert response.json() == {"detail": "Distribution settings cannot be modified for a published dataset"} | ||
|
||
assert dataset.distribution == { | ||
"strategy": DatasetDistributionStrategy.overlap, | ||
"min_submitted": 1, | ||
} | ||
|
||
async def test_update_dataset_distribution_with_invalid_strategy( | ||
self, async_client: AsyncClient, owner_auth_header: dict | ||
): | ||
dataset = await DatasetFactory.create() | ||
|
||
response = await async_client.patch( | ||
self.url(dataset.id), | ||
headers=owner_auth_header, | ||
json={ | ||
"distribution": { | ||
"strategy": "invalid_strategy", | ||
}, | ||
}, | ||
) | ||
|
||
assert response.status_code == 422 | ||
assert dataset.distribution == { | ||
"strategy": DatasetDistributionStrategy.overlap, | ||
"min_submitted": 1, | ||
} | ||
|
||
async def test_update_dataset_distribution_with_invalid_min_submitted_value( | ||
self, async_client: AsyncClient, owner_auth_header: dict | ||
): | ||
dataset = await DatasetFactory.create() | ||
|
||
response = await async_client.patch( | ||
self.url(dataset.id), | ||
headers=owner_auth_header, | ||
json={ | ||
"distribution": { | ||
"strategy": DatasetDistributionStrategy.overlap, | ||
"min_submitted": 0, | ||
}, | ||
}, | ||
) | ||
|
||
assert response.status_code == 422 | ||
assert dataset.distribution == { | ||
"strategy": DatasetDistributionStrategy.overlap, | ||
"min_submitted": 1, | ||
} | ||
|
||
async def test_update_dataset_distribution_as_none(self, async_client: AsyncClient, owner_auth_header: dict): | ||
dataset = await DatasetFactory.create() | ||
|
||
response = await async_client.patch( | ||
self.url(dataset.id), | ||
headers=owner_auth_header, | ||
json={"distribution": None}, | ||
) | ||
|
||
assert response.status_code == 422 | ||
assert dataset.distribution == { | ||
"strategy": DatasetDistributionStrategy.overlap, | ||
"min_submitted": 1, | ||
} |
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.
Even if I don't need the class method to be asynchronous, and not needing the session I prefer to have the same signature in all of them.