-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Made it unnecessary to have testing api creds in CI. - Added a way to disallow certain boolean settings in prod - Renamed some authentication stuff to be less confusing - UI permissions endpoint and tests
- Loading branch information
1 parent
1574ee2
commit 49c355b
Showing
15 changed files
with
251 additions
and
24 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 |
---|---|---|
|
@@ -7,5 +7,4 @@ MEDIA_ROOT=/data/cnc_net_files/ | |
STATIC_ROOT=/data/cnc_net_static/ | ||
POSTGRES_TEST_HOST=db | ||
SECRET_KEY=";thetechnologyofpeaceforcidevwork6352722!@#$$#@" | ||
TESTING_API_USERNAME=[email protected] | ||
TESTING_API_PASSWORD=ripbozo2 | ||
RUN_ENVIRONMENT=ci |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from rest_framework.response import Response | ||
from kirovy import typing as t | ||
|
||
|
||
class KirovyResponse(Response): | ||
def __init__( | ||
self, | ||
data: t.Optional[t.Union[t.ListResponseData, t.ResponseData]] = None, | ||
status: t.Optional[int] = None, | ||
template_name: t.Optional[str] = None, | ||
headers: t.Optional[t.DictStrAny] = None, | ||
exception: bool = False, | ||
content_type: t.Optional[str] = None, | ||
): | ||
super().__init__(data, status, template_name, headers, exception, content_type) |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from kirovy.settings.base import * | ||
|
||
TESTING_API_USERNAME = get_env_var("TESTING_API_USERNAME") | ||
TESTING_API_PASSWORD = get_env_var("TESTING_API_PASSWORD") | ||
TESTING_API_USERNAME = get_env_var("TESTING_API_USERNAME", "[email protected]") | ||
TESTING_API_PASSWORD = get_env_var("TESTING_API_PASSWORD", "ripbozo1") | ||
|
||
DATABASES = { | ||
"default": { | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from rest_framework import status | ||
from rest_framework.views import APIView | ||
|
||
from kirovy import permissions, typing as t | ||
from kirovy.request import KirovyRequest | ||
from kirovy.response import KirovyResponse | ||
|
||
|
||
class ListPermissionForAuthUser(APIView): | ||
"""End point to check which buttons / views the UI should show. | ||
The UI showing the buttons / views will not guarantee access. The backend still checks permissions for all | ||
requests. This just helps the UI know what to render. DO NOT use for permission checks within Kirovy. | ||
""" | ||
|
||
permission_classes = [permissions.ReadOnly] | ||
http_method_names = [ | ||
"get", | ||
] | ||
|
||
def get(self, request: KirovyRequest, *args, **kwargs) -> KirovyResponse: | ||
data = t.ResponseData( | ||
result=permissions.UiPermissions.render_static(request, self) | ||
) | ||
return KirovyResponse(data=data, status=status.HTTP_200_OK) |
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,5 +1,6 @@ | ||
-r requirements.txt | ||
pytest==7.* | ||
pytest-mock==3.* | ||
black==22.* | ||
pre-commit==2.* | ||
pytest-django==4.5.2 | ||
|
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import pytest | ||
import requests | ||
import ujson | ||
from django.contrib.auth.models import AnonymousUser | ||
from django.test import Client | ||
from django.conf import ( | ||
settings as _settings, | ||
|
@@ -77,7 +78,7 @@ def __convert_data(self, data: JsonLike, content_type: str) -> str: | |
|
||
def set_active_user( | ||
self, | ||
kirovy_user: t.Optional[CncUser] = None, | ||
kirovy_user: t.Optional[t.Union[CncUser, AnonymousUser]] = None, | ||
cncnet_user_info: t.Optional[objects.CncnetUserInfo] = None, | ||
) -> None: | ||
"""Set the active user for requests. | ||
|
@@ -184,7 +185,7 @@ def create_client(db): | |
""" | ||
|
||
def _inner( | ||
active_user: t.Optional[CncUser] = None, | ||
active_user: t.Optional[t.Union[CncUser, AnonymousUser]] = None, | ||
cnc_user_info: t.Optional[objects.CncnetUserInfo] = None, | ||
) -> KirovyClient: | ||
skip_if_no_django() | ||
|
@@ -243,11 +244,38 @@ def _inner( | |
|
||
|
||
@pytest.fixture | ||
def user(create_kirovy_user): | ||
def user(create_kirovy_user) -> CncUser: | ||
"""Convenience method to create a user.""" | ||
return create_kirovy_user() | ||
|
||
|
||
@pytest.fixture | ||
def banned_user(create_kirovy_user) -> CncUser: | ||
"""Returns a user that is verified, but is banned.""" | ||
return create_kirovy_user( | ||
username="MendicantBias", | ||
verified_email=True, | ||
verified_map_uploader=True, | ||
cncnet_id=49, | ||
is_banned=True, | ||
ban_count=2, | ||
ban_date=datetime.datetime.min, | ||
ban_expires=datetime.datetime(2552, 12, 11), | ||
ban_reason="Siding with the shaping sickness", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def non_verified_user(create_kirovy_user) -> CncUser: | ||
"""Returns a user that doesn't have a verified uploader badge, nor verified email.""" | ||
return create_kirovy_user( | ||
cncnet_id=123123, | ||
username="[email protected]", | ||
verified_email=False, | ||
verified_map_uploader=False, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def moderator(create_kirovy_user) -> CncUser: | ||
"""Convenience method to create a moderator.""" | ||
|
@@ -272,12 +300,30 @@ def god(create_kirovy_user) -> CncUser: | |
) | ||
|
||
|
||
@pytest.fixture | ||
def client_anonymous(create_client) -> KirovyClient: | ||
"""Returns a client with a user that isn't signed in.""" | ||
return create_client(AnonymousUser()) | ||
|
||
|
||
@pytest.fixture | ||
def client_user(user, create_client) -> KirovyClient: | ||
"""Returns a client with an active admin user.""" | ||
return create_client(user) | ||
|
||
|
||
@pytest.fixture | ||
def client_not_verified(non_verified_user, create_client) -> KirovyClient: | ||
"""Returns a client for a user that hasn't verified their email, and doesn't have a verified uploader badge.""" | ||
return create_client(non_verified_user) | ||
|
||
|
||
@pytest.fixture | ||
def client_banned(banned_user, create_client) -> KirovyClient: | ||
"""Returns a client for a banned user.""" | ||
return create_client(banned_user) | ||
|
||
|
||
@pytest.fixture | ||
def client_moderator(moderator, create_client) -> KirovyClient: | ||
"""Returns a client with an active moderator user.""" | ||
|
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.