Skip to content

Commit d2a98f6

Browse files
committed
Add initial unit tests
Signed-off-by: cwasicki <[email protected]>
1 parent 8697782 commit d2a98f6

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

tests/test_client_reporting.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,42 @@
22
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH
33

44
"""Tests for the frequenz.client.reporting package."""
5+
from typing import Generator
6+
from unittest.mock import MagicMock, patch
7+
58
import pytest
69

7-
from frequenz.client.reporting import delete_me
10+
from frequenz.client.reporting import ReportingClient
11+
from frequenz.client.reporting._client import ComponentsDataPage
12+
13+
14+
@pytest.fixture
15+
def mock_channel() -> Generator[MagicMock, None, None]:
16+
"""Fixture for grpc.aio.insecure_channel."""
17+
with patch("grpc.aio.insecure_channel") as mock:
18+
yield mock
19+
20+
21+
@pytest.mark.asyncio
22+
async def test_client_initialization(mock_channel: MagicMock) -> None:
23+
"""Test that the client initializes the channel."""
24+
client = ReportingClient("localhost:50051") # noqa: F841
25+
mock_channel.assert_called_once_with("localhost:50051")
826

927

10-
def test_client_reporting_succeeds() -> None: # TODO(cookiecutter): Remove
11-
"""Test that the delete_me function succeeds."""
12-
assert delete_me() is True
28+
def test_components_data_page_is_empty_true() -> None:
29+
"""Test that the is_empty method returns True when the page is empty."""
30+
data_pb = MagicMock()
31+
data_pb.microgrids = []
32+
page = ComponentsDataPage(_data_pb=data_pb)
33+
assert page.is_empty() is True
1334

1435

15-
def test_client_reporting_fails() -> None: # TODO(cookiecutter): Remove
16-
"""Test that the delete_me function fails."""
17-
with pytest.raises(RuntimeError, match="This function should be removed!"):
18-
delete_me(blow_up=True)
36+
def test_components_data_page_is_empty_false() -> None:
37+
"""Test that the is_empty method returns False when the page is not empty."""
38+
data_pb = MagicMock()
39+
data_pb.microgrids = [MagicMock()]
40+
data_pb.microgrids[0].components = [MagicMock()]
41+
data_pb.microgrids[0].components[0].metric_samples = [MagicMock()]
42+
page = ComponentsDataPage(_data_pb=data_pb)
43+
assert page.is_empty() is False

0 commit comments

Comments
 (0)