Skip to content

Commit

Permalink
⚙ fix settings tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshix-1 committed Jun 29, 2024
1 parent b6d5b02 commit 011a248
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 4 additions & 0 deletions an_website/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from base64 import b64encode
from collections.abc import Awaitable, Mapping

from tornado.web import HTTPError

from ..utils.options import Options
from ..utils.request_handler import HTMLRequestHandler
from ..utils.utils import (
Expand Down Expand Up @@ -63,6 +65,8 @@ async def get(self, *, head: bool = False) -> None:

async def post(self) -> None:
"""Handle POST requests to the settings page."""
if not self.request.body.strip():
raise HTTPError(400, "No body provided")
advanced_settings = self.get_bool_argument("advanced_settings", False)
save_in_cookie: bool = self.get_bool_argument("save_in_cookie", False)
token = self.get_argument("access_token", "")
Expand Down
16 changes: 5 additions & 11 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ async def test_setting_stuff_without_cookies(
"/einstellungen"
if request_body
else (
"/einstellungen?theme=pink&no_3rd_party=s&dynload=s&openmoji=i"
"&bumpscosity=0"
"/einstellungen?theme=pink&no_3rd_party=sure&dynload=sure"
"&openmoji=img&bumpscosity=0&save_in_cookie=nope"
)
),
method="POST",
method="POST" if request_body else "GET",
headers=(
{"Content-Type": "application/json"}
if isinstance(request_body, bytes)
else None
),
body=request_body,
body=request_body or None,
follow_redirects=True,
)
assert_valid_response(response, content_type="text/html;charset=utf-8")
Expand Down Expand Up @@ -112,15 +112,9 @@ async def test_setting_stuff_and_saving_to_cookies(
}
),
"theme=pink&no_3rd_party=s&dynload=s&save_in_cookie=s&openmoji=i&bumpscosity=0",
"",
):
response = await fetch(
"/einstellungen"
+ (
"?theme=pink&no_3rd_party=s&dynload=s&openmoji=i&save_in_cookie=s&bumpscosity=0"
if not request_body
else ""
),
"/einstellungen",
method="POST",
headers=(
{"Content-Type": "application/json"}
Expand Down

0 comments on commit 011a248

Please sign in to comment.