API - remove unmaintained command
This commit is contained in:
@ -8,11 +8,8 @@ import gunicorn.app.base
|
||||
from flask import Flask
|
||||
from flask_dramatiq import worker
|
||||
from flask_migrate import upgrade
|
||||
from tqdm import tqdm
|
||||
|
||||
from fittrackee import create_app, db
|
||||
from fittrackee.workouts.models import Workout
|
||||
from fittrackee.workouts.utils import update_workout
|
||||
|
||||
HOST = os.getenv('HOST', '0.0.0.0')
|
||||
PORT = os.getenv('PORT', '5000')
|
||||
@ -50,7 +47,7 @@ def upgrade_db() -> None:
|
||||
|
||||
@app.cli.command('drop-db')
|
||||
def drop_db() -> None:
|
||||
"""Empty database for dev environments."""
|
||||
"""Empty database and delete uploaded files for dev environments."""
|
||||
db.engine.execute("DROP TABLE IF EXISTS alembic_version;")
|
||||
db.drop_all()
|
||||
db.session.commit()
|
||||
@ -59,24 +56,6 @@ def drop_db() -> None:
|
||||
print('Uploaded files deleted.')
|
||||
|
||||
|
||||
@app.cli.command()
|
||||
def recalculate() -> None:
|
||||
print("Starting workouts data refresh")
|
||||
workouts = (
|
||||
Workout.query.filter(Workout.gpx != None) # noqa
|
||||
.order_by(Workout.workout_date.asc()) # noqa
|
||||
.all()
|
||||
)
|
||||
if len(workouts) == 0:
|
||||
print('➡️ no workouts to upgrade.')
|
||||
return None
|
||||
pbar = tqdm(workouts)
|
||||
for workout in pbar:
|
||||
update_workout(workout)
|
||||
pbar.set_postfix(activitiy_id=workout.id)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
options = {'bind': f'{HOST}:{PORT}', 'workers': WORKERS}
|
||||
StandaloneApplication(app, options).run()
|
||||
|
@ -7,7 +7,6 @@ from flask import Flask
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from fittrackee.workouts.utils_id import decode_short_id
|
||||
|
||||
from ..api_test_case import ApiTestCaseMixin
|
||||
from .utils import get_random_short_id, post_an_workout
|
||||
@ -619,37 +618,3 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
|
||||
assert response.status_code == 404
|
||||
assert 'not found' in data['status']
|
||||
assert len(data['data']['workouts']) == 0
|
||||
|
||||
|
||||
class TestRefreshWorkoutWithGpx:
|
||||
def test_refresh_an_workout_with_gpx(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
workout_uuid = decode_short_id(workout_short_id)
|
||||
client = app.test_client()
|
||||
|
||||
# Edit some workout data
|
||||
workout = Workout.query.filter_by(uuid=workout_uuid).first()
|
||||
workout.ascent = 1000
|
||||
workout.min_alt = -100
|
||||
|
||||
response = client.patch(
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(refresh=True)),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert 1 == data['data']['workouts'][0]['sport_id']
|
||||
assert 0.4 == data['data']['workouts'][0]['ascent']
|
||||
assert 975.0 == data['data']['workouts'][0]['min_alt']
|
||||
|
@ -189,14 +189,12 @@ def edit_workout(
|
||||
workout: Workout, workout_data: Dict, auth_user: User
|
||||
) -> Workout:
|
||||
"""
|
||||
Edit an workout
|
||||
Edit a workout
|
||||
Note: the gpx file is NOT modified
|
||||
|
||||
In a next version, map_data and weather_data will be updated
|
||||
(case of a modified gpx file, see issue #7)
|
||||
"""
|
||||
if workout_data.get('refresh'):
|
||||
workout = update_workout(workout)
|
||||
if workout_data.get('sport_id'):
|
||||
workout.sport_id = workout_data.get('sport_id')
|
||||
if workout_data.get('title'):
|
||||
|
Reference in New Issue
Block a user