Skip to content

Commit

Permalink
code consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathanjp91 committed Nov 7, 2023
1 parent de127ad commit 3cfbdce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 8 additions & 6 deletions darwin/future/core/items/set_item_layout.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
from __future__ import annotations

from typing import Dict

from darwin.future.core.client import ClientCore
from darwin.future.core.types.common import JSONType
from darwin.future.data_objects.item import ItemLayout
from darwin.future.data_objects.typing import UnknownType


def set_item_layout(
client: ClientCore,
team_slug: str,
dataset_ids: int | list[int],
layout: ItemLayout,
params: JSONType,
filters: Dict[str, UnknownType],
) -> JSONType:
"""
Set the layout of a dataset and filtered items via params.
Set the layout of a dataset and filtered items via filters.
Args:
client (ClientCore): The Darwin Core client.
team_slug (str): The team slug.
dataset_ids (int | list[int]): The dataset ids.
layout (ItemLayout): The layout.
params (JSONType): The parameters.
filters Dict[str, UnknownType]: The parameters of the filter.
Returns:
JSONType: The response data.
"""
assert (
params
filters
), "No parameters provided, please provide at least one non-dataset id filter"
assert isinstance(params, dict), "Parameters must be a dictionary of filters"
payload = {
"filters": {
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
**params,
**filters,
},
"layout": dict(layout),
}
Expand Down
6 changes: 4 additions & 2 deletions darwin/future/tests/core/items/test_set_item_layout.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import Dict

import pytest
import responses
from requests import HTTPError

from darwin.future.core.client import ClientCore
from darwin.future.core.items.set_item_layout import set_item_layout
from darwin.future.core.types.common import JSONType
from darwin.future.data_objects.item import ItemLayout
from darwin.future.data_objects.typing import UnknownType
from darwin.future.tests.core.fixtures import *
from darwin.future.tests.core.items.fixtures import *

Expand Down Expand Up @@ -35,7 +37,7 @@ def test_set_item_layout_raises_on_incorrect_parameters(
) -> None:
team_slug = "my_team"
dataset_ids = [1, 2, 3]
params: JSONType = {}
params: Dict[str, UnknownType] = {}

with pytest.raises(AssertionError):
set_item_layout(base_client, team_slug, dataset_ids, base_layout, params)
Expand Down

0 comments on commit 3cfbdce

Please sign in to comment.