Refactor test_onlinetime

to require only one iteration and simplify testing
This commit is contained in:
Thor77 2017-03-03 23:59:24 +01:00
parent 6238f14574
commit a694a2bc58
1 changed files with 17 additions and 14 deletions

View File

@ -45,22 +45,25 @@ def test_debug(output):
def test_onlinetime(soup): def test_onlinetime(soup):
# move this into a (parameterized) fixture or function
items = soup.find('ul', id='1.onlinetime').find_all('li') items = soup.find('ul', id='1.onlinetime').find_all('li')
nick_data = {}
for item in items:
nick, data = item.find_all('span')
nick_data[nick.text] = data.text
# seperate between uuid and id-clients or merge them some way
# => assert len(items) == len(clients.id)
assert len(items) == 2 assert len(items) == 2
for client in clients: for item in items:
if client.nick in nick_data and client.onlinetime > timedelta(0): nick, onlinetime = item.find_all('span')
# remove this clause after splitting cients nick = nick.text
# (uuid-clients will never have a online-time, because onlinetime = onlinetime.text
# they're only used for bans and kicks) # find corresponding client-object
assert nick_data[client.nick] == \ client = filter(
seconds_to_text(int(client.onlinetime.total_seconds())) lambda c: c.nick == nick and c.onlinetime > timedelta(0),
clients
)
# assert existence
assert client
client = client[0]
# compare onlinetimes
client_onlinetime_text = seconds_to_text(
int(client.onlinetime.total_seconds())
)
assert onlinetime == client_onlinetime_text
def test_filter_threshold(): def test_filter_threshold():