2016-05-10 16:50:34 -04:00
|
|
|
import logging
|
2015-07-31 15:55:45 -04:00
|
|
|
from os import remove
|
|
|
|
|
2016-05-09 14:09:16 -04:00
|
|
|
import pytest
|
2015-09-04 17:20:35 -04:00
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
2016-05-23 15:50:10 -04:00
|
|
|
from tsstats.log import parse_log
|
2016-05-08 15:32:37 -04:00
|
|
|
from tsstats.template import render_template
|
2016-05-09 14:09:16 -04:00
|
|
|
from tsstats.utils import seconds_to_text
|
2015-09-04 17:20:35 -04:00
|
|
|
|
2016-05-08 15:32:37 -04:00
|
|
|
output_path = 'tsstats/tests/res/output.html'
|
2016-05-23 15:50:10 -04:00
|
|
|
clients = parse_log('tsstats/tests/res/test.log')
|
2015-07-31 15:55:45 -04:00
|
|
|
|
2016-05-10 16:50:34 -04:00
|
|
|
logger = logging.getLogger('tsstats')
|
|
|
|
|
2015-07-31 15:55:45 -04:00
|
|
|
|
2016-05-09 14:09:16 -04:00
|
|
|
@pytest.fixture
|
|
|
|
def output(request):
|
|
|
|
def clean():
|
|
|
|
remove('tsstats/tests/res/output.html')
|
|
|
|
request.addfinalizer(clean)
|
|
|
|
|
|
|
|
|
2016-06-10 09:36:32 -04:00
|
|
|
@pytest.fixture
|
|
|
|
def soup(output):
|
|
|
|
render_template(clients, output_path)
|
|
|
|
return BeautifulSoup(open(output_path), 'html.parser')
|
|
|
|
|
|
|
|
|
2016-05-09 14:09:16 -04:00
|
|
|
def test_debug(output):
|
2016-05-10 16:50:34 -04:00
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
render_template(clients, output_path)
|
|
|
|
logger.setLevel(logging.INFO)
|
2016-05-09 14:09:16 -04:00
|
|
|
soup = BeautifulSoup(open(output_path), 'html.parser')
|
2016-06-10 10:22:52 -04:00
|
|
|
# check debug-label presence
|
2016-05-09 14:09:16 -04:00
|
|
|
assert soup.find_all(class_='alert alert-danger')
|
2016-06-10 10:22:52 -04:00
|
|
|
for client_item in soup.find_all('li'):
|
|
|
|
nick = client_item.find('span').text
|
|
|
|
# check for right identifier
|
|
|
|
nick, encl_identifier = nick.split()
|
|
|
|
identifier = encl_identifier.replace('(', '').replace(')', '')
|
|
|
|
assert clients[identifier].nick == nick
|
2016-05-09 14:09:16 -04:00
|
|
|
|
|
|
|
|
2016-06-10 09:36:32 -04:00
|
|
|
def test_onlinetime(soup):
|
2016-05-09 14:09:16 -04:00
|
|
|
assert seconds_to_text(clients['1'].onlinetime) == \
|
|
|
|
soup.find('span', class_='badge').text
|