-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add pageResolution field (#1303)
- Loading branch information
1 parent
da33398
commit 0d5e22a
Showing
6 changed files
with
156 additions
and
4 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
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,25 @@ | ||
"""Utilities to handle assets.""" | ||
from dataclasses import dataclass | ||
from typing import Any, Dict | ||
|
||
|
||
@dataclass | ||
class PageResolution: | ||
"""A wrapper for PageResolution GraphQL object.""" | ||
|
||
width: float | ||
height: float | ||
page_number: int | ||
rotation: int = 0 | ||
|
||
def as_dict(self) -> Dict[str, Any]: | ||
"""Return a dictionary representation of the object.""" | ||
output = { | ||
"width": self.width, | ||
"height": self.height, | ||
"pageNumber": self.page_number, | ||
} | ||
if self.rotation != 0: | ||
output["rotation"] = self.rotation | ||
|
||
return output |
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,70 @@ | ||
"""Tests for the asset mutations.""" | ||
import pytest | ||
import pytest_mock | ||
|
||
from kili.entrypoints.mutations.asset import MutationsAsset, PageResolution | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"page_resolutions_array", | ||
[ | ||
[ | ||
[ | ||
{"width": 100, "height": 200, "pageNumber": 1}, | ||
{"width": 200, "height": 300, "pageNumber": 0}, | ||
] | ||
], | ||
[ | ||
[ | ||
PageResolution(width=100, height=200, page_number=1), | ||
PageResolution(width=200, height=300, page_number=0), | ||
] | ||
], | ||
], | ||
) | ||
def test_given_page_resolutions_when_i_call_update_properties_in_assets_it_calls_the_resolvers_correctly( | ||
page_resolutions_array, | ||
mocker: pytest_mock.MockerFixture, | ||
): | ||
"""Test update_properties_in_assets for resolution update.""" | ||
# Given | ||
kili = MutationsAsset() | ||
kili.graphql_client = mocker.MagicMock() | ||
|
||
asset_ids = ["asset_id"] | ||
|
||
# When | ||
kili.update_properties_in_assets( | ||
asset_ids=asset_ids, page_resolutions_array=page_resolutions_array | ||
) | ||
|
||
# Then | ||
kili.graphql_client.execute.assert_called_once_with( | ||
( | ||
"\nmutation(\n $whereArray: [AssetWhere!]!\n $dataArray: [AssetData!]!\n) {\n" | ||
" data: updatePropertiesInAssets(\n where: $whereArray,\n data: $dataArray\n" | ||
" ) {\n id\n }\n}\n" | ||
), | ||
{ | ||
"whereArray": [{"id": "asset_id"}], | ||
"dataArray": [ | ||
{ | ||
"priority": None, | ||
"jsonMetadata": None, | ||
"consensusMark": None, | ||
"honeypotMark": None, | ||
"toBeLabeledBy": None, | ||
"shouldResetToBeLabeledBy": True, | ||
"content": None, | ||
"jsonContent": None, | ||
"status": None, | ||
"isUsedForConsensus": None, | ||
"isHoneypot": None, | ||
"pageResolutions": [ | ||
{"width": 100, "height": 200, "pageNumber": 1}, | ||
{"width": 200, "height": 300, "pageNumber": 0}, | ||
], | ||
} | ||
], | ||
}, | ||
) |