-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for OPTIONS method in users and teams modules
- Loading branch information
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# pylint: disable=missing-docstring | ||
import pytest | ||
|
||
@pytest.mark.parametrize('path,status_code', ( | ||
('/api/v1/teams/', 401), | ||
('/api/v1/users/1', 401), | ||
)) | ||
def test_teams_options_unauthorized(path, status_code, flask_app_client): | ||
response = flask_app_client.options(path) | ||
|
||
assert response.status_code == status_code | ||
|
||
|
||
@pytest.mark.parametrize('path,result', ( | ||
('/api/v1/teams/', ['POST', 'OPTIONS']), | ||
('/api/v1/teams/1', ['GET', 'OPTIONS', 'PATCH']), | ||
('/api/v1/teams/2', ['OPTIONS']), | ||
)) | ||
def test_teams_options_authorized( | ||
path, | ||
result, | ||
flask_app_client, | ||
regular_user, | ||
team_for_regular_user, | ||
team_for_nobody | ||
): | ||
with flask_app_client.login(regular_user, auth_scopes=('teams:write', 'teams:read')): | ||
response = flask_app_client.options(path) | ||
|
||
assert response.status_code == 204 | ||
assert len( | ||
list(set(result) - set(response.headers['Allow'].replace(' ', '').split(','))) | ||
) == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# pylint: disable=missing-docstring | ||
import pytest | ||
|
||
@pytest.mark.parametrize('path,status_code,result', ( | ||
('/api/v1/users/', 204, ['POST', 'OPTIONS']), | ||
('/api/v1/users/1', 401, None), | ||
)) | ||
def test_users_options_unauthorized(path, status_code, result, flask_app_client): | ||
response = flask_app_client.options(path) | ||
|
||
assert response.status_code == status_code | ||
if result: | ||
assert len( | ||
list(set(result) - set(response.headers['Allow'].replace(' ', '').split(','))) | ||
) == 0 | ||
|
||
|
||
@pytest.mark.parametrize('path,result', ( | ||
('/api/v1/users/', ['POST', 'OPTIONS']), | ||
('/api/v1/users/1', ['GET', 'OPTIONS', 'PATCH']), | ||
('/api/v1/users/2', ['OPTIONS']), | ||
)) | ||
def test_users_options_authorized(path, result, flask_app_client, regular_user): | ||
with flask_app_client.login(regular_user, auth_scopes=('users:write', 'users:read')): | ||
response = flask_app_client.options(path) | ||
|
||
assert response.status_code == 204 | ||
assert len( | ||
list(set(result) - set(response.headers['Allow'].replace(' ', '').split(','))) | ||
) == 0 |