Total Complexity | 7 |
Total Lines | 39 |
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 | @staticmethod |
||
19 | def test_get(): |
||
20 | assert Heartbeat.get() == 0 |
||
21 | |||
22 | @pytest.mark.asyncio |
||
23 | async def test_handle_hello(self, web_socket_client_protocol): |
||
24 | payload = Mock() |
||
25 | payload.data.get.return_value = 1 |
||
26 | with patch("pincer.core.heartbeat.Heartbeat"): |
||
27 | await Heartbeat.handle_hello(web_socket_client_protocol, payload) |
||
28 | web_socket_client_protocol.send.assert_awaited_once() |
||
29 | |||
30 | @pytest.mark.asyncio |
||
31 | async def test_handle_heartbeat(self, web_socket_client_protocol): |
||
32 | await Heartbeat.handle_heartbeat(web_socket_client_protocol, "GARBAGE") |
||
33 | web_socket_client_protocol.send.assert_awaited_once() |
||
34 | |||
35 | @staticmethod |
||
36 | def test_update_sequence(): |
||
37 | with assert_not_raises(): |
||
38 | Heartbeat.update_sequence(42) |
||
39 |