2018-07-11 12:50:42 +00:00
|
|
|
"""Test config"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
TEST_SECTION = 'test'
|
|
|
|
TEST_ATTRIBUTE = 'attribute'
|
|
|
|
TEST_KEY = f'{TEST_SECTION}.{TEST_ATTRIBUTE}'
|
|
|
|
TEST_VALUE = 'testvalue'
|
|
|
|
TEST_FILE = f'[{TEST_SECTION}]\n\t{TEST_ATTRIBUTE} = {TEST_VALUE}'
|
|
|
|
|
|
|
|
|
2020-11-17 20:38:31 +00:00
|
|
|
def test_config_no_params(runner, yadm_cmd, supported_configs):
|
2018-07-11 12:50:42 +00:00
|
|
|
"""No parameters
|
|
|
|
|
|
|
|
Display instructions
|
|
|
|
Display supported configs
|
|
|
|
Exit with 0
|
|
|
|
"""
|
|
|
|
|
2020-11-17 20:38:31 +00:00
|
|
|
run = runner(yadm_cmd('config'))
|
2018-07-11 12:50:42 +00:00
|
|
|
|
|
|
|
assert run.success
|
|
|
|
assert run.err == ''
|
|
|
|
assert 'Please read the CONFIGURATION section' in run.out
|
|
|
|
for config in supported_configs:
|
|
|
|
assert config in run.out
|
|
|
|
|
|
|
|
|
2020-11-17 20:38:31 +00:00
|
|
|
def test_config_read_missing(runner, yadm_cmd):
|
2018-07-11 12:50:42 +00:00
|
|
|
"""Read missing attribute
|
|
|
|
|
|
|
|
Display an empty value
|
|
|
|
Exit with 0
|
|
|
|
"""
|
|
|
|
|
2020-11-17 20:38:31 +00:00
|
|
|
run = runner(yadm_cmd('config', TEST_KEY))
|
2018-07-11 12:50:42 +00:00
|
|
|
|
|
|
|
assert run.success
|
|
|
|
assert run.err == ''
|
|
|
|
assert run.out == ''
|
|
|
|
|
|
|
|
|
2020-11-17 20:38:31 +00:00
|
|
|
def test_config_write(runner, yadm_cmd, paths):
|
2018-07-11 12:50:42 +00:00
|
|
|
"""Write attribute
|
|
|
|
|
|
|
|
Display no output
|
|
|
|
Update configuration file
|
|
|
|
Exit with 0
|
|
|
|
"""
|
|
|
|
|
2020-11-17 20:38:31 +00:00
|
|
|
run = runner(yadm_cmd('config', TEST_KEY, TEST_VALUE))
|
2018-07-11 12:50:42 +00:00
|
|
|
|
|
|
|
assert run.success
|
|
|
|
assert run.err == ''
|
|
|
|
assert run.out == ''
|
|
|
|
assert paths.config.read().strip() == TEST_FILE
|
|
|
|
|
|
|
|
|
2020-11-17 20:38:31 +00:00
|
|
|
def test_config_read(runner, yadm_cmd, paths):
|
2018-07-11 12:50:42 +00:00
|
|
|
"""Read attribute
|
|
|
|
|
|
|
|
Display value
|
|
|
|
Exit with 0
|
|
|
|
"""
|
|
|
|
|
|
|
|
paths.config.write(TEST_FILE)
|
2020-11-17 20:38:31 +00:00
|
|
|
run = runner(yadm_cmd('config', TEST_KEY))
|
2018-07-11 12:50:42 +00:00
|
|
|
|
|
|
|
assert run.success
|
|
|
|
assert run.err == ''
|
|
|
|
assert run.out.strip() == TEST_VALUE
|
|
|
|
|
|
|
|
|
2020-11-17 20:38:31 +00:00
|
|
|
def test_config_update(runner, yadm_cmd, paths):
|
2018-07-11 12:50:42 +00:00
|
|
|
"""Update attribute
|
|
|
|
|
|
|
|
Display no output
|
|
|
|
Update configuration file
|
|
|
|
Exit with 0
|
|
|
|
"""
|
|
|
|
|
|
|
|
paths.config.write(TEST_FILE)
|
|
|
|
|
2020-11-17 20:38:31 +00:00
|
|
|
run = runner(yadm_cmd('config', TEST_KEY, TEST_VALUE + 'extra'))
|
2018-07-11 12:50:42 +00:00
|
|
|
|
|
|
|
assert run.success
|
|
|
|
assert run.err == ''
|
|
|
|
assert run.out == ''
|
|
|
|
|
|
|
|
assert paths.config.read().strip() == TEST_FILE + 'extra'
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures('ds1_repo_copy')
|
2020-11-17 20:38:31 +00:00
|
|
|
def test_config_local_read(runner, yadm_cmd, paths, supported_local_configs):
|
2018-07-11 12:50:42 +00:00
|
|
|
"""Read local attribute
|
|
|
|
|
|
|
|
Display value from the repo config
|
|
|
|
Exit with 0
|
|
|
|
"""
|
|
|
|
|
|
|
|
# populate test values
|
|
|
|
for config in supported_local_configs:
|
|
|
|
os.system(
|
|
|
|
f'GIT_DIR="{paths.repo}" '
|
|
|
|
f'git config --local "{config}" "value_of_{config}"')
|
|
|
|
|
|
|
|
# run yadm config
|
|
|
|
for config in supported_local_configs:
|
2020-11-17 20:38:31 +00:00
|
|
|
run = runner(yadm_cmd('config', config))
|
2018-07-11 12:50:42 +00:00
|
|
|
assert run.success
|
|
|
|
assert run.err == ''
|
|
|
|
assert run.out.strip() == f'value_of_{config}'
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures('ds1_repo_copy')
|
2020-11-17 20:38:31 +00:00
|
|
|
def test_config_local_write(runner, yadm_cmd, paths, supported_local_configs):
|
2018-07-11 12:50:42 +00:00
|
|
|
"""Write local attribute
|
|
|
|
|
|
|
|
Display no output
|
|
|
|
Write value to the repo config
|
|
|
|
Exit with 0
|
|
|
|
"""
|
|
|
|
|
|
|
|
# run yadm config
|
|
|
|
for config in supported_local_configs:
|
2020-11-17 20:38:31 +00:00
|
|
|
run = runner(yadm_cmd('config', config, f'value_of_{config}'))
|
2018-07-11 12:50:42 +00:00
|
|
|
assert run.success
|
|
|
|
assert run.err == ''
|
|
|
|
assert run.out == ''
|
|
|
|
|
|
|
|
# verify test values
|
|
|
|
for config in supported_local_configs:
|
|
|
|
run = runner(
|
|
|
|
command=('git', 'config', config),
|
|
|
|
env={'GIT_DIR': paths.repo})
|
|
|
|
assert run.success
|
|
|
|
assert run.err == ''
|
|
|
|
assert run.out.strip() == f'value_of_{config}'
|
2020-06-01 17:37:43 +00:00
|
|
|
|
|
|
|
|
2020-11-17 20:38:31 +00:00
|
|
|
def test_config_without_parent_directory(runner, yadm_cmd, paths):
|
2020-07-08 20:30:15 +00:00
|
|
|
"""Write and read attribute to/from config file with non-existent parent dir
|
2020-06-01 17:37:43 +00:00
|
|
|
|
|
|
|
Update configuration file
|
|
|
|
Display value
|
|
|
|
Exit with 0
|
|
|
|
"""
|
|
|
|
|
|
|
|
config_file = paths.root + '/folder/does/not/exist/config'
|
|
|
|
|
2020-07-08 20:30:15 +00:00
|
|
|
run = runner(
|
2020-11-17 20:38:31 +00:00
|
|
|
yadm_cmd('--yadm-config', config_file, 'config', TEST_KEY, TEST_VALUE))
|
2020-06-01 17:37:43 +00:00
|
|
|
|
|
|
|
assert run.success
|
|
|
|
assert run.err == ''
|
|
|
|
assert run.out == ''
|
|
|
|
|
2020-11-17 20:38:31 +00:00
|
|
|
run = runner(yadm_cmd('--yadm-config', config_file, 'config', TEST_KEY))
|
2020-06-01 17:37:43 +00:00
|
|
|
|
|
|
|
assert run.success
|
|
|
|
assert run.err == ''
|
|
|
|
assert run.out.strip() == TEST_VALUE
|