API - fix notes emptying

This commit is contained in:
Sam
2021-07-14 14:54:20 +02:00
parent 66b9c77560
commit 70ae3863e2
3 changed files with 87 additions and 55 deletions

View File

@ -1,6 +1,6 @@
import json
from io import BytesIO
from typing import Tuple
from typing import Optional, Tuple
from uuid import uuid4
from flask import Flask
@ -12,7 +12,9 @@ def get_random_short_id() -> str:
return encode_uuid(uuid4())
def post_an_workout(app: Flask, gpx_file: str) -> Tuple[str, str]:
def post_an_workout(
app: Flask, gpx_file: str, notes: Optional[str] = None
) -> Tuple[str, str]:
client = app.test_client()
resp_login = client.post(
'/api/auth/login',
@ -20,11 +22,15 @@ def post_an_workout(app: Flask, gpx_file: str) -> Tuple[str, str]:
content_type='application/json',
)
token = json.loads(resp_login.data.decode())['auth_token']
workout_data = '{"sport_id": 1'
if notes is not None:
workout_data += f', "notes": "{notes}"'
workout_data += '}'
response = client.post(
'/api/workouts',
data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
data='{"sport_id": 1}',
data=workout_data,
),
headers=dict(
content_type='multipart/form-data', Authorization=f'Bearer {token}'