# Path: kafka_influxdb/config/loader.py
# class ObjectView(object):
#     def __init__(self, d):
# 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: kafka_influxdb/config/default_config.py
# DEFAULT_CONFIG = {
#     'kafka': {
#         'host': 'localhost',
#         'port': '9092',
#         'topic': 'my_topic',
#         'group': 'kafka-influxdb',
#         'reconnect_wait_time_ms': 1000,
#         'reader': 'kafka_influxdb.reader.confluent',
#         'offset': 'largest',
#     },
#     'influxdb': {
#         'host': 'localhost',
#         'port': 8086,
#         'user': 'root',
#         'password': 'root',
#         'dbname': 'metrics',
#         'use_ssl': False,
#         'verify_ssl': False,
#         'timeout': 5,
#         'use_udp': False,
#         'retention_policy': 'autogen',
#         'time_precision': 's',
#     },
#     'encoder': 'kafka_influxdb.encoder.collectd_graphite_encoder',
#     'buffer_size': 1000,
#     'buffer_timeout': False,
#     'configfile': None,
#     'c': None,
#     'statistics': False,
#     's': False,
#     'verbose': 0,
#     'v': 0
# }


import unittest
import os
import argparse
from mock import MagicMock
from kafka_influxdb.config import loader, default_config
    def test_argparse_flags(self):
        long_flags = [
            'influxdb_use_ssl',
            'influxdb_verify_ssl',
            'influxdb_use_udp',
            'statistics'
        ]
        for flag in long_flags:
            parsed = loader.parse_args(['--' + flag])
            self.assertEqual(parsed[flag], True)

        parsed = loader.parse_args(['-s'])
        self.assertEqual(parsed['statistics'], True)

    def test_cli_overwrite(self):
        # Fake commandline arguments
        # Argparse returns a namespace, not a dictionary
        fake_args = argparse.Namespace()
        fake_args.influxdb_use_ssl = False
        argparse.ArgumentParser.parse_args = MagicMock(return_value=fake_args)

        # Fake default config
        default_config.DEFAULT_CONFIG = MagicMock(
            return_value={'influxdb_use_ssl': True})
        config = loader.load_config()

        # Check if the default setting got overwritten
        self.assertEqual(config.influxdb_use_ssl, False)

    def test_overwrite_default_config(self):

# Path: kafka_influxdb/config/loader.py
# class ObjectView(object):
#     def __init__(self, d):
# 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: kafka_influxdb/config/default_config.py
# DEFAULT_CONFIG = {
#     'kafka': {
#         'host': 'localhost',
#         'port': '9092',
#         'topic': 'my_topic',
#         'group': 'kafka-influxdb',
#         'reconnect_wait_time_ms': 1000,
#         'reader': 'kafka_influxdb.reader.confluent',
#         'offset': 'largest',
#     },
#     'influxdb': {
#         'host': 'localhost',
#         'port': 8086,
#         'user': 'root',
#         'password': 'root',
#         'dbname': 'metrics',
#         'use_ssl': False,
#         'verify_ssl': False,
#         'timeout': 5,
#         'use_udp': False,
#         'retention_policy': 'autogen',
#         'time_precision': 's',
#     },
#     'encoder': 'kafka_influxdb.encoder.collectd_graphite_encoder',
#     'buffer_size': 1000,
#     'buffer_timeout': False,
#     'configfile': None,
#     'c': None,
#     'statistics': False,
#     's': False,
#     'verbose': 0,
#     'v': 0
# }


# Path: kafka_influxdb/tests/config_test/test_config.py
import unittest
import os
import argparse
from mock import MagicMock
from kafka_influxdb.config import loader, default_config

    def test_argparse_flags(self):
        long_flags = [
            'influxdb_use_ssl',
            'influxdb_verify_ssl',
            'influxdb_use_udp',
            'statistics'
        ]
        for flag in long_flags:
            parsed = loader.parse_args(['--' + flag])
            self.assertEqual(parsed[flag], True)

        parsed = loader.parse_args(['-s'])
        self.assertEqual(parsed['statistics'], True)

    def test_cli_overwrite(self):
        # Fake commandline arguments
        # Argparse returns a namespace, not a dictionary
        fake_args = argparse.Namespace()
        fake_args.influxdb_use_ssl = False
        argparse.ArgumentParser.parse_args = MagicMock(return_value=fake_args)

        # Fake default config
        default_config.DEFAULT_CONFIG = MagicMock(
            return_value={'influxdb_use_ssl': True})
        config = loader.load_config()

        # Check if the default setting got overwritten
        self.assertEqual(config.influxdb_use_ssl, False)

    def test_overwrite_default_config(self):

        default_config = {'kafka_host': 'defaulthost'}