API - remove unmaintained command

This commit is contained in:
Sam 2022-02-12 14:13:55 +01:00
parent 1a53d4a991
commit b1cafc585d
5 changed files with 3 additions and 82 deletions

View File

@ -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()

View File

@ -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']

View File

@ -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'):

22
poetry.lock generated
View File

@ -1206,22 +1206,6 @@ category = "dev"
optional = false
python-versions = ">=3.7"
[[package]]
name = "tqdm"
version = "4.62.3"
description = "Fast, Extensible Progress Meter"
category = "main"
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7"
[package.dependencies]
colorama = {version = "*", markers = "platform_system == \"Windows\""}
[package.extras]
dev = ["py-make (>=0.1.0)", "twine", "wheel"]
notebook = ["ipywidgets (>=6)"]
telegram = ["requests"]
[[package]]
name = "trio"
version = "0.19.0"
@ -1367,7 +1351,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-
[metadata]
lock-version = "1.1"
python-versions = "^3.7"
content-hash = "efbc9200e445df97c991ac1e6b72873262c32e0f09b21dc682593fd5034686ab"
content-hash = "ec6da4aaa4cef6ee6c235ef4d2f101b533409097ee8b5169596373a5b4c60cdb"
[metadata.files]
alabaster = [
@ -2105,10 +2089,6 @@ tomli = [
{file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"},
{file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"},
]
tqdm = [
{file = "tqdm-4.62.3-py2.py3-none-any.whl", hash = "sha256:8dd278a422499cd6b727e6ae4061c40b48fce8b76d1ccbf5d34fca9b7f925b0c"},
{file = "tqdm-4.62.3.tar.gz", hash = "sha256:d359de7217506c9851b7869f3708d8ee53ed70a1b8edbba4dbcb47442592920d"},
]
trio = [
{file = "trio-0.19.0-py3-none-any.whl", hash = "sha256:c27c231e66336183c484fbfe080fa6cc954149366c15dc21db8b7290081ec7b8"},
{file = "trio-0.19.0.tar.gz", hash = "sha256:895e318e5ec5e8cea9f60b473b6edb95b215e82d99556a03eb2d20c5e027efe1"},

View File

@ -38,7 +38,6 @@ python-forecastio = "^1.4"
pytz = "^2021.3"
shortuuid = "^1.0.8"
staticmap = "^0.5.4"
tqdm = "^4.62"
SQLAlchemy = "1.4.31"
pyOpenSSL = "^22.0"