2018-07-19 17:30:09 -07:00
|
|
|
"""
|
|
|
|
|
Unit test functions in installer.py
|
|
|
|
|
"""
|
|
|
|
|
import os
|
2019-07-16 20:18:45 +03:00
|
|
|
import pytest
|
2018-08-28 14:16:09 +02:00
|
|
|
|
|
|
|
|
from tljh import installer
|
2019-07-15 12:02:18 +03:00
|
|
|
from tljh.yaml import yaml
|
2018-08-28 14:16:09 +02:00
|
|
|
|
2018-07-19 17:30:09 -07:00
|
|
|
|
2018-08-28 14:16:09 +02:00
|
|
|
def test_ensure_config_yaml(tljh_dir):
|
|
|
|
|
pm = installer.setup_plugins()
|
|
|
|
|
installer.ensure_config_yaml(pm)
|
|
|
|
|
assert os.path.exists(installer.CONFIG_FILE)
|
|
|
|
|
assert os.path.isdir(installer.CONFIG_DIR)
|
|
|
|
|
assert os.path.isdir(os.path.join(installer.CONFIG_DIR, 'jupyterhub_config.d'))
|
2018-08-31 12:17:16 +02:00
|
|
|
# verify that old config doesn't exist
|
|
|
|
|
assert not os.path.exists(os.path.join(tljh_dir, 'config.yaml'))
|
2019-07-15 12:02:18 +03:00
|
|
|
|
2019-07-16 20:18:45 +03:00
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2021-11-01 09:42:45 +01:00
|
|
|
"admins, expected_config",
|
|
|
|
|
[
|
|
|
|
|
([['a1'], ['a2'], ['a3']], ['a1', 'a2', 'a3']),
|
|
|
|
|
([['a1:p1'], ['a2']], ['a1', 'a2']),
|
|
|
|
|
],
|
2019-07-16 20:18:45 +03:00
|
|
|
)
|
|
|
|
|
def test_ensure_admins(tljh_dir, admins, expected_config):
|
2021-11-01 09:42:45 +01:00
|
|
|
# --admin option called multiple times on the installer
|
|
|
|
|
# creates a list of argument lists.
|
|
|
|
|
installer.ensure_admins(admins)
|
2019-07-15 12:02:18 +03:00
|
|
|
|
2021-11-01 09:42:45 +01:00
|
|
|
config_path = installer.CONFIG_FILE
|
|
|
|
|
with open(config_path) as f:
|
|
|
|
|
config = yaml.load(f)
|
2019-07-15 12:02:18 +03:00
|
|
|
|
2021-11-01 09:42:45 +01:00
|
|
|
# verify the list was flattened
|
|
|
|
|
assert config['users']['admin'] == expected_config
|