Beispiel #1
0
def test_delete_track_does_not_removes_gpxfile_with_multiple_tracks(
    client, auth, example_users, example_gpxfiles, example_tracks
):
    auth.login("*****@*****.**", "password1")
    user = User.query.get(auth.id)
    assert len(user.gpxfiles.all()) == 2
    assert len(user.tracks.all()) == 3
    track = Track.query.get(1)
    gpxfile = track.file
    assert len(gpxfile.tracks.all()) == 2
    create_empty_file(gpxfile.static_file_path())
    create_empty_file(track.thumbnail_path())
    assert os.path.isfile(gpxfile.static_file_path())
    assert os.path.isfile(track.thumbnail_path())
    r = client.delete(
        url_for("api.delete_user_track", user_id=auth.id, track_id=track.id),
        headers=auth.headers,
    )
    assert r.status_code == 204
    # make sure the thumbnail file and track database object were deleted
    assert len(user.gpxfiles.all()) == 2
    assert len(user.tracks.all()) == 2
    assert not os.path.isfile(track.thumbnail_path())
    # make sure gpxfile still exists and has one track left
    assert len(gpxfile.tracks.all()) == 1
    assert os.path.isfile(gpxfile.static_file_path())
Beispiel #2
0
def test_delete_track_automatically_removes_thumbnail_file(app, example_users):
    track = Track(id=1, thumbnail=str(uuid4()))
    db.session.add(track)
    db.session.commit()
    create_empty_file(track.thumbnail_path())
    assert os.path.isfile(track.thumbnail_path())
    db.session.delete(track)
    db.session.commit()
    assert not os.path.isfile(track.thumbnail_path())
Beispiel #3
0
def test_delete_gpxfile_automatically_removes_static_file(app, example_users):
    user = User.query.get(1)
    gpxfile = GPXFile(id=1, owner=user, filename="GPXFile 01")
    db.session.add(gpxfile)
    db.session.commit()
    create_empty_file(gpxfile.static_file_path())
    assert os.path.isfile(gpxfile.static_file_path())
    db.session.delete(gpxfile)
    db.session.commit()
    assert not os.path.isfile(gpxfile.static_file_path())
Beispiel #4
0
def test_delete_user_automatically_deletes_gpxfiles_and_tracks(
    client, auth, example_users, example_gpxfiles, example_tracks
):
    auth.login("*****@*****.**", "password1")
    assert len(GPXFile.query.all()) == 2
    assert len(Track.query.all()) == 3
    gpxfile = GPXFile.query.get(1)
    create_empty_file(gpxfile.static_file_path())
    assert os.path.isfile(gpxfile.static_file_path())
    r = client.delete(url_for("api.delete_user", user_id=auth.id), headers=auth.headers)
    assert r.status_code == 204
    # make sure the static file and database objects were deleted
    assert len(GPXFile.query.all()) == 0
    assert len(Track.query.all()) == 0
    assert not os.path.isfile(gpxfile.static_file_path())
Beispiel #5
0
def test_delete_track_automatically_removes_gpxfile(
    client, auth, example_users, example_gpxfiles, example_tracks
):
    auth.login("*****@*****.**", "password1")
    user = User.query.get(auth.id)
    assert len(user.gpxfiles.all()) == 2
    assert len(user.tracks.all()) == 3
    track = Track.query.get(3)
    gpxfile = track.file
    create_empty_file(gpxfile.static_file_path())
    create_empty_file(track.thumbnail_path())
    assert os.path.isfile(gpxfile.static_file_path())
    assert os.path.isfile(track.thumbnail_path())
    r = client.delete(
        url_for("api.delete_user_track", user_id=auth.id, track_id=track.id),
        headers=auth.headers,
    )
    assert r.status_code == 204
    # make sure the static files and database objects (including gpxfile) were deleted
    assert len(user.gpxfiles.all()) == 1
    assert len(user.tracks.all()) == 2
    assert not os.path.isfile(gpxfile.static_file_path())
    assert not os.path.isfile(track.thumbnail_path())
Beispiel #6
0
def test_delete_gpxfile(client, auth, example_users, example_gpxfiles,
                        example_tracks):
    auth.login("*****@*****.**", "password1")
    user = User.query.get(auth.id)
    assert len(user.gpxfiles.all()) == 2
    assert len(user.tracks.all()) == 3
    gpxfile = GPXFile.query.get(1)
    track = gpxfile.tracks.first()
    create_empty_file(gpxfile.static_file_path())
    create_empty_file(track.thumbnail_path())
    assert os.path.isfile(gpxfile.static_file_path())
    assert os.path.isfile(track.thumbnail_path())
    r = client.delete(
        url_for("api.delete_user_gpxfile",
                user_id=auth.id,
                gpxfile_id=gpxfile.id),
        headers=auth.headers,
    )
    assert r.status_code == 204
    # make sure the static files and database objects were deleted
    assert len(user.gpxfiles.all()) == 1
    assert len(user.tracks.all()) == 1
    assert not os.path.isfile(gpxfile.static_file_path())
    assert not os.path.isfile(track.thumbnail_path())
Beispiel #7
0
def test_can_delete_track_thumbnail(app):
    track = Track(thumbnail=str(uuid4()))
    create_empty_file(track.thumbnail_path())
    assert os.path.isfile(track.thumbnail_path())
    track.delete_thumbnail_file()
    assert not os.path.isfile(track.thumbnail_path())
Beispiel #8
0
def test_can_delete_gpxfile_static_file(app):
    gpxfile = GPXFile(id=1, user_id=1, filename="GPXFile 01")
    create_empty_file(gpxfile.static_file_path())
    assert os.path.isfile(gpxfile.static_file_path())
    gpxfile.delete_static_file()
    assert not os.path.isfile(gpxfile.static_file_path())