# Path: protector/config/loader.py
# def load_config():
# def overwrite_config(old_values, new_values):
# def parse_configfile(configfile):
# def flatten(d, parent_key='', sep='_'):
# def parse_args(args=sys.argv[1:]):


import unittest
import os
import argparse
from mock import patch
from protector.config import loader
    def setUp(self):
        path = os.path.dirname(os.path.abspath(__file__))
        self.configfile = "{}/../fixtures/config_sample.yaml".format(path)

    def test_load_config(self):
        parsed_config = loader.parse_configfile(self.configfile)
        self.assertEqual(parsed_config["host"], "myhost")
        self.assertEqual(parsed_config["port"], 1234)

    def test_cli_overwrite(self):
        # Fake commandline arguments
        # Argparse returns a namespace, not a dictionary
        fake_args = argparse.Namespace()
        fake_args.host = "myhost"

        with patch('argparse.ArgumentParser.parse_args') as parse_args_mock:
            parse_args_mock.return_value = fake_args

            # Fake default config
            with patch('protector.config.default_config.DEFAULT_CONFIG') as default_config_mock:
                default_config_mock.return_value = {"host": "yourhost"}
                config = loader.load_config()

        # Check if the default setting got overwritten
        self.assertEqual(config.host, "myhost")

    def test_shorthand_cli_parameters(self):
        config = loader.parse_args([])
        self.assertIsNotNone(config)
        self.assertEqual(config['foreground'], False)

# Path: protector/config/loader.py
# def load_config():
# def overwrite_config(old_values, new_values):
# def parse_configfile(configfile):
# def flatten(d, parent_key='', sep='_'):
# def parse_args(args=sys.argv[1:]):


# Path: protector/tests/config_test/test_loader.py
import unittest
import os
import argparse
from mock import patch
from protector.config import loader

    def setUp(self):
        path = os.path.dirname(os.path.abspath(__file__))
        self.configfile = "{}/../fixtures/config_sample.yaml".format(path)

    def test_load_config(self):
        parsed_config = loader.parse_configfile(self.configfile)
        self.assertEqual(parsed_config["host"], "myhost")
        self.assertEqual(parsed_config["port"], 1234)

    def test_cli_overwrite(self):
        # Fake commandline arguments
        # Argparse returns a namespace, not a dictionary
        fake_args = argparse.Namespace()
        fake_args.host = "myhost"

        with patch('argparse.ArgumentParser.parse_args') as parse_args_mock:
            parse_args_mock.return_value = fake_args

            # Fake default config
            with patch('protector.config.default_config.DEFAULT_CONFIG') as default_config_mock:
                default_config_mock.return_value = {"host": "yourhost"}
                config = loader.load_config()

        # Check if the default setting got overwritten
        self.assertEqual(config.host, "myhost")

    def test_shorthand_cli_parameters(self):
        config = loader.parse_args([])
        self.assertIsNotNone(config)
        self.assertEqual(config['foreground'], False)

        config = loader.parse_args(['-f'])