API - test refacto (auth method to get client and token)

This commit is contained in:
Sam 2022-03-12 17:56:06 +01:00
parent 97935d0fbb
commit 1245a64e18
11 changed files with 570 additions and 221 deletions

View File

@ -8,15 +8,20 @@ from flask.testing import FlaskClient
class ApiTestCaseMixin:
@staticmethod
def get_test_client_and_auth_token(
app: Flask, as_admin: bool = False
app: Flask, user_email: str
) -> Tuple[FlaskClient, str]:
"""user_email must be user_1 or user_2 email"""
client = app.test_client()
resp_login = client.post(
'/api/auth/login',
data=json.dumps(
dict(
email='admin@example.com' if as_admin else 'test@test.com',
password='12345678',
email=user_email,
password=(
'87654321'
if user_email == 'toto@toto.com'
else '12345678'
),
)
),
content_type='application/json',

View File

@ -12,7 +12,9 @@ class TestGetConfig(ApiTestCaseMixin):
def test_it_gets_application_config(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/config',
@ -38,7 +40,7 @@ class TestGetConfig(ApiTestCaseMixin):
self, app_no_config: Flask, user_1_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app_no_config, as_admin=True
app_no_config, user_1_admin.email
)
response = client.get(
@ -56,7 +58,7 @@ class TestGetConfig(ApiTestCaseMixin):
self, app: Flask, app_config: Flask, user_1_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.get(
@ -76,7 +78,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
'/api/config',
@ -98,7 +100,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -127,7 +129,9 @@ class TestUpdateConfig(ApiTestCaseMixin):
def test_it_returns_403_when_user_is_not_an_admin(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.patch(
'/api/config',
@ -146,7 +150,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -165,7 +169,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
self, app_no_config: Flask, user_1_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app_no_config, as_admin=True
app_no_config, user_1_admin.email
)
response = client.patch(
@ -184,7 +188,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -213,7 +217,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
self, app_with_max_file_size_equals_0: Flask, user_1_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app_with_max_file_size_equals_0, as_admin=True
app_with_max_file_size_equals_0, user_1_admin.email
)
response = client.patch(
@ -239,7 +243,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -265,7 +269,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(

View File

@ -420,7 +420,9 @@ class TestUserLogin:
class TestUserLogout(ApiTestCaseMixin):
def test_user_can_logout(self, app: Flask, user_1: User) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/auth/logout',
@ -436,7 +438,9 @@ class TestUserLogout(ApiTestCaseMixin):
self, app: Flask, user_1: User
) -> None:
now = datetime.utcnow()
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
with freeze_time(now + timedelta(seconds=4)):
response = client.get(
@ -471,7 +475,9 @@ class TestUserProfile(ApiTestCaseMixin):
def test_it_returns_user_minimal_profile(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/auth/profile',
@ -500,7 +506,9 @@ class TestUserProfile(ApiTestCaseMixin):
def test_it_returns_user_full_profile(
self, app: Flask, user_1_full: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1_full.email
)
response = client.get(
'/api/auth/profile',
@ -540,7 +548,9 @@ class TestUserProfile(ApiTestCaseMixin):
workout_cycling_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/auth/profile',
@ -577,7 +587,9 @@ class TestUserProfile(ApiTestCaseMixin):
class TestUserProfileUpdate(ApiTestCaseMixin):
def test_it_updates_user_profile(self, app: Flask, user_1: User) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit',
@ -623,7 +635,9 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
def test_it_updates_user_profile_without_password(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit',
@ -667,7 +681,9 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
def test_it_returns_error_if_fields_are_missing(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit',
@ -684,7 +700,9 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
def test_it_returns_error_if_payload_is_empty(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit',
@ -701,7 +719,9 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
def test_it_returns_error_if_passwords_mismatch(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit',
@ -731,7 +751,9 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
def test_it_returns_error_if_password_confirmation_is_missing(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit',
@ -762,7 +784,9 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
def test_it_updates_user_preferences(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit/preferences',
@ -805,7 +829,9 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
def test_it_returns_error_if_fields_are_missing(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit/preferences',
@ -822,7 +848,9 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
def test_it_returns_error_if_payload_is_empty(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit/preferences',
@ -841,7 +869,9 @@ class TestUserSportPreferencesUpdate(ApiTestCaseMixin):
def test_it_returns_error_if_payload_is_empty(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit/sports',
@ -858,7 +888,9 @@ class TestUserSportPreferencesUpdate(ApiTestCaseMixin):
def test_it_returns_error_if_sport_id_is_missing(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit/sports',
@ -875,7 +907,9 @@ class TestUserSportPreferencesUpdate(ApiTestCaseMixin):
def test_it_returns_error_if_sport_not_found(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit/sports',
@ -892,7 +926,9 @@ class TestUserSportPreferencesUpdate(ApiTestCaseMixin):
def test_it_returns_error_if_payload_contains_only_sport_id(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit/sports',
@ -909,7 +945,9 @@ class TestUserSportPreferencesUpdate(ApiTestCaseMixin):
def test_it_returns_error_if_color_is_invalid(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit/sports',
@ -939,7 +977,9 @@ class TestUserSportPreferencesUpdate(ApiTestCaseMixin):
sport_2_running: Sport,
input_color: str,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit/sports',
@ -966,7 +1006,9 @@ class TestUserSportPreferencesUpdate(ApiTestCaseMixin):
def test_it_disables_sport_for_auth_user(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit/sports',
@ -993,7 +1035,9 @@ class TestUserSportPreferencesUpdate(ApiTestCaseMixin):
def test_it_updates_stopped_speed_threshold_for_auth_user(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/profile/edit/sports',
@ -1022,7 +1066,9 @@ class TestUserSportPreferencesReset(ApiTestCaseMixin):
def test_it_returns_error_if_sport_does_not_exist(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.delete(
'/api/auth/profile/reset/sports/1',
@ -1041,7 +1087,9 @@ class TestUserSportPreferencesReset(ApiTestCaseMixin):
sport_1_cycling: Sport,
user_sport_1_preference: UserSportPreference,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.delete(
f'/api/auth/profile/reset/sports/{sport_1_cycling.id}',
@ -1060,7 +1108,9 @@ class TestUserSportPreferencesReset(ApiTestCaseMixin):
def test_it_does_not_raise_error_if_sport_preferences_do_not_exist(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.delete(
f'/api/auth/profile/reset/sports/{sport_1_cycling.id}',
@ -1072,7 +1122,9 @@ class TestUserSportPreferencesReset(ApiTestCaseMixin):
class TestUserPicture(ApiTestCaseMixin):
def test_it_updates_user_picture(self, app: Flask, user_1: User) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/picture',
@ -1108,7 +1160,9 @@ class TestUserPicture(ApiTestCaseMixin):
def test_it_returns_error_if_file_is_missing(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/picture',
@ -1126,7 +1180,9 @@ class TestUserPicture(ApiTestCaseMixin):
def test_it_returns_error_if_file_is_invalid(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/auth/picture',
@ -1150,7 +1206,7 @@ class TestUserPicture(ApiTestCaseMixin):
gpx_file: str,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app_with_max_file_size
app_with_max_file_size, user_1.email
)
response = client.post(
@ -1181,7 +1237,7 @@ class TestUserPicture(ApiTestCaseMixin):
gpx_file: str,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app_with_max_zip_file_size
app_with_max_zip_file_size, user_1.email
)
response = client.post(

View File

@ -15,7 +15,9 @@ class TestGetUser(ApiTestCaseMixin):
def test_it_gets_single_user_without_workouts(
self, app: Flask, user_1: User, user_2: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/users/{user_2.username}',
@ -57,7 +59,9 @@ class TestGetUser(ApiTestCaseMixin):
workout_cycling_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/users/{user_1.username}',
@ -93,7 +97,9 @@ class TestGetUser(ApiTestCaseMixin):
def test_it_returns_error_if_user_does_not_exist(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users/not_existing',
@ -111,7 +117,9 @@ class TestGetUsers(ApiTestCaseMixin):
def test_it_get_users_list(
self, app: Flask, user_1: User, user_2: User, user_3: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users',
@ -181,7 +189,9 @@ class TestGetUsers(ApiTestCaseMixin):
workout_running_user_1: Workout,
workout_cycling_user_2: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users',
@ -244,7 +254,9 @@ class TestGetUsers(ApiTestCaseMixin):
user_2: User,
user_3: User,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?page=1',
@ -271,7 +283,9 @@ class TestGetUsers(ApiTestCaseMixin):
user_2: User,
user_3: User,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?page=2',
@ -297,7 +311,9 @@ class TestGetUsers(ApiTestCaseMixin):
user_2: User,
user_3: User,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?page=2',
@ -323,7 +339,9 @@ class TestGetUsers(ApiTestCaseMixin):
user_2: User,
user_3: User,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?per_page=2',
@ -349,7 +367,9 @@ class TestGetUsers(ApiTestCaseMixin):
user_2: User,
user_3: User,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?page=2&per_page=2',
@ -371,7 +391,9 @@ class TestGetUsers(ApiTestCaseMixin):
def test_it_gets_users_list_ordered_by_username(
self, app: Flask, user_1: User, user_2: User, user_3: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?order_by=username',
@ -396,7 +418,9 @@ class TestGetUsers(ApiTestCaseMixin):
def test_it_gets_users_list_ordered_by_username_ascending(
self, app: Flask, user_1: User, user_2: User, user_3: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?order_by=username&order=asc',
@ -421,7 +445,9 @@ class TestGetUsers(ApiTestCaseMixin):
def test_it_gets_users_list_ordered_by_username_descending(
self, app: Flask, user_1: User, user_2: User, user_3: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?order_by=username&order=desc',
@ -450,7 +476,7 @@ class TestGetUsers(ApiTestCaseMixin):
user_3.created_at = datetime.utcnow() - timedelta(hours=1)
user_1_admin.created_at = datetime.utcnow()
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.get(
@ -480,7 +506,7 @@ class TestGetUsers(ApiTestCaseMixin):
user_3.created_at = datetime.utcnow() - timedelta(hours=1)
user_1_admin.created_at = datetime.utcnow()
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.get(
@ -510,7 +536,7 @@ class TestGetUsers(ApiTestCaseMixin):
user_3.created_at = datetime.utcnow() - timedelta(hours=1)
user_1_admin.created_at = datetime.utcnow()
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.get(
@ -537,7 +563,7 @@ class TestGetUsers(ApiTestCaseMixin):
self, app: Flask, user_2: User, user_1_admin: User, user_3: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.get(
@ -564,7 +590,7 @@ class TestGetUsers(ApiTestCaseMixin):
self, app: Flask, user_2: User, user_1_admin: User, user_3: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.get(
@ -591,7 +617,7 @@ class TestGetUsers(ApiTestCaseMixin):
self, app: Flask, user_2: User, user_3: User, user_1_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.get(
@ -623,7 +649,9 @@ class TestGetUsers(ApiTestCaseMixin):
sport_1_cycling: Sport,
workout_cycling_user_2: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?order_by=workouts_count',
@ -657,7 +685,9 @@ class TestGetUsers(ApiTestCaseMixin):
sport_1_cycling: Sport,
workout_cycling_user_2: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?order_by=workouts_count&order=asc',
@ -691,7 +721,9 @@ class TestGetUsers(ApiTestCaseMixin):
sport_1_cycling: Sport,
workout_cycling_user_2: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?order_by=workouts_count&order=desc',
@ -719,7 +751,9 @@ class TestGetUsers(ApiTestCaseMixin):
def test_it_gets_users_list_filtering_on_username(
self, app: Flask, user_1: User, user_2: User, user_3: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?q=toto',
@ -742,7 +776,9 @@ class TestGetUsers(ApiTestCaseMixin):
def test_it_returns_empty_users_list_filtering_on_username(
self, app: Flask, user_1: User, user_2: User, user_3: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?q=not_existing',
@ -764,7 +800,9 @@ class TestGetUsers(ApiTestCaseMixin):
def test_it_users_list_with_complex_query(
self, app: Flask, user_1: User, user_2: User, user_3: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/users?order_by=username&order=desc&page=2&per_page=2',
@ -816,7 +854,7 @@ class TestUpdateUser(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User, user_2: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -838,7 +876,7 @@ class TestUpdateUser(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User, user_2: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -861,7 +899,7 @@ class TestUpdateUser(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User, user_2: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -880,7 +918,7 @@ class TestUpdateUser(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User, user_2: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -901,7 +939,9 @@ class TestUpdateUser(ApiTestCaseMixin):
def test_it_returns_error_if_user_can_not_change_admin_rights(
self, app: Flask, user_1: User, user_2: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.patch(
'/api/users/toto',
@ -920,7 +960,9 @@ class TestDeleteUser(ApiTestCaseMixin):
def test_user_can_delete_its_own_account(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.delete(
'/api/users/test',
@ -932,7 +974,9 @@ class TestDeleteUser(ApiTestCaseMixin):
def test_user_with_workout_can_delete_its_own_account(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
client.post(
'/api/workouts',
data=dict(
@ -959,7 +1003,9 @@ class TestDeleteUser(ApiTestCaseMixin):
sport_1_cycling: Sport,
user_sport_1_preference: UserSportPreference,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.delete(
'/api/users/test',
@ -971,7 +1017,9 @@ class TestDeleteUser(ApiTestCaseMixin):
def test_user_with_picture_can_delete_its_own_account(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
client.post(
'/api/auth/picture',
data=dict(file=(BytesIO(b'avatar'), 'avatar.png')),
@ -991,7 +1039,9 @@ class TestDeleteUser(ApiTestCaseMixin):
def test_user_can_not_delete_another_user_account(
self, app: Flask, user_1: User, user_2: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.delete(
'/api/users/toto',
@ -1006,7 +1056,9 @@ class TestDeleteUser(ApiTestCaseMixin):
def test_it_returns_error_when_deleting_non_existing_user(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.delete(
'/api/users/not_existing',
@ -1022,7 +1074,7 @@ class TestDeleteUser(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User, user_2: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.delete(
@ -1036,7 +1088,7 @@ class TestDeleteUser(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User, user_2_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.delete(
@ -1050,7 +1102,7 @@ class TestDeleteUser(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User, user_2: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.delete(
@ -1074,7 +1126,7 @@ class TestDeleteUser(ApiTestCaseMixin):
user_3: User,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app_with_3_users_max, as_admin=True
app_with_3_users_max, user_1_admin.email
)
client.delete(
'/api/users/toto',
@ -1104,7 +1156,7 @@ class TestDeleteUser(ApiTestCaseMixin):
user_1_paris: User,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app_with_3_users_max, as_admin=True
app_with_3_users_max, user_1_admin.email
)
client.delete(

View File

@ -19,7 +19,9 @@ class TestGetRecords(ApiTestCaseMixin):
workout_cycling_user_1: Workout,
workout_cycling_user_2: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/records',
@ -92,7 +94,9 @@ class TestGetRecords(ApiTestCaseMixin):
sport_2_running: Sport,
workout_cycling_user_2: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/records',
@ -111,7 +115,9 @@ class TestGetRecords(ApiTestCaseMixin):
sport_1_cycling: Sport,
sport_2_running: Sport,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
client.post(
'/api/workouts/no_gpx',
@ -141,7 +147,9 @@ class TestGetRecords(ApiTestCaseMixin):
def test_it_gets_updated_records_after_workouts_post_and_patch(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts/no_gpx',
content_type='application/json',
@ -628,7 +636,9 @@ class TestGetRecords(ApiTestCaseMixin):
sport_1_cycling: Sport,
sport_2_running: Sport,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts/no_gpx',

View File

@ -52,7 +52,9 @@ class TestGetSports(ApiTestCaseMixin):
sport_1_cycling: Sport,
sport_2_running: Sport,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/sports',
@ -73,7 +75,9 @@ class TestGetSports(ApiTestCaseMixin):
sport_1_cycling_inactive: Sport,
sport_2_running: Sport,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/sports',
@ -98,7 +102,7 @@ class TestGetSports(ApiTestCaseMixin):
sport_2_running: Sport,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.get(
@ -132,7 +136,7 @@ class TestGetSports(ApiTestCaseMixin):
db.session.commit()
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.get(
@ -156,7 +160,9 @@ class TestGetSport(ApiTestCaseMixin):
def test_it_gets_a_sport(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/sports/1',
@ -176,7 +182,9 @@ class TestGetSport(ApiTestCaseMixin):
sport_1_cycling: Sport,
user_sport_1_preference: UserSportPreference,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/sports/1',
@ -192,7 +200,9 @@ class TestGetSport(ApiTestCaseMixin):
def test_it_returns_404_if_sport_does_not_exist(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/sports/1',
@ -207,7 +217,9 @@ class TestGetSport(ApiTestCaseMixin):
def test_it_gets_a_inactive_sport(
self, app: Flask, user_1: User, sport_1_cycling_inactive: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/sports/1',
@ -227,7 +239,7 @@ class TestGetSport(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User, sport_1_cycling_inactive: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.get(
@ -250,7 +262,7 @@ class TestUpdateSport(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -273,7 +285,7 @@ class TestUpdateSport(ApiTestCaseMixin):
) -> None:
sport_1_cycling.is_active = False
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -299,7 +311,7 @@ class TestUpdateSport(ApiTestCaseMixin):
workout_cycling_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -326,7 +338,7 @@ class TestUpdateSport(ApiTestCaseMixin):
) -> None:
sport_1_cycling.is_active = False
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -352,7 +364,7 @@ class TestUpdateSport(ApiTestCaseMixin):
user_admin_sport_1_preference: UserSportPreference,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -380,7 +392,7 @@ class TestUpdateSport(ApiTestCaseMixin):
) -> None:
sport_1_cycling.is_active = False
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -401,7 +413,9 @@ class TestUpdateSport(ApiTestCaseMixin):
def test_returns_error_if_user_has_no_admin_rights(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.patch(
'/api/sports/1',
@ -420,7 +434,7 @@ class TestUpdateSport(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(
@ -439,7 +453,7 @@ class TestUpdateSport(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.patch(

View File

@ -12,7 +12,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
def test_it_gets_no_stats_when_user_has_no_workouts(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_time',
@ -27,7 +29,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
def test_it_returns_error_when_user_does_not_exists(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/stats/1000/by_time',
@ -48,7 +52,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
(
@ -75,7 +81,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_time?from=2018-04-01&to=2018-04-30&time=day', # noqa
@ -96,7 +104,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_time',
@ -146,7 +156,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_time?from=2018-04-01&to=2018-04-30', # noqa
@ -186,7 +198,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1_paris.email
)
response = client.get(
f'/api/stats/{user_1_paris.username}/by_time?'
@ -227,7 +241,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_time?time=year',
@ -277,7 +293,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_time?from=2018-04-01&to=2018-04-30&time=year', # noqa
@ -318,7 +336,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1_paris.email
)
response = client.get(
f'/api/stats/{user_1_paris.username}/by_time?from=2018-04-01&to=2018-04-30&time=year', # noqa
@ -358,7 +378,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_time?time=month',
@ -448,7 +470,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1_full.email
)
response = client.get(
f'/api/stats/{user_1_full.username}/by_time?time=month',
@ -538,7 +562,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_time?from=2018-04-01&to=2018-04-30&time=month', # noqa
@ -578,7 +604,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1_full.email
)
response = client.get(
f'/api/stats/{user_1_full.username}/by_time?time=week',
@ -668,7 +696,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_time?from=2018-04-01&to=2018-04-30&time=week', # noqa
@ -708,7 +738,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_time?time=weekm',
@ -798,7 +830,9 @@ class TestGetStatsByTime(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_time?from=2018-04-01&to=2018-04-30&time=weekm', # noqa
@ -840,7 +874,9 @@ class TestGetStatsBySport(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_sport',
@ -878,7 +914,9 @@ class TestGetStatsBySport(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_sport?sport_id=1',
@ -908,7 +946,9 @@ class TestGetStatsBySport(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/stats/1000/by_sport?sport_id=1',
@ -929,7 +969,9 @@ class TestGetStatsBySport(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_sport?sport_id=999',
@ -950,7 +992,9 @@ class TestGetStatsBySport(ApiTestCaseMixin):
seven_workouts_user_1: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/stats/{user_1.username}/by_sport?sport_id="999',
@ -971,7 +1015,7 @@ class TestGetAllStats(ApiTestCaseMixin):
self, app: Flask, user_1_admin: User, user_2: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.get(
@ -1000,7 +1044,7 @@ class TestGetAllStats(ApiTestCaseMixin):
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, as_admin=True
app, user_1_admin.email
)
response = client.get(
@ -1028,7 +1072,9 @@ class TestGetAllStats(ApiTestCaseMixin):
workout_cycling_user_2: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/stats/all',

View File

@ -23,7 +23,9 @@ class TestGetWorkouts(ApiTestCaseMixin):
workout_cycling_user_2: Workout,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts',
@ -119,7 +121,9 @@ class TestGetWorkoutsWithPagination(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts',
@ -157,7 +161,9 @@ class TestGetWorkoutsWithPagination(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?page=1',
@ -195,7 +201,9 @@ class TestGetWorkoutsWithPagination(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?page=2',
@ -233,7 +241,9 @@ class TestGetWorkoutsWithPagination(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?page=3',
@ -259,7 +269,9 @@ class TestGetWorkoutsWithPagination(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?page=A',
@ -282,7 +294,9 @@ class TestGetWorkoutsWithPagination(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?per_page=10',
@ -317,7 +331,9 @@ class TestGetWorkoutsWithPagination(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?per_page=3',
@ -353,7 +369,9 @@ class TestGetWorkoutsWithOrder(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts',
@ -387,7 +405,9 @@ class TestGetWorkoutsWithOrder(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?order=asc',
@ -421,7 +441,9 @@ class TestGetWorkoutsWithOrder(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?order=desc',
@ -457,7 +479,9 @@ class TestGetWorkoutsWithOrderBy(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?order_by=workout_date',
@ -491,7 +515,9 @@ class TestGetWorkoutsWithOrderBy(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?order_by=distance',
@ -519,7 +545,9 @@ class TestGetWorkoutsWithOrderBy(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?order_by=duration',
@ -547,7 +575,9 @@ class TestGetWorkoutsWithOrderBy(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?order_by=ave_speed',
@ -577,7 +607,9 @@ class TestGetWorkoutsWithFilters(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?from=2018-02-01&to=2018-02-28',
@ -615,7 +647,9 @@ class TestGetWorkoutsWithFilters(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?from=2018-03-01&to=2018-03-30',
@ -641,7 +675,9 @@ class TestGetWorkoutsWithFilters(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?from=2018-04-01',
@ -676,7 +712,9 @@ class TestGetWorkoutsWithFilters(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?to=2017-12-31',
@ -710,7 +748,9 @@ class TestGetWorkoutsWithFilters(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?distance_from=5&distance_to=8.1',
@ -744,7 +784,9 @@ class TestGetWorkoutsWithFilters(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?duration_from=00:52&duration_to=01:20',
@ -774,7 +816,9 @@ class TestGetWorkoutsWithFilters(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?ave_speed_from=5&ave_speed_to=10',
@ -808,7 +852,9 @@ class TestGetWorkoutsWithFilters(ApiTestCaseMixin):
) -> None:
workout_cycling_user_1.max_speed = 25
workout_running_user_1.max_speed = 11
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?max_speed_from=10&max_speed_to=20',
@ -840,7 +886,9 @@ class TestGetWorkoutsWithFilters(ApiTestCaseMixin):
sport_2_running: Sport,
workout_running_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?sport_id=2',
@ -872,7 +920,9 @@ class TestGetWorkoutsWithFiltersAndPagination(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?from=2017-01-01&page=2',
@ -906,7 +956,9 @@ class TestGetWorkoutsWithFiltersAndPagination(ApiTestCaseMixin):
sport_1_cycling: Sport,
seven_workouts_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
'/api/workouts?from=2017-01-01&page=2&order=asc',
@ -942,7 +994,9 @@ class TestGetWorkout(ApiTestCaseMixin):
sport_1_cycling: Sport,
workout_cycling_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/workouts/{workout_cycling_user_1.short_id}',
@ -971,7 +1025,9 @@ class TestGetWorkout(ApiTestCaseMixin):
sport_1_cycling: Sport,
workout_cycling_user_2: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/workouts/{workout_cycling_user_2.short_id}',
@ -986,7 +1042,9 @@ class TestGetWorkout(ApiTestCaseMixin):
def test_it_returns_404_if_workout_does_not_exist(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/workouts/{get_random_short_id()}',
@ -1002,7 +1060,9 @@ class TestGetWorkout(ApiTestCaseMixin):
self, app: Flask, user_1: User
) -> None:
random_short_id = get_random_short_id()
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/workouts/{random_short_id}/gpx',
@ -1019,7 +1079,9 @@ class TestGetWorkout(ApiTestCaseMixin):
self, app: Flask, user_1: User
) -> None:
random_short_id = get_random_short_id()
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/workouts/{random_short_id}/chart_data',
@ -1040,7 +1102,9 @@ class TestGetWorkout(ApiTestCaseMixin):
workout_cycling_user_1: Workout,
) -> None:
workout_short_id = workout_cycling_user_1.short_id
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/workouts/{workout_short_id}/gpx',
@ -1063,7 +1127,9 @@ class TestGetWorkout(ApiTestCaseMixin):
workout_cycling_user_1: Workout,
) -> None:
workout_short_id = workout_cycling_user_1.short_id
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/workouts/{workout_short_id}/chart_data',
@ -1086,7 +1152,9 @@ class TestGetWorkout(ApiTestCaseMixin):
workout_cycling_user_1: Workout,
) -> None:
workout_cycling_user_1.gpx = "some path"
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/workouts/{workout_cycling_user_1.short_id}/gpx',
@ -1110,7 +1178,9 @@ class TestGetWorkout(ApiTestCaseMixin):
workout_cycling_user_1: Workout,
) -> None:
workout_cycling_user_1.gpx = 'some path'
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/workouts/{workout_cycling_user_1.short_id}/chart_data',
@ -1129,7 +1199,9 @@ class TestGetWorkout(ApiTestCaseMixin):
def test_it_returns_404_if_workout_has_no_map(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/workouts/map/{uuid4().hex}',
headers=dict(Authorization=f'Bearer {auth_token}'),
@ -1147,7 +1219,9 @@ class TestDownloadWorkoutGpx(ApiTestCaseMixin):
app: Flask,
user_1: User,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/workouts/{get_random_short_id()}/gpx/download',
@ -1166,7 +1240,9 @@ class TestDownloadWorkoutGpx(ApiTestCaseMixin):
sport_1_cycling: Sport,
workout_cycling_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/workouts/{workout_cycling_user_1.short_id}/gpx/download',
@ -1186,7 +1262,9 @@ class TestDownloadWorkoutGpx(ApiTestCaseMixin):
sport_1_cycling: Sport,
workout_cycling_user_2: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.get(
f'/api/workouts/{workout_cycling_user_2.short_id}/gpx/download',
@ -1209,7 +1287,9 @@ class TestDownloadWorkoutGpx(ApiTestCaseMixin):
workout_cycling_user_1.gpx = gpx_file_path
with patch('fittrackee.workouts.workouts.send_from_directory') as mock:
mock.return_value = 'file'
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
client.get(
(

View File

@ -210,7 +210,9 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
def test_it_adds_an_workout_with_gpx_file(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -238,7 +240,9 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
sport_1_cycling: Sport,
gpx_file_wo_name: str,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -270,7 +274,9 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
gpx_file_wo_name: str,
) -> None:
user_1.timezone = 'Europe/Paris'
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -311,7 +317,9 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
sport_1_cycling: Sport,
gpx_file: str,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -339,7 +347,9 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
gpx_file: str,
static_map_get_mock: Mock,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
client.post(
'/api/workouts',
data=dict(
@ -369,7 +379,7 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
static_map_get_mock: Mock,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app_default_static_map
app_default_static_map, user_1.email
)
client.post(
'/api/workouts',
@ -398,7 +408,9 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
sport_1_cycling: Sport,
gpx_file_wo_track: str,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -425,7 +437,9 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
sport_1_cycling: Sport,
gpx_file_invalid_xml: str,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -451,7 +465,9 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
def test_it_returns_400_if_workout_gpx_has_invalid_extension(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -473,7 +489,9 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
def test_it_returns_400_if_sport_id_is_not_provided(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -494,7 +512,9 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
def test_it_returns_500_if_sport_id_does_not_exists(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -516,7 +536,9 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
def test_returns_400_if_no_gpx_file_is_provided(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -540,7 +562,7 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
gpx_file: str,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app_with_max_file_size
app_with_max_file_size, user_1.email
)
response = client.post(
@ -568,7 +590,9 @@ class TestPostWorkoutWithoutGpx(ApiTestCaseMixin):
def test_it_adds_an_workout_without_gpx(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts/no_gpx',
@ -593,7 +617,9 @@ class TestPostWorkoutWithoutGpx(ApiTestCaseMixin):
def test_it_returns_400_if_workout_date_is_missing(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts/no_gpx',
@ -610,7 +636,9 @@ class TestPostWorkoutWithoutGpx(ApiTestCaseMixin):
def test_it_returns_500_if_workout_format_is_invalid(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts/no_gpx',
@ -638,7 +666,9 @@ class TestPostWorkoutWithoutGpx(ApiTestCaseMixin):
sport_1_cycling: Sport,
sport_2_running: Sport,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts/no_gpx',
@ -690,7 +720,9 @@ class TestPostWorkoutWithZipArchive(ApiTestCaseMixin):
file_path = os.path.join(app.root_path, 'tests/files/gpx_test.zip')
# 'gpx_test.zip' contains 3 gpx files (same data) and 1 non-gpx file
with open(file_path, 'rb') as zip_file:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -719,7 +751,9 @@ class TestPostWorkoutWithZipArchive(ApiTestCaseMixin):
# 'gpx_test_folder.zip' contains 3 gpx files (same data) and 1 non-gpx
# file in a folder
with open(file_path, 'rb') as zip_file:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -746,7 +780,9 @@ class TestPostWorkoutWithZipArchive(ApiTestCaseMixin):
)
# 'gpx_test_incorrect.zip' contains 2 gpx files, one is incorrect
with open(file_path, 'rb') as zip_file:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -778,7 +814,7 @@ class TestPostWorkoutWithZipArchive(ApiTestCaseMixin):
# 'gpx_test.zip' contains 3 gpx files (same data) and 1 non-gpx file
with open(file_path, 'rb') as zip_file:
client, auth_token = self.get_test_client_and_auth_token(
app_with_max_workouts
app_with_max_workouts, user_1.email
)
client.post(
@ -811,7 +847,7 @@ class TestPostWorkoutWithZipArchive(ApiTestCaseMixin):
# 'gpx_test.zip' contains 3 gpx files (same data) and 1 non-gpx file
with open(file_path, 'rb') as zip_file:
client, auth_token = self.get_test_client_and_auth_token(
app_with_max_zip_file_size
app_with_max_zip_file_size, user_1.email
)
response = client.post(
@ -836,9 +872,11 @@ class TestPostWorkoutWithZipArchive(ApiTestCaseMixin):
class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
def workout_assertion(
self, app: Flask, gpx_file: str, with_segments: bool
self, app: Flask, user_1: User, gpx_file: str, with_segments: bool
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
data=dict(
@ -917,7 +955,7 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
def test_it_gets_an_workout_created_with_gpx(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
) -> None:
return self.workout_assertion(app, gpx_file, False)
return self.workout_assertion(app, user_1, gpx_file, False)
def test_it_gets_an_workout_created_with_gpx_with_segments(
self,
@ -926,12 +964,16 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
sport_1_cycling: Sport,
gpx_file_with_segments: str,
) -> None:
return self.workout_assertion(app, gpx_file_with_segments, True)
return self.workout_assertion(
app, user_1, gpx_file_with_segments, True
)
def test_it_gets_chart_data_for_an_workout_created_with_gpx(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -960,7 +1002,9 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
def test_it_gets_segment_chart_data_for_an_workout_created_with_gpx(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -994,7 +1038,9 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
sport_1_cycling: Sport,
gpx_file: str,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
data=dict(
@ -1030,7 +1076,9 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
def test_it_returns_500_on_invalid_segment_id(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -1059,7 +1107,9 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
def test_it_returns_404_if_segment_id_does_not_exist(
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts',
@ -1090,7 +1140,9 @@ class TestPostAndGetWorkoutWithoutGpx(ApiTestCaseMixin):
def test_it_add_and_gets_an_workout_wo_gpx(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts/no_gpx',
@ -1121,7 +1173,9 @@ class TestPostAndGetWorkoutWithoutGpx(ApiTestCaseMixin):
def test_it_adds_and_gets_an_workout_wo_gpx_notes(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts/no_gpx',
@ -1156,7 +1210,9 @@ class TestPostAndGetWorkoutUsingTimezones(ApiTestCaseMixin):
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
user_1.timezone = 'Europe/Paris'
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.post(
'/api/workouts/no_gpx',
@ -1194,7 +1250,9 @@ class TestPostAndGetWorkoutUsingTimezones(ApiTestCaseMixin):
def test_it_adds_and_gets_workouts_date_filter_with_timezone_new_york(
self, app: Flask, user_1_full: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1_full.email
)
client.post(
'/api/workouts/no_gpx',
@ -1234,7 +1292,9 @@ class TestPostAndGetWorkoutUsingTimezones(ApiTestCaseMixin):
sport_1_cycling: Sport,
workout_cycling_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1_paris.email
)
client.post(
'/api/workouts/no_gpx',

View File

@ -250,7 +250,9 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
workout_cycling_user_1: Workout,
) -> None:
workout_short_id = workout_cycling_user_1.short_id
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.patch(
f'/api/workouts/{workout_short_id}',
@ -337,7 +339,9 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
workout_cycling_user_1: Workout,
) -> None:
workout_short_id = workout_cycling_user_1.short_id
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.patch(
f'/api/workouts/{workout_short_id}',
@ -361,7 +365,9 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
) -> None:
workout_short_id = workout_cycling_user_1.short_id
workout_cycling_user_1.notes = uuid4().hex
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.patch(
f'/api/workouts/{workout_short_id}',
@ -384,7 +390,9 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
sport_1_cycling: Sport,
workout_cycling_user_2: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.patch(
f'/api/workouts/{workout_cycling_user_2.short_id}',
@ -415,7 +423,9 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
workout_cycling_user_1: Workout,
) -> None:
workout_short_id = workout_cycling_user_1.short_id
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1_paris.email
)
response = client.patch(
f'/api/workouts/{workout_short_id}',
@ -488,7 +498,9 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
workout_cycling_user_1: Workout,
) -> None:
workout_short_id = workout_cycling_user_1.short_id
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.patch(
f'/api/workouts/{workout_short_id}',
@ -551,7 +563,9 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
sport_1_cycling: Sport,
workout_cycling_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.patch(
f'/api/workouts/{workout_cycling_user_1.short_id}',
@ -572,7 +586,9 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
sport_1_cycling: Sport,
workout_cycling_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.patch(
f'/api/workouts/{workout_cycling_user_1.short_id}',
content_type='application/json',
@ -599,7 +615,9 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
def test_it_returns_404_if_edited_workout_does_not_exists(
self, app: Flask, user_1: User, sport_1_cycling: Sport
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.patch(
f'/api/workouts/{get_random_short_id()}',
content_type='application/json',

View File

@ -63,7 +63,9 @@ class TestDeleteWorkoutWithGpx(ApiTestCaseMixin):
def test_it_returns_404_if_workout_does_not_exist(
self, app: Flask, user_1: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.delete(
f'/api/workouts/{get_random_short_id()}',
headers=dict(Authorization=f'Bearer {auth_token}'),
@ -104,7 +106,9 @@ class TestDeleteWorkoutWithoutGpx(ApiTestCaseMixin):
sport_1_cycling: Sport,
workout_cycling_user_1: Workout,
) -> None:
client, auth_token = self.get_test_client_and_auth_token(app)
client, auth_token = self.get_test_client_and_auth_token(
app, user_1.email
)
response = client.delete(
f'/api/workouts/{workout_cycling_user_1.short_id}',
headers=dict(Authorization=f'Bearer {auth_token}'),