TeamspeakStats/tsstats/tests/test_client.py

44 lines
950 B
Python
Raw Normal View History

2016-05-19 09:43:44 -04:00
import pytest
from tsstats.client import Client, Clients
clients = Clients()
2016-05-19 09:43:44 -04:00
cl1 = Client('1')
cl2 = Client('2')
clients += cl1
clients += cl2
uidcl1 = Client('UID1')
uidcl2 = Client('UID2')
clients += uidcl1
clients += uidcl2
def test_client_get():
2016-05-19 09:43:44 -04:00
assert clients['1'] == cl1
assert clients['2'] == cl2
assert clients['UID1'] == uidcl1
assert clients['UID2'] == uidcl2
with pytest.raises(KeyError):
clients['3']
clients['UID3']
def test_client_repr():
assert str(clients['1']) == '<1,None>'
assert str(clients['2']) == '<2,None>'
assert str(clients['UID1']) == '<UID1,None>'
assert str(clients['UID2']) == '<UID2,None>'
def test_clients_iter():
2016-05-19 09:43:44 -04:00
client_list = list(iter(clients))
assert cl1 in client_list
assert cl2 in client_list
assert uidcl1 in client_list
assert uidcl2 in client_list
2016-05-19 15:24:22 -04:00
def test_clients_delete():
del clients['1']
assert cl1 not in clients