From 3e22461b755aa39bc2ef6e1e4c50c50c7d6fdd46 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Fri, 31 Jul 2015 21:55:45 +0200 Subject: [PATCH] add template-tests --- testing_requirements.txt | 1 + tests/test_template.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/test_template.py diff --git a/testing_requirements.txt b/testing_requirements.txt index 5a9f7ae..de39aaf 100644 --- a/testing_requirements.txt +++ b/testing_requirements.txt @@ -1,2 +1,3 @@ nose>=1.3.7 pep8>=1.6.2 +BeautifulSoup4>=4.4.0 diff --git a/tests/test_template.py b/tests/test_template.py new file mode 100644 index 0000000..fbe5bee --- /dev/null +++ b/tests/test_template.py @@ -0,0 +1,27 @@ +from bs4 import BeautifulSoup +from tsstats import parse_logs, render_template, _format_seconds +from os import remove + +output_path = 'tests/res/output.html' +clients = parse_logs('tests/res/test.log') + + +class TestTemplate: + def teardown_class(): + remove(output_path) + + def test_debug(self): + render_template(clients, output_path, debug=True) + soup = BeautifulSoup(open(output_path), 'html.parser') + # check red label + assert soup.find_all(class_='alert alert-danger') + # check ident present after nick + li = soup.find('li') + assert li + assert '(' in li.text.split()[1] + + def test_data(self): + render_template(clients, output_path) + soup = BeautifulSoup(open(output_path), 'html.parser') + # check onlinetime-data + assert _format_seconds(clients['1'].onlinetime) == soup.find('span').text