API - test refacto (auth method to get client and token)
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user