def test_user_delete_deletes_owned_igc_files(db_session):
    with open(igcs.simple_path, "rb") as f:
        filename = files.add_file("simple.igc", f)

    assert filename is not None
    assert os.path.isfile(files.filename_to_path(filename))

    john = users.john()
    igc = igcs.simple(owner=john, filename=filename)
    db_session.add(igc)
    db_session.commit()

    assert db_session.query(IGCFile).count() == 1
    assert db_session.query(IGCFile).get(igc.id).owner_id == john.id

    john.delete()
    db_session.commit()

    assert db_session.query(IGCFile).count() == 0
    assert not os.path.isfile(files.filename_to_path(filename))