Total Complexity | 7 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # Copyright Pincer 2021-Present |
||
2 | # Full MIT License can be found in `LICENSE` at the project root. |
||
3 | |||
4 | from unittest.mock import AsyncMock, Mock, patch |
||
5 | |||
6 | import pytest |
||
7 | |||
8 | from pincer.core.heartbeat import Heartbeat |
||
9 | from tests.utils.utils import assert_not_raises |
||
10 | |||
11 | |||
12 | @pytest.fixture |
||
13 | def web_socket_client_protocol(): |
||
14 | return AsyncMock() |
||
15 | |||
16 | |||
17 | class TestHeartbeat: |
||
18 | def test_get(self): |
||
19 | assert Heartbeat.get() == 0 |
||
20 | |||
21 | @pytest.mark.asyncio |
||
22 | async def test_handle_hello(self, web_socket_client_protocol): |
||
23 | payload = Mock() |
||
24 | payload.data.get.return_value = 1 |
||
25 | with patch("pincer.core.heartbeat.Heartbeat"): |
||
26 | await Heartbeat.handle_hello(web_socket_client_protocol, payload) |
||
27 | web_socket_client_protocol.send.assert_awaited_once() |
||
28 | |||
29 | @pytest.mark.asyncio |
||
30 | async def test_handle_heartbeat(self, web_socket_client_protocol): |
||
31 | await Heartbeat.handle_heartbeat(web_socket_client_protocol, "GARBAGE") |
||
32 | web_socket_client_protocol.send.assert_awaited_once() |
||
33 | |||
34 | def test_update_sequence(self): |
||
35 | with assert_not_raises(): |
||
36 | Heartbeat.update_sequence(42) |
||
37 |
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.