Example #1
0
async def test_update_config(factory: Factory, graphql_query):
    pathObj = factory.rand_path("")
    pathObj.mkdir()
    path = str(pathObj)

    query = f"""
        mutation {{
            updateConfig(
                musicDirectories: ["{path}"],
                indexCrontab: "1 1 * 2 *",
            ) {{
                ...ConfigFields
            }}
        }}
    """
    success, data = await graphql_query(query)
    assert success is True

    expected_crontab = "1 1 * 2 *"

    assert data["data"]["updateConfig"]["musicDirectories"] == [{
        "directory":
        f"{path}",
        "existsOnDisk":
        True
    }]
    assert data["data"]["updateConfig"]["indexCrontab"] == expected_crontab

    assert config.music_directories() == [f"{path}"]
    assert config.index_crontab_str() == expected_crontab
Example #2
0
def test_valid_music_directories(db: Connection, factory: Factory):
    p1 = factory.rand_path("")
    p1.mkdir()
    p2 = factory.rand_path("")
    p2.mkdir()

    directories = [str(p1), str(p2)]

    db.execute(
        "UPDATE system__config SET value = ? WHERE key = ?",
        (json.dumps(directories), MUSIC_DIRECTORIES),
    )
    db.commit()

    # If it doesn't exception we are good.
    music_directories()
    set_music_directories(directories, db)
Example #3
0
def _create_dummy_file_with_hash(factory: Factory) -> tuple[Path, bytes]:
    filepath = factory.rand_path(".m4a")
    with filepath.open("wb") as fp:
        fp.write(b"123")

    sha256sum = sha256(b"123").digest()

    return filepath, sha256sum
Example #4
0
def _create_dummy_file_with_hash(factory: Factory) -> tuple[Path, bytes]:
    filepath = factory.rand_path(".m4a")
    content = random.randbytes(12)
    with filepath.open("wb") as fp:
        fp.write(content)

    sha256sum = sha256(content).digest()

    return filepath, sha256sum