Coverage for tests/test_revenues.py: 100%
29 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-05 11:17 +0200
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-05 11:17 +0200
1"""Tests du sous-client revenues (synchrone et asynchrone)."""
3from __future__ import annotations
5from unittest.mock import AsyncMock, MagicMock
7from henrri_connect.connect import (
8 AsyncHenrriClient, SyncHenrriClient, # type: ignore[import]
9)
10from tests.conftest import MONTHLY_REVENUE_JSON, REVENUE_JSON, make_response
13class TestSyncRevenues:
14 """Tests du sous-client revenues (synchrone)."""
15 def test_get_annual(
16 self, sync_client: SyncHenrriClient, mock_http: MagicMock
17 ) -> None:
18 """Test de la méthode get_annual()."""
19 mock_http.request.return_value = make_response(REVENUE_JSON)
21 result = sync_client.revenues.get_annual(2025)
23 assert result.year == 2025
24 assert result.total_services_revenue == float(50000)
25 assert "/v1/revenues/2025" in mock_http.request.call_args.args[1]
27 def test_get_monthly(
28 self, sync_client: SyncHenrriClient, mock_http: MagicMock
29 ) -> None:
30 """Test de la méthode get_monthly()."""
31 mock_http.request.return_value = make_response([MONTHLY_REVENUE_JSON])
33 result = sync_client.revenues.get_monthly(2025)
35 assert len(result) == 1
36 assert result[0].month == 1
37 assert result[0].total_services_revenue == float(4000)
38 assert "/v1/revenues/2025/months" in mock_http.request.call_args.args[1]
41class TestAsyncRevenues:
42 """Tests du sous-client revenues (asynchrone)."""
43 async def test_get_annual(
44 self, async_client: AsyncHenrriClient, mock_async_http: AsyncMock
45 ) -> None:
46 """Test de la méthode get_annual()."""
47 mock_async_http.request.return_value = make_response(REVENUE_JSON)
49 result = await async_client.revenues.get_annual(2025)
51 assert result.year == 2025
52 assert result.total_products_revenue == float(10000)
54 async def test_get_monthly(
55 self, async_client: AsyncHenrriClient, mock_async_http: AsyncMock
56 ) -> None:
57 """Test de la méthode get_monthly()."""
58 mock_async_http.request.return_value = make_response([MONTHLY_REVENUE_JSON])
60 result = await async_client.revenues.get_monthly(2025)
62 assert len(result) == 1
63 assert result[0].month == 1