Exemple #1
0
    def test_from_config(self):
        with TemporaryDirectory() as root:
            # create hb root dir
            hb_root = Path(root, 'hidebound').as_posix()
            os.makedirs(hb_root)
            spec_file = self.write_spec_file(root)

            config = dict(
                root_directory=root,
                hidebound_directory=hb_root,
                specification_files=[spec_file],
                include_regex='foo',
                exclude_regex='bar',
                write_mode='copy',
            )
            expected = copy(config)
            Database.from_config(config)
            self.assertEqual(config, expected)

            config['specification_files'] = ['/foo/bar.py']
            with self.assertRaises(DataError):
                Database.from_config(config)
Exemple #2
0
def initialize():
    # type: () -> flask.Response
    '''
    Initialize database with given config.

    Returns:
        Response: Flask Response instance.
    '''
    global DATABASE
    global CONFIG

    config = dict(
        specification_files=[],
        include_regex='',
        exclude_regex=r'\.DS_Store',
        write_mode='copy',
    )

    temp = flask.request.get_json()
    try:
        temp = json.loads(temp)
    except (JSONDecodeError, TypeError):
        return server_tools.get_config_error()
    if not isinstance(temp, dict):
        return server_tools.get_config_error()

    config.update(temp)
    DATABASE = Database.from_config(config)
    CONFIG = config

    return flask.Response(
        response=json.dumps(dict(
            message='Database initialized.',
            config=config,
        )),
        mimetype='application/json'
    )