from pathlib import Path
import shutil


def create_local_testdb(db_path, data_path, db='ixmptest',
                        auth_url='http://localhost'):
    """Create a local database for testing in the directory *db_path*.

    Returns the path to a database properties file in the directory. Contents
    are copied from *data_path*.
    """
    # Copy test database
    dst = Path(db_path) / 'testdb'
    # str() here is for py2 compatibility
    shutil.copytree(str(data_path), str(dst))

    # Create properties file
    props = (Path(data_path) / 'test_auth.properties_template').read_text()
    test_props = dst / 'test.properties'
    test_props.write_text(props.format(
        here=str(dst).replace("\\", "/"),
        db=db,
        auth_url=auth_url
    ))

    return test_props