-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
89 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
from test.fixtures import * | ||
|
||
import pytest | ||
from mock import patch | ||
|
||
from app import app as realapp | ||
from data import model | ||
from endpoints.api import api | ||
from endpoints.api.organization import Organization, OrganizationCollaboratorList | ||
from endpoints.api.organization import ( | ||
Organization, | ||
OrganizationCollaboratorList, | ||
OrganizationList, | ||
) | ||
from endpoints.api.test.shared import conduct_api_call | ||
from endpoints.test.shared import client_with_identity | ||
from features import FeatureNameValue | ||
from test.fixtures import * | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -44,3 +50,36 @@ def test_get_organization_collaborators(app): | |
if collaborator["name"] == "outsideorg": | ||
assert "orgrepo" in collaborator["repositories"] | ||
assert "anotherorgrepo" not in collaborator["repositories"] | ||
|
||
|
||
def test_create_org_as_superuser_with_restricted_users_set(app): | ||
body = { | ||
"name": "buyandlarge", | ||
"email": "[email protected]", | ||
} | ||
|
||
# check if super users can create organizations regardles of restricted users set | ||
with patch("features.RESTRICTED_USERS", FeatureNameValue("RESTRICTED_USERS", True)): | ||
with client_with_identity("devtable", app) as cl: | ||
resp = conduct_api_call( | ||
cl, OrganizationList, "POST", None, body=body, expected_code=201 | ||
) | ||
|
||
# unset all super users temporarily | ||
superuser_list = realapp.config.get("SUPER_USERS") | ||
realapp.config["SUPER_USERS"] = [] | ||
|
||
body = { | ||
"name": "buyandlargetimes2", | ||
"email": "[email protected]", | ||
} | ||
|
||
# check if users who are not super users can create organizations when restricted users is set | ||
with patch("features.RESTRICTED_USERS", FeatureNameValue("RESTRICTED_USERS", True)): | ||
with client_with_identity("devtable", app) as cl: | ||
resp = conduct_api_call( | ||
cl, OrganizationList, "POST", None, body=body, expected_code=403 | ||
) | ||
|
||
# reset superuser list to previous value | ||
realapp.config["SUPER_USERS"] = superuser_list |
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