Example #1
0
 def read_temp_config_file(self, test_file):
     """Read the specified test configuration file."""
     self.replace_test_config_file(test_file)
     try:
         cfg.read()
     finally:
         self.restore_test_config_file()
def test_common(Notification):
    """Verify that the common() function returns the correct values."""
    cfg.read()  # initialize config settings

    request = HttpRequest()
    request.path = '/aaa/bbb/ccc/'
    request.user = Mock()
    request.user.groups.filter().exists = Mock(return_value=True)
    request.session = MagicMock()
    response = cp.common(request)
    assert response is not None

    config = response['cfg']
    assert config is not None
    assert config.box_name == 'FreedomBox'

    assert response['box_name'] == 'FreedomBox'

    submenu = response['submenu']
    assert submenu is None

    urls = response['active_menu_urls']
    assert urls is not None
    assert ['/', '/aaa/', '/aaa/bbb/', '/aaa/bbb/ccc/'] == urls

    assert response['user_is_admin']
    def test_common(self):
        """Verify that the common() function returns the correct values."""
        cfg.read()  # initialize config settings

        request = HttpRequest()
        request.path = '/aaa/bbb/ccc/'
        request.user = Mock()
        request.user.groups.filter().exists = Mock(return_value=True)
        response = cp.common(request)
        self.assertIsNotNone(response)

        config = response['cfg']
        self.assertIsNotNone(config)
        self.assertEqual('FreedomBox', config.box_name)

        self.assertEqual('FreedomBox', response['box_name'])

        submenu = response['submenu']
        self.assertIsNone(submenu)

        urls = response['active_menu_urls']
        self.assertIsNotNone(urls)
        self.assertEqual(['/', '/aaa/', '/aaa/bbb/', '/aaa/bbb/ccc/'], urls)

        self.assertTrue(response['user_is_admin'])
        request.user.groups.filter().exists = Mock(return_value=False)
        response = cp.common(request)
        self.assertFalse(response['user_is_admin'])
Example #4
0
 def test_read_main_menu(self):
     """Verify that the cfg.main_menu container is initially empty."""
     # Menu should be empty before...
     self.assertEqual(len(cfg.main_menu.items), 0)
     cfg.read(self.test_config_file, self.test_config_dir)
     # ...and after reading the config file
     self.assertEqual(len(cfg.main_menu.items), 0)
Example #5
0
def main():
    """Intialize and start the application"""
    cfg.read()

    parse_arguments()

    setup_logging()

    service.init()

    configure_django()

    logger.info('Configuration loaded from file - %s', cfg.config_file)
    logger.info('Script prefix - %s', cfg.server_dir)

    module_loader.load_modules()
    if arguments.setup is not False:
        run_setup_and_exit(arguments.setup)

    if arguments.setup_no_install is not False:
        run_setup_and_exit(arguments.setup_no_install, allow_install=False)

    if arguments.list_dependencies is not False:
        list_dependencies(arguments.list_dependencies)

    if arguments.list_modules is not False:
        list_modules(arguments.list_modules)

    if arguments.diagnose:
        run_diagnostics_and_exit()

    setup_server()

    cherrypy.engine.start()
    cherrypy.engine.block()
Example #6
0
def main():
    """Intialize and start the application"""
    cfg.read()

    parse_arguments()

    setup_logging()

    service.init()

    configure_django()

    logger.info('Configuration loaded from file - %s', cfg.config_file)
    logger.info('Script prefix - %s', cfg.server_dir)

    module_loader.load_modules()
    if arguments.setup is not False:
        run_setup_and_exit(arguments.setup)

    if arguments.setup_no_install is not False:
        run_setup_and_exit(arguments.setup_no_install, allow_install=False)

    if arguments.list_dependencies is not False:
        list_dependencies(arguments.list_dependencies)

    if arguments.diagnose:
        run_diagnostics_and_exit()

    setup_server()

    cherrypy.engine.start()
    cherrypy.engine.block()
Example #7
0
 def test_read_main_menu(self):
     """Verify that the cfg.main_menu container is initially empty."""
     # Menu should be empty before...
     self.assertEqual(len(cfg.main_menu.items), 0)
     cfg.read()
     # ...and after reading the config file
     self.assertEqual(len(cfg.main_menu.items), 0)
Example #8
0
 def read_temp_config_file(self, test_file):
     """Read the specified test configuration file."""
     self.replace_test_config_file(test_file)
     try:
         cfg.read()
     finally:
         self.restore_test_config_file()
    def test_common(self):
        """Verify that the common() function returns the correct values."""
        cfg.read()      # initialize config settings

        request = HttpRequest()
        request.path = '/aaa/bbb/ccc/'
        request.user = Mock()
        request.user.groups.filter().exists = Mock(return_value=True)
        request.session = MagicMock()
        response = cp.common(request)
        self.assertIsNotNone(response)

        config = response['cfg']
        self.assertIsNotNone(config)
        self.assertEqual('FreedomBox', config.box_name)

        self.assertEqual('FreedomBox', response['box_name'])

        submenu = response['submenu']
        self.assertIsNone(submenu)

        urls = response['active_menu_urls']
        self.assertIsNotNone(urls)
        self.assertEqual(['/', '/aaa/', '/aaa/bbb/', '/aaa/bbb/ccc/'], urls)

        self.assertTrue(response['user_is_admin'])
Example #10
0
def test_read_fallback_config_file():
    """Verify that the correct fallback config file is used"""
    test_dir = os.path.dirname(os.path.realpath(__file__))
    fallback_root = os.path.realpath(os.path.join(test_dir, '..', '..'))
    fallback_config_file = os.path.join(fallback_root, 'plinth.config')
    config_path, root_directory = cfg.get_fallback_config_paths()
    cfg.read(config_path, root_directory)
    assert cfg.config_file == fallback_config_file
    assert cfg.root == fallback_root
Example #11
0
    def test_read_default_config_file(self):
        """Verify that the default config file can be read correctly."""
        # Read the plinth.config file directly
        parser = self.read_config_file(TEST_CONFIG_FILE, TEST_CONFIG_DIR)

        # Read the plinth.config file via the cfg module
        cfg.read()

        # Compare the two results
        self.compare_configurations(parser)
Example #12
0
    def test_read_default_config_file(self):
        """Verify that the default config file can be read correctly."""
        # Read the plinth.config file directly
        parser = self.read_config_file(TEST_CONFIG_FILE, TEST_CONFIG_DIR)

        # Read the plinth.config file via the cfg module
        cfg.read()

        # Compare the two results
        self.compare_configurations(parser)
Example #13
0
def fixture_load_cfg():
    """Load test configuration."""
    from plinth import cfg

    root_dir = pathlib.Path(__file__).resolve().parent
    test_data_dir = root_dir / 'plinth' / 'tests' / 'data'
    cfg_file = test_data_dir / 'etc' / 'plinth' / 'plinth.config'
    cfg.read(str(cfg_file), str(root_dir))
    yield cfg
    cfg.read()
Example #14
0
def test_read_default_config_file(test_config_dir, test_config_file):
    """Verify that the default config file can be read correctly."""
    # Read the plinth.config file directly
    parser = configparser.ConfigParser(defaults={'root': test_config_dir})
    parser.read(test_config_file)

    # Read the plinth.config file via the cfg module
    cfg.read(test_config_file, test_config_dir)

    # Compare the two results
    compare_configurations(parser)
Example #15
0
    def test_read_default_config_file(self):
        """Verify that the default config file can be read correctly."""
        # Read the plinth.config file directly
        parser = configparser.ConfigParser(
            defaults={'root': self.test_config_dir})
        parser.read(self.test_config_file)

        # Read the plinth.config file via the cfg module
        cfg.read(self.test_config_file, self.test_config_dir)

        # Compare the two results
        self.compare_configurations(parser)
Example #16
0
def test_read_dot_d_config_files(get_config_paths):
    """Verify that the configuration is read from .d directories."""
    root_dir = pathlib.Path(__file__).resolve().parent
    config_path = root_dir / 'data' / 'configs' / 'freedombox.config'
    config_path_d = config_path.with_suffix(config_path.suffix + '.d')

    get_config_paths.return_value = [str(config_path)]
    cfg.read()
    assert cfg.config_files[-3] == str(config_path)
    assert cfg.config_files[-2] == str(config_path_d / '01_first.config')
    assert cfg.config_files[-1] == str(config_path_d / '02_second.config')
    assert cfg.box_name == 'FreedomBox02'
Example #17
0
def main():
    """Intialize and start the application"""
    cfg.read()

    parse_arguments()

    setup_logging()

    service.init()

    configure_django()

    logger.info('Configuration loaded from file - %s', cfg.config_file)
    logger.info('Script prefix - %s', cfg.server_dir)

    module_loader.include_urls()

    menu.init()

    module_loader.load_modules()

    if arguments.setup is not False:
        run_setup_and_exit(arguments.setup, allow_install=True)

    if arguments.setup_no_install is not False:
        run_setup_and_exit(arguments.setup_no_install, allow_install=False)

    if arguments.list_dependencies is not False:
        list_dependencies(arguments.list_dependencies)

    if arguments.list_modules is not False:
        list_modules(arguments.list_modules)

    if arguments.diagnose:
        run_diagnostics_and_exit()

    # Run setup steps for essential modules
    # Installation is not necessary as they are dependencies of Plinth
    run_setup(None, allow_install=False)

    setup_server()

    cherrypy.engine.start()
    cherrypy.engine.block()
    def test_common(self):
        """Verify that the common() function returns the correct values."""
        cfg.read()  # initialize config settings

        request = HttpRequest()
        request.path = '/aaa/bbb/ccc/'
        response = cp.common(request)
        self.assertIsNotNone(response)

        config = response['cfg']
        self.assertIsNotNone(config)
        self.assertEqual('FreedomBox', config.box_name)

        submenu = response['submenu']
        self.assertIsNone(submenu)

        urls = response['active_menu_urls']
        self.assertIsNotNone(urls)
        self.assertEqual(['/', '/aaa/', '/aaa/bbb/', '/aaa/bbb/ccc/'], urls)
Example #19
0
    def test_common(self):
        """Verify that the common() function returns the correct values."""
        cfg.read()      # initialize config settings

        request = HttpRequest()
        request.path = '/aaa/bbb/ccc/'
        response = cp.common(request)
        self.assertIsNotNone(response)

        config = response['cfg']
        self.assertIsNotNone(config)
        self.assertEqual('FreedomBox', config.box_name)

        submenu = response['submenu']
        self.assertIsNone(submenu)

        urls = response['active_menu_urls']
        self.assertIsNotNone(urls)
        self.assertEqual(['/', '/aaa/', '/aaa/bbb/', '/aaa/bbb/ccc/'], urls)
Example #20
0
def main():
    """Intialize and start the application"""
    parse_arguments()

    cfg.read()

    setup_logging()

    service.init()

    configure_django()

    LOGGER.info('Configuration loaded from file - %s', cfg.CONFIG_FILE)

    module_loader.load_modules()

    setup_server()

    cherrypy.engine.start()
    cherrypy.engine.block()
Example #21
0
def main():
    """Intialize and start the application"""
    parse_arguments()

    cfg.read()

    setup_logging()

    service.init()

    configure_django()

    LOGGER.info('Configuration loaded from file - %s', cfg.CONFIG_FILE)

    module_loader.load_modules()

    setup_server()

    cherrypy.engine.start()
    cherrypy.engine.block()
Example #22
0
    def test_read_missing_config_file(self):
        """Verify that an exception is raised when there's no config file.

        This test will be executed only if the fallback (non-default) copy of
        plinth.config is NOT present.  If there is only a single, default
        config file available, then that file can be copied to a test area and
        be hidden by temporary renaming.  But if the default file is hidden
        and the fallback file can be found in its place, the fallback file
        will not be renamed.  Instead, the entire test will be skipped.
        """
        if self.fallback_config_file_present:
            self.skipTest(
                'Fallback copy of {} cannot be hidden to establish the test'
                'pre-condition.'.format(CONFIG_FILENAME))
        else:
            with self.assertRaises(FileNotFoundError):
                try:
                    self.rename_test_config_file()
                    cfg.read()
                finally:
                    self.restore_test_config_file()
Example #23
0
    def test_read_missing_config_file(self):
        """Verify that an exception is raised when there's no config file.

        This test will be executed only if the fallback (non-default) copy of
        plinth.config is NOT present.  If there is only a single, default
        config file available, then that file can be copied to a test area and
        be hidden by temporary renaming.  But if the default file is hidden
        and the fallback file can be found in its place, the fallback file
        will not be renamed.  Instead, the entire test will be skipped.
        """
        if self.fallback_config_file_present:
            self.skipTest(
                'Fallback copy of {} cannot be hidden to establish the test'
                'pre-condition.'.format(CONFIG_FILENAME))
        else:
            with self.assertRaises(FileNotFoundError):
                try:
                    self.rename_test_config_file()
                    cfg.read()
                finally:
                    self.restore_test_config_file()
Example #24
0
    def test_read_fallback_config_file(self):
        """Verify that the fallback config file can be read correctly.

        This test will be executed only if there is a fallback (non-default)
        configuration file available for reading.  If so, the cfg default
        values for config filename and root will be temporarily modified to
        prevent any default file from being found, thus allowing the fallback
        file to be located and read.
        """
        if not self.fallback_config_file_present:
            self.skipTest('A fallback copy of {} is not available.'
                          .format(CONFIG_FILENAME))
        else:
            try:
                cfg.DEFAULT_CONFIG_FILE = '/{}'.format(CONFIG_FILENAME)
                cfg.DEFAULT_ROOT = '/'
                parser = self.read_config_file(self.fallback_config_file,
                                               self.fallback_root)
                cfg.read()
                self.compare_configurations(parser)
            finally:
                cfg.DEFAULT_CONFIG_FILE = self.default_config_file
                cfg.DEFAULT_ROOT = self.default_root
Example #25
0
def test_read_primary_config_file():
    """Verify that the primary config file is used by default."""
    original_config_path = cfg.DEFAULT_CONFIG_FILE
    original_root_directory = cfg.DEFAULT_ROOT

    expected_config_path = CONFIG_FILE_WITH_MISSING_OPTIONS
    root_directory = 'x-default-root'
    expected_root_directory = os.path.realpath(root_directory)

    try:
        cfg.DEFAULT_CONFIG_FILE = expected_config_path
        cfg.DEFAULT_ROOT = root_directory
        # reading the config file will fail, but still cfg.root and
        # cfg.config_file will be set for parsing the config file
        try:
            cfg.read()
        except configparser.NoOptionError:
            pass
        assert cfg.config_file == expected_config_path
        assert cfg.root == expected_root_directory
    finally:
        cfg.DEFAULT_CONFIG_FILE = original_config_path
        cfg.DEFAULT_ROOT = original_root_directory
Example #26
0
    def test_read_fallback_config_file(self):
        """Verify that the fallback config file can be read correctly.

        This test will be executed only if there is a fallback (non-default)
        configuration file available for reading.  If so, the cfg default
        values for config filename and root will be temporarily modified to
        prevent any default file from being found, thus allowing the fallback
        file to be located and read.
        """
        if not self.fallback_config_file_present:
            self.skipTest('A fallback copy of {} is not available.'.format(
                CONFIG_FILENAME))
        else:
            try:
                cfg.DEFAULT_CONFIG_FILE = '/{}'.format(CONFIG_FILENAME)
                cfg.DEFAULT_ROOT = '/'
                parser = self.read_config_file(self.fallback_config_file,
                                               self.fallback_root)
                cfg.read()
                self.compare_configurations(parser)
            finally:
                cfg.DEFAULT_CONFIG_FILE = self.default_config_file
                cfg.DEFAULT_ROOT = self.default_root
Example #27
0
def main():
    """Intialize and start the application"""
    cfg.read()

    parse_arguments()

    setup_logging()

    service.init()

    configure_django()

    logger.info('Configuration loaded from file - %s', cfg.CONFIG_FILE)
    logger.info('Script prefix - %s', cfg.server_dir)

    module_loader.load_modules()

    if arguments.diagnose:
        run_diagnostics_and_exit()

    setup_server()

    cherrypy.engine.start()
    cherrypy.engine.block()
Example #28
0
def main():
    """Intialize and start the application"""
    cfg.read()

    parse_arguments()

    setup_logging()

    service.init()

    configure_django()

    logger.info('Configuration loaded from file - %s', cfg.CONFIG_FILE)
    logger.info('Script prefix - %s', cfg.server_dir)

    module_loader.load_modules()

    if arguments.diagnose:
        run_diagnostics_and_exit()

    setup_server()

    cherrypy.engine.start()
    cherrypy.engine.block()
Example #29
0
def test_read_primary_config_file(get_config_paths):
    """Verify that the primary config file is used by default."""
    config_path = CONFIG_FILE_WITH_MISSING_OPTIONS
    get_config_paths.return_value = [config_path]
    cfg.read()
    assert cfg.config_files[-1] == config_path
Example #30
0
    def setUpClass(cls):
        """Setup all the test cases."""
        super(TestSetupMiddleware, cls).setUpClass()

        cfg.read()
Example #31
0
def test_read_missing_config_file():
    """Verify that an exception is raised when there's no config file."""
    with pytest.raises(FileNotFoundError):
        cfg.read('x-non-existant-file', 'x-root-directory')
Example #32
0
 def tearDownClass(cls):
     """Cleanup after all tests are completed."""
     cfg.read()
Example #33
0
def test_read_config_file_with_missing_options(test_config_dir):
    """Verify that missing configuration options can be detected."""
    with pytest.raises(configparser.NoOptionError):
        cfg.read(CONFIG_FILE_WITH_MISSING_OPTIONS, test_config_dir)