Merge branch 'tests-refacto' into dev

This commit is contained in:
Sam 2023-05-21 16:29:46 +02:00
commit edfe0233a7
11 changed files with 46 additions and 239 deletions

View File

@ -11,7 +11,7 @@ from fittrackee.application.models import AppConfig
from fittrackee.users.models import User from fittrackee.users.models import User
from ..mixins import ApiTestCaseMixin from ..mixins import ApiTestCaseMixin
from ..utils import jsonify_dict from ..utils import OAUTH_SCOPES, jsonify_dict
class TestGetConfig(ApiTestCaseMixin): class TestGetConfig(ApiTestCaseMixin):
@ -432,15 +432,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'application:write': True}.items(),
('application:write', True),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', False),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,

View File

@ -19,7 +19,7 @@ from fittrackee.users.utils.token import get_user_token
from fittrackee.workouts.models import Sport from fittrackee.workouts.models import Sport
from ..mixins import ApiTestCaseMixin from ..mixins import ApiTestCaseMixin
from ..utils import jsonify_dict from ..utils import OAUTH_SCOPES, jsonify_dict
USER_AGENT = ( USER_AGENT = (
'Mozilla/5.0 (X11; Linux x86_64; rv:98.0) Gecko/20100101 Firefox/98.0' 'Mozilla/5.0 (X11; Linux x86_64; rv:98.0) Gecko/20100101 Firefox/98.0'
@ -622,15 +622,7 @@ class TestUserProfile(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'profile:read': True}.items(),
('application:write', False),
('profile:read', True),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', False),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, app: Flask, user_1: User, client_scope: str, can_access: bool self, app: Flask, user_1: User, client_scope: str, can_access: bool
@ -719,15 +711,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'profile:write': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', True),
('users:read', False),
('users:write', False),
('workouts:read', False),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -1389,15 +1373,7 @@ class TestUserAccountUpdate(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'profile:write': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', True),
('users:read', False),
('users:write', False),
('workouts:read', False),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -1503,15 +1479,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'profile:write': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', True),
('users:read', False),
('users:write', False),
('workouts:read', False),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -1721,15 +1689,7 @@ class TestUserSportPreferencesUpdate(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'profile:write': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', True),
('users:read', False),
('users:write', False),
('workouts:read', False),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -1812,15 +1772,7 @@ class TestUserSportPreferencesReset(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'profile:write': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', True),
('users:read', False),
('users:write', False),
('workouts:read', False),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -1979,15 +1931,7 @@ class TestUserPicture(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'profile:write': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', True),
('users:read', False),
('users:write', False),
('workouts:read', False),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,

View File

@ -12,7 +12,7 @@ from fittrackee.utils import get_readable_duration
from fittrackee.workouts.models import Sport, Workout from fittrackee.workouts.models import Sport, Workout
from ..mixins import ApiTestCaseMixin from ..mixins import ApiTestCaseMixin
from ..utils import jsonify_dict from ..utils import OAUTH_SCOPES, jsonify_dict
class TestGetUser(ApiTestCaseMixin): class TestGetUser(ApiTestCaseMixin):
@ -135,15 +135,7 @@ class TestGetUser(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'users:read': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', True),
('users:write', False),
('workouts:read', False),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -925,15 +917,7 @@ class TestGetUsers(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'users:read': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', True),
('users:write', False),
('workouts:read', False),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -1436,15 +1420,7 @@ class TestUpdateUser(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'users:write': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', True),
('workouts:read', False),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -1713,15 +1689,7 @@ class TestDeleteUser(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'users:write': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', True),
('workouts:read', False),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,

View File

@ -53,3 +53,13 @@ TEST_OAUTH_CLIENT_METADATA = {
'redirect_uris': [random_domain()], 'redirect_uris': [random_domain()],
'scope': 'profile:read workouts:read', 'scope': 'profile:read workouts:read',
} }
OAUTH_SCOPES = {
"application:write": False,
"profile:read": False,
"profile:write": False,
"users:read": False,
"users:write": False,
"workouts:read": False,
"workouts:write": False,
}

View File

@ -7,6 +7,7 @@ from fittrackee.users.models import User
from fittrackee.workouts.models import Sport, Workout from fittrackee.workouts.models import Sport, Workout
from ..mixins import ApiTestCaseMixin from ..mixins import ApiTestCaseMixin
from ..utils import OAUTH_SCOPES
class TestGetRecords(ApiTestCaseMixin): class TestGetRecords(ApiTestCaseMixin):
@ -901,15 +902,7 @@ class TestGetRecords(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:read': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', True),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,

View File

@ -8,7 +8,7 @@ from fittrackee.users.models import User, UserSportPreference
from fittrackee.workouts.models import Sport, Workout from fittrackee.workouts.models import Sport, Workout
from ..mixins import ApiTestCaseMixin from ..mixins import ApiTestCaseMixin
from ..utils import jsonify_dict from ..utils import OAUTH_SCOPES, jsonify_dict
class TestGetSports(ApiTestCaseMixin): class TestGetSports(ApiTestCaseMixin):
@ -141,15 +141,7 @@ class TestGetSports(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:read': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', True),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -281,15 +273,7 @@ class TestGetSport(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:read': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', True),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -520,15 +504,7 @@ class TestUpdateSport(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:write': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', False),
('workouts:write', True),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,

View File

@ -7,6 +7,7 @@ from fittrackee.users.models import User
from fittrackee.workouts.models import Sport, Workout from fittrackee.workouts.models import Sport, Workout
from ..mixins import ApiTestCaseMixin from ..mixins import ApiTestCaseMixin
from ..utils import OAUTH_SCOPES
class TestGetStatsByTime(ApiTestCaseMixin): class TestGetStatsByTime(ApiTestCaseMixin):
@ -864,15 +865,7 @@ class TestGetStatsByTime(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:read': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', True),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -1045,15 +1038,7 @@ class TestGetStatsBySport(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:read': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', True),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -1164,15 +1149,7 @@ class TestGetAllStats(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:read': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', True),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,

View File

@ -12,7 +12,7 @@ from fittrackee.users.models import User
from fittrackee.workouts.models import Sport, Workout from fittrackee.workouts.models import Sport, Workout
from ..mixins import ApiTestCaseMixin from ..mixins import ApiTestCaseMixin
from ..utils import jsonify_dict from ..utils import OAUTH_SCOPES, jsonify_dict
from .utils import get_random_short_id from .utils import get_random_short_id
@ -106,15 +106,7 @@ class TestGetWorkouts(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:read': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', True),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -1316,15 +1308,7 @@ class TestGetWorkout(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:read': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', True),
('workouts:write', False),
],
) )
@pytest.mark.parametrize( @pytest.mark.parametrize(
'endpoint', 'endpoint',
@ -1450,15 +1434,7 @@ class TestDownloadWorkoutGpx(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:read': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', True),
('workouts:write', False),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,

View File

@ -13,6 +13,7 @@ from fittrackee.users.models import User
from fittrackee.workouts.models import Sport, Workout from fittrackee.workouts.models import Sport, Workout
from ..mixins import ApiTestCaseMixin, CallArgsMixin from ..mixins import ApiTestCaseMixin, CallArgsMixin
from ..utils import OAUTH_SCOPES
def assert_workout_data_with_gpx(data: Dict) -> None: def assert_workout_data_with_gpx(data: Dict) -> None:
@ -939,15 +940,7 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:write': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', False),
('workouts:write', True),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,
@ -1280,15 +1273,7 @@ class TestPostWorkoutWithoutGpx(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:write': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', False),
('workouts:write', True),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,

View File

@ -9,6 +9,7 @@ from fittrackee.users.models import User
from fittrackee.workouts.models import Sport, Workout from fittrackee.workouts.models import Sport, Workout
from ..mixins import ApiTestCaseMixin from ..mixins import ApiTestCaseMixin
from ..utils import OAUTH_SCOPES
from .utils import get_random_short_id, post_a_workout from .utils import get_random_short_id, post_a_workout
@ -227,15 +228,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:write': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', False),
('workouts:write', True),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,

View File

@ -5,6 +5,7 @@ from fittrackee.users.models import User
from fittrackee.workouts.models import Sport, Workout from fittrackee.workouts.models import Sport, Workout
from ..mixins import ApiTestCaseMixin from ..mixins import ApiTestCaseMixin
from ..utils import OAUTH_SCOPES
from .utils import get_random_short_id, post_a_workout from .utils import get_random_short_id, post_a_workout
@ -104,15 +105,7 @@ class TestDeleteWorkoutWithGpx(ApiTestCaseMixin):
@pytest.mark.parametrize( @pytest.mark.parametrize(
'client_scope, can_access', 'client_scope, can_access',
[ {**OAUTH_SCOPES, 'workouts:write': True}.items(),
('application:write', False),
('profile:read', False),
('profile:write', False),
('users:read', False),
('users:write', False),
('workouts:read', False),
('workouts:write', True),
],
) )
def test_expected_scopes_are_defined( def test_expected_scopes_are_defined(
self, self,