#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from configuration import Configuration
import os


class TestConfigurationFunctions(unittest.TestCase):

    def test_configuration_creates_file(self):
        """"Confirm that if a file doesn't exist, that the configuration system
         will create one."""
        path = '~/test.config'
        c = Configuration(path)
        path = os.path.expanduser(path)
        FileExists = os.path.isfile(path)
        self.assertTrue(FileExists, msg="""Configuration file has not been
        created by the configuration object.""")

    def test_configuration_creates_file_with_sensible_values(self):
        """"Confirm that if a file doesn't exist, that the configuration system
         will create one and that it contains sensible defaults."""
        path = '~/test.config'
        FileExists = os.path.isfile(os.path.expanduser(path))
        if FileExists:
            os.remove(os.path.expanduser(path))
        c = Configuration(path)
        path = os.path.expanduser(path)
        FileExists = os.path.isfile(path)
        self.assertTrue(FileExists, msg=("Configuration file has not been "
                                        "created by the configuration object."))

        # Get values from Configuration object
        CastPath = c.CastLocation()
        SensibleCastPath = "~/cast"
        ScanRecursive = c.ScanRecursive()
        SensibleScanRecursive = False

        self.assertEqual(CastPath, SensibleCastPath,("Default configuration is"
                                                        "not a sensible value"))
        self.assertEqual(ScanRecursive, SensibleScanRecursive,("Default "
                                       "configuration is not a sensible value"))




    def test_configuration_returns_a_dictionary_object_representing_settings(self):
        path = '~/test.config'
        FileExists = os.path.isfile(os.path.expanduser(path))
        if FileExists:
            os.remove(os.path.expanduser(path))
        c = Configuration(path)

        res = c.GetDictionary()
        print "hi there"
        print res

    def test_configuration_reads_all_values_correctly_to_file(self):
        #TODO write this test

        pass

    def test_configuration_writes_all_values_correctly_to_file(self):
        pass


if __name__ == '__main__':
    unittest.main()