add unit tests

This commit is contained in:
Stefan Allius
2025-05-06 22:23:41 +02:00
parent 4012196fcd
commit 911d0a9612
2 changed files with 51 additions and 2 deletions

View File

@@ -43,7 +43,6 @@ class Server():
return dict(version=self.version)
def parse_args(self, arg_list: list[str] | None):
print("in Server.read_cli1")
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config_path', type=str,
default='./config/',
@@ -65,7 +64,6 @@ class Server():
help='use relative dashboard urls')
args = parser.parse_args(arg_list)
print(f"rel_urls-1: {args.rel_urls}")
self.config_path = args.config_path
self.json_config = args.json_config
self.toml_config = args.toml_config

View File

@@ -73,3 +73,54 @@ async def test_healthy():
assert response.status_code == 200
result = await response.get_data()
assert result == b"I'm fine"
def test_default_args():
s = FakeServer()
assert s.config_path == './config/'
assert s.json_config == ''
assert s.toml_config == ''
assert s.trans_path == '../translations/'
assert s.rel_urls == False
assert s.log_path == './log/'
assert s.log_backups == 0
def test_parse_args_empty():
s = FakeServer()
s.parse_args([])
assert s.config_path == './config/'
assert s.json_config == None
assert s.toml_config == None
assert s.trans_path == '../translations/'
assert s.rel_urls == False
assert s.log_path == './log/'
assert s.log_backups == 0
def test_parse_args_short():
s = FakeServer()
s.parse_args(['-r', '-c', '/tmp/my-config', '-j', 'cnf.jsn', '-t', 'cnf.tml', '-tr', '/my/trans/', '-l', '/my_logs/', '-b', '3'])
assert s.config_path == '/tmp/my-config'
assert s.json_config == 'cnf.jsn'
assert s.toml_config == 'cnf.tml'
assert s.trans_path == '/my/trans/'
assert s.rel_urls == True
assert s.log_path == '/my_logs/'
assert s.log_backups == 3
def test_parse_args_long():
s = FakeServer()
s.parse_args(['--rel_urls', '--config_path', '/tmp/my-config', '--json_config', 'cnf.jsn',
'--toml_config', 'cnf.tml', '--trans_path', '/my/trans/', '--log_path', '/my_logs/',
'--log_backups', '3'])
assert s.config_path == '/tmp/my-config'
assert s.json_config == 'cnf.jsn'
assert s.toml_config == 'cnf.tml'
assert s.trans_path == '/my/trans/'
assert s.rel_urls == True
assert s.log_path == '/my_logs/'
assert s.log_backups == 3
def test_parse_args_invalid():
s = FakeServer()
with pytest.raises(SystemExit) as exc_info:
s.parse_args(['--inalid', '/tmp/my-config'])
assert exc_info.value.code == 2