|
1 | 1 | """Tests for batch_update_list.""" |
2 | 2 |
|
3 | | -import asyncio |
4 | | -from http import HTTPStatus |
5 | 3 | from typing import Any |
6 | 4 |
|
7 | | -import aiohttp |
8 | 5 | from aioresponses import aioresponses |
9 | 6 | import pytest |
10 | 7 |
|
11 | | -from bring_api import ( |
12 | | - Bring, |
13 | | - BringAuthException, |
14 | | - BringItem, |
15 | | - BringItemOperation, |
16 | | - BringRequestException, |
17 | | -) |
| 8 | +from bring_api import Bring, BringItem, BringItemOperation |
18 | 9 |
|
19 | | -from .conftest import DEFAULT_HEADERS, UUID, load_fixture |
| 10 | +from .conftest import DEFAULT_HEADERS, UUID |
20 | 11 |
|
21 | 12 |
|
22 | 13 | @pytest.mark.parametrize( |
@@ -400,14 +391,12 @@ async def test_batch_update_list_single_item( |
400 | 391 | ) -> None: |
401 | 392 | """Test batch_update_list.""" |
402 | 393 | await bring.login() |
403 | | - r = await bring.batch_update_list(UUID, item, operation) |
| 394 | + await bring.batch_update_list(UUID, item, operation) |
404 | 395 |
|
405 | | - assert r.status == HTTPStatus.OK |
406 | 396 | mocked.assert_called_with( |
407 | 397 | f"https://api.getbring.com/rest/v2/bringlists/{UUID}/items", |
408 | 398 | method="PUT", |
409 | 399 | headers=DEFAULT_HEADERS, |
410 | | - data=None, |
411 | 400 | json=payload, |
412 | 401 | ) |
413 | 402 |
|
@@ -474,78 +463,11 @@ async def test_batch_update_list_multiple_items( |
474 | 463 | "sender": "", |
475 | 464 | } |
476 | 465 | await bring.login() |
477 | | - r = await bring.batch_update_list(UUID, test_items) |
| 466 | + await bring.batch_update_list(UUID, test_items) |
478 | 467 |
|
479 | | - assert r.status == HTTPStatus.OK |
480 | 468 | mocked.assert_called_with( |
481 | 469 | f"https://api.getbring.com/rest/v2/bringlists/{UUID}/items", |
482 | 470 | method="PUT", |
483 | 471 | headers=DEFAULT_HEADERS, |
484 | | - data=None, |
485 | 472 | json=payload, |
486 | 473 | ) |
487 | | - |
488 | | - |
489 | | -@pytest.mark.parametrize( |
490 | | - "exception", |
491 | | - [ |
492 | | - asyncio.TimeoutError, |
493 | | - aiohttp.ClientError, |
494 | | - ], |
495 | | -) |
496 | | -async def test_request_exception( |
497 | | - mocked: aioresponses, |
498 | | - bring: Bring, |
499 | | - exception: type[Exception], |
500 | | -) -> None: |
501 | | - """Test request exceptions.""" |
502 | | - await bring.login() |
503 | | - mocked.clear() |
504 | | - mocked.put( |
505 | | - f"https://api.getbring.com/rest/v2/bringlists/{UUID}/items", |
506 | | - exception=exception, |
507 | | - ) |
508 | | - |
509 | | - with pytest.raises(BringRequestException): |
510 | | - await bring.batch_update_list( |
511 | | - UUID, BringItem(itemId="item_name", spec="spec", uuid=UUID) |
512 | | - ) |
513 | | - |
514 | | - |
515 | | -async def test_unauthorized( |
516 | | - mocked: aioresponses, |
517 | | - bring: Bring, |
518 | | -) -> None: |
519 | | - """Test unauthorized exception.""" |
520 | | - await bring.login() |
521 | | - mocked.clear() |
522 | | - mocked.put( |
523 | | - f"https://api.getbring.com/rest/v2/bringlists/{UUID}/items", |
524 | | - status=HTTPStatus.UNAUTHORIZED, |
525 | | - body=load_fixture("error_response.json"), |
526 | | - ) |
527 | | - |
528 | | - with pytest.raises(BringAuthException): |
529 | | - await bring.batch_update_list( |
530 | | - UUID, BringItem(itemId="item_name", spec="spec", uuid=UUID) |
531 | | - ) |
532 | | - |
533 | | - |
534 | | -async def test_parse_exception( |
535 | | - mocked: aioresponses, |
536 | | - bring: Bring, |
537 | | -) -> None: |
538 | | - """Test parse exceptions.""" |
539 | | - await bring.login() |
540 | | - mocked.clear() |
541 | | - mocked.put( |
542 | | - f"https://api.getbring.com/rest/v2/bringlists/{UUID}/items", |
543 | | - status=HTTPStatus.UNAUTHORIZED, |
544 | | - body="not json", |
545 | | - content_type="application/json", |
546 | | - ) |
547 | | - |
548 | | - with pytest.raises(BringAuthException): |
549 | | - await bring.batch_update_list( |
550 | | - UUID, BringItem(itemId="item_name", spec="spec", uuid=UUID) |
551 | | - ) |
0 commit comments