<reponame>jalanb/portals
from pathlib import Path

from pyfakefs.fake_filesystem_unittest import TestCase

from portals import config


class TestConfigure(TestCase):
    def setUp(self):
        self.setUpPyfakefs()

    def test_read_file(self):
        """config.read_file() reads configuration for a single file

        Assumes a file in same dir with ".yaml" extension
        We do not know if such a file exists
            so use pyfakefs to create one
            and write into it a yaml config like
                name: value
        """
        path_to_module = Path("/path/to/fred.py")
        path_to_config = Path("/path/to/fred.yaml")
        self.fs.create_file(path_to_config, contents="name: value")
        conf = config.read_file(path_to_module)
        expected = "value"
        actual = conf.name
        self.assertEqual(actual, expected)

    def test_read_missing_file(self):
        """config.read_file() reads configuration for a single file

        If the config file does not exist:
            get an empty configuration
        """
        path_to_package = Path("/path/to/fred.py")
        conf = config.read_file(path_to_package)
        self.assertTrue(not conf)

    def test_missing_filename(self):
        path_to_package = Path("/path/to/")
        conf = config.read("", path_to_package)
        self.assertTrue(not conf)
