34 lines
904 B
Python
34 lines
904 B
Python
|
import json
|
||
|
from io import BytesIO
|
||
|
from uuid import UUID
|
||
|
|
||
|
|
||
|
def is_valid_uuid(string):
|
||
|
try:
|
||
|
UUID(string, version=4)
|
||
|
except ValueError:
|
||
|
return False
|
||
|
return True
|
||
|
|
||
|
|
||
|
def post_an_activity(app, gpx_file):
|
||
|
client = app.test_client()
|
||
|
resp_login = client.post(
|
||
|
'/api/auth/login',
|
||
|
data=json.dumps(dict(email='test@test.com', password='12345678')),
|
||
|
content_type='application/json',
|
||
|
)
|
||
|
token = json.loads(resp_login.data.decode())['auth_token']
|
||
|
response = client.post(
|
||
|
'/api/activities',
|
||
|
data=dict(
|
||
|
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||
|
data='{"sport_id": 1}',
|
||
|
),
|
||
|
headers=dict(
|
||
|
content_type='multipart/form-data', Authorization=f'Bearer {token}'
|
||
|
),
|
||
|
)
|
||
|
data = json.loads(response.data.decode())
|
||
|
return token, data['data']['activities'][0]['id']
|