API - refacto + remove unused endpoint for now
This commit is contained in:
@ -5,7 +5,7 @@ from flask import Flask
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..api_test_case import ApiTestCaseMixin
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
|
||||
|
||||
class TestGetRecords(ApiTestCaseMixin):
|
||||
|
@ -6,7 +6,7 @@ from fittrackee import db
|
||||
from fittrackee.users.models import User, UserSportPreference
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..api_test_case import ApiTestCaseMixin
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
|
||||
expected_sport_1_cycling_result = {
|
||||
'id': 1,
|
||||
|
@ -5,7 +5,7 @@ from flask import Flask
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..api_test_case import ApiTestCaseMixin
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
|
||||
|
||||
class TestGetStatsByTime(ApiTestCaseMixin):
|
||||
|
@ -7,7 +7,7 @@ from flask import Flask
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..api_test_case import ApiTestCaseMixin
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from .utils import get_random_short_id
|
||||
|
||||
|
||||
@ -73,19 +73,13 @@ class TestGetWorkouts(ApiTestCaseMixin):
|
||||
workout_cycling_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='toto@toto.com', password='87654321')),
|
||||
content_type='application/json',
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_2.email
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/workouts',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
|
@ -12,7 +12,7 @@ from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from fittrackee.workouts.utils.short_id import decode_short_id
|
||||
|
||||
from ..api_test_case import ApiTestCaseMixin, CallArgsMixin
|
||||
from ..mixins import ApiTestCaseMixin, CallArgsMixin
|
||||
|
||||
|
||||
def assert_workout_data_with_gpx(data: Dict) -> None:
|
||||
@ -1018,18 +1018,13 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
workout_short_id = data['data']['workouts'][0]['id']
|
||||
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='toto@toto.com', password='87654321')),
|
||||
content_type='application/json',
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_2.email
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
f'/api/workouts/{workout_short_id}/chart_data',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
)
|
||||
|
||||
self.assert_403(response)
|
||||
|
@ -8,7 +8,7 @@ from flask import Flask
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..api_test_case import ApiTestCaseMixin
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from .utils import get_random_short_id, post_an_workout
|
||||
|
||||
|
||||
@ -152,21 +152,15 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
_, workout_short_id = post_an_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='toto@toto.com', password='87654321')),
|
||||
content_type='application/json',
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_2.email
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2, title="Workout test")),
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
)
|
||||
|
||||
self.assert_403(response)
|
||||
|
@ -1,4 +1,3 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from flask import Flask
|
||||
@ -7,7 +6,7 @@ from fittrackee.files import get_absolute_file_path
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..api_test_case import ApiTestCaseMixin
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from .utils import get_random_short_id, post_an_workout
|
||||
|
||||
|
||||
@ -39,19 +38,13 @@ class TestDeleteWorkoutWithGpx(ApiTestCaseMixin):
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
_, workout_short_id = post_an_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='toto@toto.com', password='87654321')),
|
||||
content_type='application/json',
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_2.email
|
||||
)
|
||||
|
||||
response = client.delete(
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
)
|
||||
|
||||
self.assert_403(response)
|
||||
@ -113,18 +106,13 @@ class TestDeleteWorkoutWithoutGpx(ApiTestCaseMixin):
|
||||
sport_1_cycling: Sport,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(email='toto@toto.com', password='87654321')),
|
||||
content_type='application/json',
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_2.email
|
||||
)
|
||||
|
||||
response = client.delete(
|
||||
f'/api/workouts/{workout_cycling_user_1.short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
)
|
||||
|
||||
self.assert_403(response)
|
||||
|
Reference in New Issue
Block a user