# Path: tests/functional/ucare_cli/helpers.py
# def arg_namespace(arguments_str):
#     return ucare_argparser().parse_args(arguments_str.split())
# 
# Path: pyuploadcare/ucare_cli/settings.py
# def load_config(  # noqa: C901
#     arg_namespace: Optional[argparse.Namespace] = None,
#     config_file_names: Optional[List[str]] = None,
# ) -> Dict[str, Any]:
#     conf: Dict[str, Any] = {}
# 
#     if config_file_names:
#         for file_name in config_file_names:
#             conf = load_config_from_file(file_name, conf)
# 
#     if arg_namespace:
#         conf = load_config_from_args(arg_namespace, conf)
# 
#     client_conf = {}
#     for key, value in conf.items():
#         if key in client_setting_mapping:
#             key = client_setting_mapping[key]
#         client_conf[key] = value
# 
#     return client_conf


from tempfile import NamedTemporaryFile
from tests.functional.ucare_cli.helpers import arg_namespace
from pyuploadcare.ucare_cli.settings import load_config
import pytest




@pytest.fixture
def config_file():
    return NamedTemporaryFile(mode="w+t", delete=False)


def test_use_pub_key_from_config_file(config_file):
    config_file.write("[ucare]\n" "pub_key = demopublickey")
    config_file.close()

    args = arg_namespace("list_files")
    conf = load_config(args, [config_file.name])

    assert conf["public_key"] == "demopublickey"


def test_redefine_pub_key_by_second_config_file(config_file):

    config_file.write("[ucare]\n" "pub_key = demopublickey")
    config_file.close()

    second_tmp_conf_file = NamedTemporaryFile(mode="w+t", delete=False)
    second_tmp_conf_file.write("[ucare]\n" "pub_key = demopublickey_modified")
    second_tmp_conf_file.close()

    args = arg_namespace("list_files")

# Path: tests/functional/ucare_cli/helpers.py
# def arg_namespace(arguments_str):
#     return ucare_argparser().parse_args(arguments_str.split())
# 
# Path: pyuploadcare/ucare_cli/settings.py
# def load_config(  # noqa: C901
#     arg_namespace: Optional[argparse.Namespace] = None,
#     config_file_names: Optional[List[str]] = None,
# ) -> Dict[str, Any]:
#     conf: Dict[str, Any] = {}
# 
#     if config_file_names:
#         for file_name in config_file_names:
#             conf = load_config_from_file(file_name, conf)
# 
#     if arg_namespace:
#         conf = load_config_from_args(arg_namespace, conf)
# 
#     client_conf = {}
#     for key, value in conf.items():
#         if key in client_setting_mapping:
#             key = client_setting_mapping[key]
#         client_conf[key] = value
# 
#     return client_conf


# Path: tests/functional/ucare_cli/test_config_file.py
from tempfile import NamedTemporaryFile
from tests.functional.ucare_cli.helpers import arg_namespace
from pyuploadcare.ucare_cli.settings import load_config
import pytest





@pytest.fixture
def config_file():
    return NamedTemporaryFile(mode="w+t", delete=False)


def test_use_pub_key_from_config_file(config_file):
    config_file.write("[ucare]\n" "pub_key = demopublickey")
    config_file.close()

    args = arg_namespace("list_files")
    conf = load_config(args, [config_file.name])

    assert conf["public_key"] == "demopublickey"


def test_redefine_pub_key_by_second_config_file(config_file):

    config_file.write("[ucare]\n" "pub_key = demopublickey")
    config_file.close()

    second_tmp_conf_file = NamedTemporaryFile(mode="w+t", delete=False)
    second_tmp_conf_file.write("[ucare]\n" "pub_key = demopublickey_modified")
    second_tmp_conf_file.close()

    args = arg_namespace("list_files")

    conf = load_config(args, [config_file.name, second_tmp_conf_file.name])