-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
22 changed files
with
157 additions
and
72 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
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
73 changes: 73 additions & 0 deletions
73
backend/tests/integration/common_utils/managers/settings.py
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,73 @@ | ||
from typing import Any | ||
from typing import Dict | ||
from typing import Optional | ||
|
||
import requests | ||
|
||
from tests.integration.common_utils.constants import API_SERVER_URL | ||
from tests.integration.common_utils.constants import GENERAL_HEADERS | ||
from tests.integration.common_utils.test_models import DATestSettings | ||
from tests.integration.common_utils.test_models import DATestUser | ||
|
||
|
||
class SettingsManager: | ||
@staticmethod | ||
def get_settings( | ||
user_performing_action: DATestUser | None = None, | ||
) -> Dict[str, Any]: | ||
headers = ( | ||
user_performing_action.headers | ||
if user_performing_action | ||
else GENERAL_HEADERS | ||
) | ||
headers.pop("Content-Type", None) | ||
|
||
response = requests.get( | ||
f"{API_SERVER_URL}/api/manage/admin/settings", | ||
headers=headers, | ||
) | ||
|
||
if not response.ok: | ||
return ( | ||
{}, | ||
f"Failed to get settings - {response.json().get('detail', 'Unknown error')}", | ||
) | ||
|
||
return response.json(), "" | ||
|
||
@staticmethod | ||
def update_settings( | ||
settings: DATestSettings, | ||
user_performing_action: DATestUser | None = None, | ||
) -> Dict[str, Any]: | ||
headers = ( | ||
user_performing_action.headers | ||
if user_performing_action | ||
else GENERAL_HEADERS | ||
) | ||
headers.pop("Content-Type", None) | ||
|
||
payload = settings.model_dump() | ||
response = requests.patch( | ||
f"{API_SERVER_URL}/api/manage/admin/settings", | ||
json=payload, | ||
headers=headers, | ||
) | ||
|
||
if not response.ok: | ||
return ( | ||
{}, | ||
f"Failed to update settings - {response.json().get('detail', 'Unknown error')}", | ||
) | ||
|
||
return response.json(), "" | ||
|
||
@staticmethod | ||
def get_setting( | ||
key: str, | ||
user_performing_action: DATestUser | None = None, | ||
) -> Optional[Any]: | ||
settings, error = SettingsManager.get_settings(user_performing_action) | ||
if error: | ||
return None | ||
return settings.get(key) |
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
14 changes: 14 additions & 0 deletions
14
backend/tests/integration/tests/anonymous_user/test_anonymous_user.py
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,14 @@ | ||
from tests.integration.common_utils.managers.settings import SettingsManager | ||
from tests.integration.common_utils.managers.user import UserManager | ||
from tests.integration.common_utils.test_models import DATestSettings | ||
from tests.integration.common_utils.test_models import DATestUser | ||
|
||
|
||
def test_limited(reset: None) -> None: | ||
"""Verify that with a limited role key, limited endpoints are accessible and | ||
others are not.""" | ||
|
||
# Creating an admin user (first user created is automatically an admin) | ||
admin_user: DATestUser = UserManager.create(name="admin_user") | ||
SettingsManager.update_settings(DATestSettings(anonymous_user_enabled=True)) | ||
print(admin_user.headers) |
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
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
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
Oops, something went wrong.