|
5 | 5 | from responses.matchers import json_params_matcher, query_param_matcher |
6 | 6 |
|
7 | 7 | from darwin.future.core.client import ClientCore |
| 8 | +from darwin.future.exceptions import BadRequest |
8 | 9 | from darwin.future.meta.objects.item import Item |
9 | 10 | from darwin.future.meta.queries.item import ItemQuery |
10 | 11 | from darwin.future.tests.core.fixtures import * |
@@ -70,3 +71,78 @@ def test_delete( |
70 | 71 | json={}, |
71 | 72 | ) |
72 | 73 | item_query.delete() |
| 74 | + |
| 75 | + |
| 76 | +def test_move_to_folder( |
| 77 | + item_query: ItemQuery, items_json: List[dict], items: List[Item] |
| 78 | +) -> None: |
| 79 | + with responses.RequestsMock() as rsps: |
| 80 | + rsps.add( |
| 81 | + rsps.GET, |
| 82 | + item_query.client.config.api_endpoint + "v2/teams/test/items", |
| 83 | + match=[ |
| 84 | + query_param_matcher( |
| 85 | + {"page[offset]": "0", "page[size]": "500", "dataset_ids": "1"} |
| 86 | + ) |
| 87 | + ], |
| 88 | + json={"items": items_json, "errors": []}, |
| 89 | + ) |
| 90 | + team_slug = items[0].meta_params["team_slug"] |
| 91 | + dataset_id = items[0].meta_params["dataset_id"] |
| 92 | + path = "/new_folder" |
| 93 | + rsps.add( |
| 94 | + rsps.POST, |
| 95 | + items[0].client.config.api_endpoint + f"v2/teams/{team_slug}/items/path", |
| 96 | + status=200, |
| 97 | + match=[ |
| 98 | + json_params_matcher( |
| 99 | + { |
| 100 | + "filters": { |
| 101 | + "item_ids": [str(item.id) for item in items], |
| 102 | + "dataset_ids": [dataset_id], |
| 103 | + }, |
| 104 | + "path": path, |
| 105 | + } |
| 106 | + ) |
| 107 | + ], |
| 108 | + json={}, |
| 109 | + ) |
| 110 | + item_query.move_to_folder(path) |
| 111 | + |
| 112 | + |
| 113 | +def test_move_to_folder_raises_on_incorrect_parameters( |
| 114 | + item_query: ItemQuery, items_json: List[dict], items: List[Item] |
| 115 | +) -> None: |
| 116 | + with responses.RequestsMock() as rsps: |
| 117 | + rsps.add( |
| 118 | + rsps.GET, |
| 119 | + item_query.client.config.api_endpoint + "v2/teams/test/items", |
| 120 | + match=[ |
| 121 | + query_param_matcher( |
| 122 | + {"page[offset]": "0", "page[size]": "500", "dataset_ids": "1"} |
| 123 | + ) |
| 124 | + ], |
| 125 | + json={"items": items_json, "errors": []}, |
| 126 | + ) |
| 127 | + team_slug = items[0].meta_params["team_slug"] |
| 128 | + dataset_id = items[0].meta_params["dataset_id"] |
| 129 | + path = 1234 |
| 130 | + rsps.add( |
| 131 | + rsps.POST, |
| 132 | + items[0].client.config.api_endpoint + f"v2/teams/{team_slug}/items/path", |
| 133 | + status=400, |
| 134 | + match=[ |
| 135 | + json_params_matcher( |
| 136 | + { |
| 137 | + "filters": { |
| 138 | + "item_ids": [str(item.id) for item in items], |
| 139 | + "dataset_ids": [dataset_id], |
| 140 | + }, |
| 141 | + "path": path, |
| 142 | + } |
| 143 | + ) |
| 144 | + ], |
| 145 | + json={}, |
| 146 | + ) |
| 147 | + with pytest.raises(BadRequest): |
| 148 | + item_query.move_to_folder(path) |
0 commit comments