Skip to content

Commit

Permalink
Added sad path tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JBWilkie committed Nov 13, 2023
1 parent da5269a commit 5ab44b0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
28 changes: 28 additions & 0 deletions darwin/future/tests/meta/objects/test_itemmeta.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from uuid import UUID

import pytest
import responses
from responses import json_params_matcher

from darwin.future.data_objects.item import ItemLayout, ItemSlot
from darwin.future.exceptions import BadRequest
from darwin.future.meta.objects.item import Item
from darwin.future.tests.meta.objects.fixtures import *

Expand Down Expand Up @@ -69,3 +71,29 @@ def test_move_to_folder(item: Item) -> None:
json={},
)
item.move_to_folder(path)


def test_move_to_folder_raises_on_incorrect_parameters(item: Item) -> None:
with responses.RequestsMock() as rsps:
team_slug = item.meta_params["team_slug"]
dataset_id = item.meta_params["dataset_id"]
path = 1234
rsps.add(
rsps.POST,
item.client.config.api_endpoint + f"v2/teams/{team_slug}/items/path",
status=400,
match=[
json_params_matcher(
{
"filters": {
"item_ids": [str(item.id)],
"dataset_ids": [dataset_id],
},
"path": path,
}
)
],
json={},
)
with pytest.raises(BadRequest):
item.move_to_folder(path)
41 changes: 40 additions & 1 deletion darwin/future/tests/meta/queries/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from responses.matchers import json_params_matcher, query_param_matcher

from darwin.future.core.client import ClientCore
from darwin.future.exceptions import BadRequest
from darwin.future.meta.objects.item import Item
from darwin.future.meta.queries.item import ItemQuery
from darwin.future.tests.core.fixtures import *
Expand Down Expand Up @@ -72,7 +73,7 @@ def test_delete(
item_query.delete()


def test_move_to_folders(
def test_move_to_folder(
item_query: ItemQuery, items_json: List[dict], items: List[Item]
) -> None:
with responses.RequestsMock() as rsps:
Expand Down Expand Up @@ -107,3 +108,41 @@ def test_move_to_folders(
json={},
)
item_query.move_to_folder(path)


def test_move_to_folder_raises_on_incorrect_parameters(
item_query: ItemQuery, items_json: List[dict], items: List[Item]
) -> None:
with responses.RequestsMock() as rsps:
rsps.add(
rsps.GET,
item_query.client.config.api_endpoint + "v2/teams/test/items",
match=[
query_param_matcher(
{"page[offset]": "0", "page[size]": "500", "dataset_ids": "1"}
)
],
json={"items": items_json, "errors": []},
)
team_slug = items[0].meta_params["team_slug"]
dataset_id = items[0].meta_params["dataset_id"]
path = 1234
rsps.add(
rsps.POST,
items[0].client.config.api_endpoint + f"v2/teams/{team_slug}/items/path",
status=400,
match=[
json_params_matcher(
{
"filters": {
"item_ids": [str(item.id) for item in items],
"dataset_ids": [dataset_id],
},
"path": path,
}
)
],
json={},
)
with pytest.raises(BadRequest):
item_query.move_to_folder(path)

0 comments on commit 5ab44b0

Please sign in to comment.