This repository was archived by the owner on Jun 13, 2023. It is now read-only.
forked from Murgeye/teamspeak3-python-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_TS3Connection.py
More file actions
55 lines (45 loc) · 2.73 KB
/
test_TS3Connection.py
File metadata and controls
55 lines (45 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import logging
from unittest import TestCase
from .Events import ClientLeftEvent, ReasonID, ClientKickedEvent, ClientBannedEvent
from .TS3Connection import TS3Connection
class MockTS3Connection(TS3Connection):
def __init__(self):
self._logger = logging.Logger(__name__, logging.DEBUG)
self._logger.addHandler(logging.StreamHandler())
# noinspection DuplicatedCode
class TestTS3Connection(TestCase):
def setUp(self) -> None:
self.conn = MockTS3Connection()
def test_parse_resp_left_event(self):
resp = b"notifyclientleftview cfid=1 ctid=0 reasonid=8 " \
b"reasonmsg=Left. clid=1"
result = self.conn._parse_resp(resp)
self.assertIs(ClientLeftEvent, type(result), "ClientLeft not parsed correctly")
self.assertEqual(result.client_id, 1, "ClientLeft not parsed correctly")
def test_parse_resp_kicked_event(self):
resp = b"notifyclientleftview cfid=1 ctid=0 reasonid=" + str(
ReasonID.SERVER_KICK.value).encode("ascii") + b" reasonmsg=Kicked. clid=1"
result = self.conn._parse_resp(resp)
self.assertIs(ClientKickedEvent, type(result), "Client kick not parsed correctly")
self.assertEqual(1, result.client_id, "Client kick not parsed correctly")
def test_parse_banned_event(self):
resp = b"notifyclientleftview cfid=1 ctid=0 reasonid=" + str(ReasonID.BAN.value).encode(
"ascii") + b" reasonmsg=Kicked. clid=1 bantime=10 invokerid=2 invokername=Test invokeruid=sdfsadf"
result = self.conn._parse_resp(resp)
self.assertIs(ClientBannedEvent, type(result), "Client ban not parsed correctly")
self.assertEqual(1, result.client_id, "Client ban not parsed correctly")
self.assertEqual(10, result.ban_time, "Client ban not parsed correctly")
self.assertEqual(2, result.invoker_id, "Client ban not parsed correctly")
self.assertEqual("Test", result.invoker_name, "Client ban not parsed correctly")
self.assertEqual("sdfsadf", result.invoker_uid, "Client ban not parsed correctly")
def test_parse_resp_left_event_missing_reason_id(self):
resp = b"notifyclientleftview reasonmsg=Left. clid=1"
result = self.conn._parse_resp(resp)
self.assertIs(ClientLeftEvent, type(result),
"ClientLeft without reason id not parsed correctly")
self.assertEqual(1, result.client_id, "ClientLeft without reason id not parsed correctly")
def test_parse_resp_left_event_empty(self):
resp = b"notifyclientleftview"
result = self.conn._parse_resp(resp)
self.assertIs(ClientLeftEvent, type(result), "Empty client left not parsed correctly")
self.assertEqual(-1, result.client_id, "Empty ClientLeft not parsed correctly")