API - OAuth2 scopes tests refacto
This commit is contained in:
parent
518251d442
commit
230ce9022e
@ -11,7 +11,7 @@ from fittrackee.application.models import AppConfig
|
||||
from fittrackee.users.models import User
|
||||
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from ..utils import jsonify_dict
|
||||
from ..utils import OAUTH_SCOPES, jsonify_dict
|
||||
|
||||
|
||||
class TestGetConfig(ApiTestCaseMixin):
|
||||
@ -432,15 +432,7 @@ class TestUpdateConfig(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', True),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'application:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
|
@ -19,7 +19,7 @@ from fittrackee.users.utils.token import get_user_token
|
||||
from fittrackee.workouts.models import Sport
|
||||
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from ..utils import jsonify_dict
|
||||
from ..utils import OAUTH_SCOPES, jsonify_dict
|
||||
|
||||
USER_AGENT = (
|
||||
'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(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', True),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'profile:read': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self, app: Flask, user_1: User, client_scope: str, can_access: bool
|
||||
@ -719,15 +711,7 @@ class TestUserProfileUpdate(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', True),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'profile:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -1389,15 +1373,7 @@ class TestUserAccountUpdate(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', True),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'profile:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -1503,15 +1479,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', True),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'profile:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -1721,15 +1689,7 @@ class TestUserSportPreferencesUpdate(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', True),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'profile:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -1812,15 +1772,7 @@ class TestUserSportPreferencesReset(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', True),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'profile:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -1979,15 +1931,7 @@ class TestUserPicture(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', True),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'profile:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
|
@ -12,7 +12,7 @@ from fittrackee.utils import get_readable_duration
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from ..utils import jsonify_dict
|
||||
from ..utils import OAUTH_SCOPES, jsonify_dict
|
||||
|
||||
|
||||
class TestGetUser(ApiTestCaseMixin):
|
||||
@ -135,15 +135,7 @@ class TestGetUser(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', True),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'users:read': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -925,15 +917,7 @@ class TestGetUsers(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', True),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'users:read': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -1436,15 +1420,7 @@ class TestUpdateUser(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', True),
|
||||
('workouts:read', False),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'users:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -1713,15 +1689,7 @@ class TestDeleteUser(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', True),
|
||||
('workouts:read', False),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'users:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
|
@ -53,3 +53,13 @@ TEST_OAUTH_CLIENT_METADATA = {
|
||||
'redirect_uris': [random_domain()],
|
||||
'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,
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from ..utils import OAUTH_SCOPES
|
||||
|
||||
|
||||
class TestGetRecords(ApiTestCaseMixin):
|
||||
@ -901,15 +902,7 @@ class TestGetRecords(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', True),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:read': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
|
@ -8,7 +8,7 @@ from fittrackee.users.models import User, UserSportPreference
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from ..utils import jsonify_dict
|
||||
from ..utils import OAUTH_SCOPES, jsonify_dict
|
||||
|
||||
|
||||
class TestGetSports(ApiTestCaseMixin):
|
||||
@ -141,15 +141,7 @@ class TestGetSports(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', True),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:read': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -281,15 +273,7 @@ class TestGetSport(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', True),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:read': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -520,15 +504,7 @@ class TestUpdateSport(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', True),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
|
@ -7,6 +7,7 @@ from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from ..utils import OAUTH_SCOPES
|
||||
|
||||
|
||||
class TestGetStatsByTime(ApiTestCaseMixin):
|
||||
@ -864,15 +865,7 @@ class TestGetStatsByTime(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', True),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:read': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -1045,15 +1038,7 @@ class TestGetStatsBySport(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', True),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:read': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -1164,15 +1149,7 @@ class TestGetAllStats(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', True),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:read': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
|
@ -12,7 +12,7 @@ from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from ..utils import jsonify_dict
|
||||
from ..utils import OAUTH_SCOPES, jsonify_dict
|
||||
from .utils import get_random_short_id
|
||||
|
||||
|
||||
@ -106,15 +106,7 @@ class TestGetWorkouts(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', True),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:read': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -1316,15 +1308,7 @@ class TestGetWorkout(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', True),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:read': True}.items(),
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
'endpoint',
|
||||
@ -1450,15 +1434,7 @@ class TestDownloadWorkoutGpx(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', True),
|
||||
('workouts:write', False),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:read': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
|
@ -13,6 +13,7 @@ from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..mixins import ApiTestCaseMixin, CallArgsMixin
|
||||
from ..utils import OAUTH_SCOPES
|
||||
|
||||
|
||||
def assert_workout_data_with_gpx(data: Dict) -> None:
|
||||
@ -939,15 +940,7 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', True),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
@ -1280,15 +1273,7 @@ class TestPostWorkoutWithoutGpx(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', True),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
|
@ -9,6 +9,7 @@ from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from ..utils import OAUTH_SCOPES
|
||||
from .utils import get_random_short_id, post_a_workout
|
||||
|
||||
|
||||
@ -227,15 +228,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', True),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
|
@ -5,6 +5,7 @@ from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from ..utils import OAUTH_SCOPES
|
||||
from .utils import get_random_short_id, post_a_workout
|
||||
|
||||
|
||||
@ -104,15 +105,7 @@ class TestDeleteWorkoutWithGpx(ApiTestCaseMixin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'client_scope, can_access',
|
||||
[
|
||||
('application:write', False),
|
||||
('profile:read', False),
|
||||
('profile:write', False),
|
||||
('users:read', False),
|
||||
('users:write', False),
|
||||
('workouts:read', False),
|
||||
('workouts:write', True),
|
||||
],
|
||||
{**OAUTH_SCOPES, 'workouts:write': True}.items(),
|
||||
)
|
||||
def test_expected_scopes_are_defined(
|
||||
self,
|
||||
|
Loading…
Reference in New Issue
Block a user