add tests
This commit is contained in:
parent
309966a0ad
commit
234f671e84
|
@ -0,0 +1,11 @@
|
||||||
|
2015-05-18 15:52:52.685612|INFO |VirtualServerBase| 3| client connected 'Client1'(id:1) from 1.2.3.4:1234
|
||||||
|
2015-05-18 15:54:13.966536|INFO |VirtualServerBase| 3| client connected 'Client2'(id:2) from 5.6.7.8:5678
|
||||||
|
2015-05-18 15:54:25.055304|INFO |VirtualServerBase| 3| client disconnected 'Client2'(id:2) reason 'invokerid=1 invokername=Client1 invokeruid=UIDClient1 reasonmsg'
|
||||||
|
2015-05-18 15:54:30.053231|INFO |VirtualServerBase| 3| client connected 'Client2'(id:2) from 5.6.7.8:5678
|
||||||
|
2015-05-18 15:54:38.723364|INFO |VirtualServer | 3| ban added reason='' cluid='UIDClient2' bantime=0 by client 'Client1'(id:1)
|
||||||
|
2015-05-18 15:54:38.724012|INFO |VirtualServer | 3| ban added reason='' ip='5.6.7.8:5678' bantime=0 by client 'Client1'(id:1)
|
||||||
|
2015-05-18 15:54:38.724107|INFO |VirtualServerBase| 3| client disconnected 'Client2'(id:2) reason 'invokerid=1 invokername=Client1 invokeruid=UIDClient1 reasonmsg bantime=0'
|
||||||
|
2015-05-18 15:54:43.340308|INFO |VirtualServerBase| 3| client disconnected 'Client1'(id:1) reason 'reasonmsg=ByeBye!'
|
||||||
|
2015-05-18 15:55:23.456679|INFO |VirtualServerBase| 3| client connected 'Client1'(id:1) from 1.2.3.4:1234
|
||||||
|
2015-05-18 16:00:14.951191|INFO |VirtualServerBase| 3| client disconnected 'Client1'(id:1) reason 'reasonmsg=ByeBye!'
|
||||||
|
2015-05-18 16:00:38.802524|INFO |VirtualServerBase| 3| client connected 'Client1'(id:1) from 1.2.3.4:1234
|
|
@ -0,0 +1,47 @@
|
||||||
|
import configparser
|
||||||
|
from os import remove
|
||||||
|
from os.path import exists
|
||||||
|
import tsstats
|
||||||
|
from nose.tools import raises, with_setup
|
||||||
|
|
||||||
|
|
||||||
|
def create_config(values, key='General'):
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config[key] = values
|
||||||
|
with open('config.ini', 'w') as configfile:
|
||||||
|
config.write(configfile)
|
||||||
|
|
||||||
|
|
||||||
|
def clean_config():
|
||||||
|
if exists('config.ini'):
|
||||||
|
remove('config.ini')
|
||||||
|
|
||||||
|
|
||||||
|
def clean_result():
|
||||||
|
if exists('output.html'):
|
||||||
|
remove('output.html')
|
||||||
|
|
||||||
|
|
||||||
|
@with_setup(clean_config, clean_config)
|
||||||
|
@raises(Exception)
|
||||||
|
def test_invalid_config():
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
create_config({
|
||||||
|
'logfile': 'tests/res/test.log',
|
||||||
|
'outputfile': '',
|
||||||
|
'deebug': 'false',
|
||||||
|
})
|
||||||
|
_, _, _, _ = parse_config(config_path)
|
||||||
|
|
||||||
|
|
||||||
|
@with_setup(clean_config, clean_config)
|
||||||
|
@raises(Exception)
|
||||||
|
def test_debug_without_debugfile():
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
create_config({
|
||||||
|
'logfile': 'tests/res/test.log',
|
||||||
|
'debug': 'true',
|
||||||
|
'debugfile': 'false',
|
||||||
|
})
|
||||||
|
_, _, _, _ = parse_config(config_path)
|
||||||
|
open('debug.txt', 'r')
|
|
@ -0,0 +1,36 @@
|
||||||
|
from tsstats import parse_logs
|
||||||
|
from sys import stderr
|
||||||
|
|
||||||
|
clients = parse_logs('tests/res/test.log')
|
||||||
|
|
||||||
|
|
||||||
|
def test_length():
|
||||||
|
assert len(clients.clients_by_id) == 2
|
||||||
|
assert len(clients.clients_by_uid) == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_getter():
|
||||||
|
# check getter not raise
|
||||||
|
assert clients['UIDClient2'].onlinetime == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_onlinetime():
|
||||||
|
# check different dicts
|
||||||
|
assert clients['1'].onlinetime == 402
|
||||||
|
assert clients['2'].onlinetime == 20
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_kicks():
|
||||||
|
assert clients['UIDClient1'].kicks == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_pkicks():
|
||||||
|
assert clients['2'].pkicks == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_bans():
|
||||||
|
assert clients['UIDClient1'].bans == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_pbans():
|
||||||
|
assert clients['2'].pbans == 1
|
Loading…
Reference in New Issue