|
| 1 | +import pytest |
1 | 2 | import responses |
2 | 3 | from responses import matchers |
3 | 4 |
|
@@ -117,6 +118,14 @@ def test_create_tag(self): |
117 | 118 | academy_tag_parent_id = client.tags.create(name="academy", parent=tag["id"]) |
118 | 119 | academy_tag_parent_tag = client.tags.create(name="academy", parent=tag) |
119 | 120 |
|
| 121 | + with pytest.raises(TypeError): |
| 122 | + client.tags.create( |
| 123 | + name="academy", |
| 124 | + parent=123, # pyright: ignore[reportArgumentType] |
| 125 | + ) |
| 126 | + with pytest.raises(ValueError): |
| 127 | + client.tags.create(name="academy", parent="") |
| 128 | + |
120 | 129 | # assert |
121 | 130 | assert mock_create_tag.call_count == 2 |
122 | 131 |
|
@@ -285,15 +294,105 @@ def test_destroy(self): |
285 | 294 | class TestContentItemTags: |
286 | 295 | @responses.activate |
287 | 296 | def test_find(self): |
288 | | - # TODO-barret |
289 | | - raise NotImplementedError |
| 297 | + # behavior |
| 298 | + content_item_guid = "f2f37341-e21d-3d80-c698-a935ad614066" |
| 299 | + mock_get = responses.get( |
| 300 | + f"https://connect.example/__api__/v1/content/{content_item_guid}", |
| 301 | + json=load_mock_dict(f"v1/content/{content_item_guid}.json"), |
| 302 | + ) |
| 303 | + mock_tags_get = responses.get( |
| 304 | + f"https://connect.example/__api__/v1/content/{content_item_guid}/tags", |
| 305 | + json=load_mock_list(f"v1/content/{content_item_guid}/tags.json"), |
| 306 | + ) |
| 307 | + |
| 308 | + # setup |
| 309 | + client = Client("https://connect.example", "12345") |
| 310 | + content_item = client.content.get(content_item_guid) |
| 311 | + |
| 312 | + # invoke |
| 313 | + tags = content_item.tags.find() |
| 314 | + |
| 315 | + # assert |
| 316 | + assert mock_get.call_count == 1 |
| 317 | + assert mock_tags_get.call_count == 1 |
| 318 | + assert len(tags) == 2 |
290 | 319 |
|
291 | 320 | @responses.activate |
292 | 321 | def test_add(self): |
293 | | - # TODO-barret |
294 | | - raise NotImplementedError |
| 322 | + # behavior |
| 323 | + content_item_guid = "f2f37341-e21d-3d80-c698-a935ad614066" |
| 324 | + tag_id = "33" |
| 325 | + mock_content_item_get = responses.get( |
| 326 | + f"https://connect.example/__api__/v1/content/{content_item_guid}", |
| 327 | + json=load_mock_dict(f"v1/content/{content_item_guid}.json"), |
| 328 | + ) |
| 329 | + mock_tag_get = responses.get( |
| 330 | + f"https://connect.example/__api__/v1/tags/{tag_id}", |
| 331 | + json=load_mock_dict(f"v1/tags/{tag_id}.json"), |
| 332 | + ) |
| 333 | + mock_tags_add = responses.post( |
| 334 | + f"https://connect.example/__api__/v1/content/{content_item_guid}/tags", |
| 335 | + json={}, # empty response |
| 336 | + ) |
| 337 | + |
| 338 | + # setup |
| 339 | + client = Client("https://connect.example", "12345") |
| 340 | + content_item = client.content.get(content_item_guid) |
| 341 | + |
| 342 | + sub_tag = client.tags.get("33") |
| 343 | + |
| 344 | + # invoke |
| 345 | + content_item.tags.add(sub_tag["id"]) |
| 346 | + content_item.tags.add(sub_tag) |
| 347 | + |
| 348 | + with pytest.raises(TypeError): |
| 349 | + content_item.tags.add( |
| 350 | + 123, # pyright: ignore[reportArgumentType] |
| 351 | + ) |
| 352 | + with pytest.raises(ValueError): |
| 353 | + content_item.tags.add("") |
| 354 | + |
| 355 | + # assert |
| 356 | + assert mock_content_item_get.call_count == 1 |
| 357 | + assert mock_tag_get.call_count == 1 |
| 358 | + assert mock_tags_add.call_count == 2 |
295 | 359 |
|
296 | 360 | @responses.activate |
297 | 361 | def test_delete(self): |
298 | | - # TODO-barret |
299 | | - raise NotImplementedError |
| 362 | + # behavior |
| 363 | + content_item_guid = "f2f37341-e21d-3d80-c698-a935ad614066" |
| 364 | + tag_id = "33" |
| 365 | + mock_content_item_get = responses.get( |
| 366 | + f"https://connect.example/__api__/v1/content/{content_item_guid}", |
| 367 | + json=load_mock_dict(f"v1/content/{content_item_guid}.json"), |
| 368 | + ) |
| 369 | + mock_tag_get = responses.get( |
| 370 | + f"https://connect.example/__api__/v1/tags/{tag_id}", |
| 371 | + json=load_mock_dict(f"v1/tags/{tag_id}.json"), |
| 372 | + ) |
| 373 | + mock_tags_delete = responses.delete( |
| 374 | + f"https://connect.example/__api__/v1/content/{content_item_guid}/tags/{tag_id}", |
| 375 | + json={}, # empty response |
| 376 | + ) |
| 377 | + |
| 378 | + # setup |
| 379 | + client = Client("https://connect.example", "12345") |
| 380 | + content_item = client.content.get(content_item_guid) |
| 381 | + |
| 382 | + sub_tag = client.tags.get("33") |
| 383 | + |
| 384 | + # invoke |
| 385 | + content_item.tags.delete(sub_tag["id"]) |
| 386 | + content_item.tags.delete(sub_tag) |
| 387 | + |
| 388 | + with pytest.raises(TypeError): |
| 389 | + content_item.tags.delete( |
| 390 | + 123, # pyright: ignore[reportArgumentType] |
| 391 | + ) |
| 392 | + with pytest.raises(ValueError): |
| 393 | + content_item.tags.delete("") |
| 394 | + |
| 395 | + # assert |
| 396 | + assert mock_content_item_get.call_count == 1 |
| 397 | + assert mock_tag_get.call_count == 1 |
| 398 | + assert mock_tags_delete.call_count == 2 |
0 commit comments