API - OAuth2 scopes tests refacto

This commit is contained in:
Sam
2023-05-21 16:13:14 +02:00
parent 518251d442
commit 230ce9022e
11 changed files with 46 additions and 239 deletions

View File

@ -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,

View File

@ -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,