Coverage for tests/test_customers_asynchro_extra.py: 100%
42 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-09 19:37 +0200
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-09 19:37 +0200
1"""Tests de la sous-cliente customers (asynchrone)."""
2from __future__ import annotations
4from typing import Any
5from unittest.mock import AsyncMock
7import pytest # pylint: disable=W0611
9from henrri_connect.models import CustomerRequest
10from tests.conftest import CUSTOMER_JSON, PAGED_META, make_response
13def _paged(elements: list[Any]) -> dict[str, Any]:
14 return {"elements": elements, "meta": PAGED_META}
17class TestAsyncCustomersExtra:
18 """Tests de la sous-cliente customers (asynchrone)."""
19 async def test_list_and_filters(self, async_client, mock_async_http: AsyncMock) -> None:
20 """Test de la méthode list_customers()."""
21 mock_async_http.request.return_value = make_response(_paged([CUSTOMER_JSON]))
23 res = await async_client.customers.list_customers(
24 request=CustomerRequest(
25 search="",
26 from_date="",
27 to_date=""
28 ),
29 with_selected_fields=False
30 )
31 assert res.elements and res.elements[0].id == CUSTOMER_JSON["id"]
33 mock_async_http.request.return_value = make_response(_paged([]))
34 await async_client.customers.list_customers(
35 request=CustomerRequest(
36 search="x",
37 page=2,
38 limit=10,
39 from_date="",
40 to_date=""
41 ),
42 with_selected_fields=False
43 )
44 _, kwargs = mock_async_http.request.call_args
45 params = kwargs["params"]
46 assert params["search"] == "x"
47 assert params["page"] == 2
49 async def test_best_sales_and_last_used_and_address(
50 self,
51 async_client,
52 mock_async_http: AsyncMock
53 ) -> None:
54 """Test de la méthode list_customers()."""
55 mock_async_http.request.return_value = make_response(_paged([CUSTOMER_JSON]))
56 best = await async_client.customers.get_best_sales(year=2025)
57 assert best.elements and len(best.elements) == 1
59 mock_async_http.request.return_value = make_response(CUSTOMER_JSON)
60 last = await async_client.customers.get_last_used("professional", 5)
61 assert last.id == CUSTOMER_JSON["id"]
63 mock_async_http.request.return_value = make_response(
64 {
65 "id": 5,
66 "city": "Lyon",
67 "isPostCodeShared": False
68 }
69 )
70 addr = await async_client.customers.get_address(1)
71 assert addr.city == "Lyon"
73 async def test_contacts_crud(self, async_client, mock_async_http: AsyncMock) -> None:
74 """Test de la méthode list_contacts()."""
75 contact_json = {"id": 1, "firstName": "Alice", "isPrimary": True, "showOnDocument": False}
76 mock_async_http.request.return_value = make_response([contact_json])
77 contacts = await async_client.customers.list_contacts(1)
78 assert len(contacts) == 1
80 mock_async_http.request.return_value = make_response(contact_json)
81 from henrri_connect.models import Contact # pylint: disable=C0415
82 c = Contact()
83 added = await async_client.customers.add_contact(1, c)
84 assert added.id == 1
86 mock_async_http.request.return_value = make_response({})
87 await async_client.customers.delete_contact(1, 2)
88 assert mock_async_http.request.call_args is not None