-
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 (#34)
- Loading branch information
Showing
3 changed files
with
74 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,31 @@ | ||
# 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,expected_allowed_methods', ( | ||
('/api/v1/teams/', {'GET', 'POST', 'OPTIONS'}), | ||
('/api/v1/teams/1', {'GET', 'OPTIONS', 'PATCH', 'DELETE'}), | ||
('/api/v1/teams/2', {'OPTIONS'}), | ||
)) | ||
def test_teams_options_authorized( | ||
path, | ||
expected_allowed_methods, | ||
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 set(response.headers['Allow'].split(', ')) == expected_allowed_methods |
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,26 @@ | ||
# pylint: disable=missing-docstring | ||
import pytest | ||
|
||
@pytest.mark.parametrize('path,status_code,expected_allowed_methods', ( | ||
('/api/v1/users/', 204, {'POST', 'OPTIONS'}), | ||
('/api/v1/users/1', 401, None), | ||
)) | ||
def test_users_options_unauthorized(path, status_code, expected_allowed_methods, flask_app_client): | ||
response = flask_app_client.options(path) | ||
|
||
assert response.status_code == status_code | ||
if expected_allowed_methods: | ||
assert set(response.headers['Allow'].split(', ')) == expected_allowed_methods | ||
|
||
|
||
@pytest.mark.parametrize('path,expected_allowed_methods', ( | ||
('/api/v1/users/', {'POST', 'OPTIONS'}), | ||
('/api/v1/users/1', {'GET', 'OPTIONS', 'PATCH'}), | ||
('/api/v1/users/2', {'OPTIONS'}), | ||
)) | ||
def test_users_options_authorized(path, expected_allowed_methods, 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 set(response.headers['Allow'].split(', ')) == expected_allowed_methods |