A bunch of remaining ds_client conversions, refs #1959

This commit is contained in:
Simon Willison 2022-12-16 09:44:30 -08:00
commit 42a66c2f04
5 changed files with 17 additions and 14 deletions

View file

@ -1,8 +1,9 @@
from .fixtures import app_client
from .utils import cookie_was_deleted
import pytest
@pytest.mark.ds_client
@pytest.mark.asyncio
@pytest.mark.parametrize(
"qs,expected",
[
@ -11,18 +12,20 @@ import pytest
("add_msg=added-error&type=ERROR", [["added-error", 3]]),
],
)
def test_add_message_sets_cookie(app_client, qs, expected):
response = app_client.get(f"/fixtures.message?{qs}")
async def test_add_message_sets_cookie(ds_client, qs, expected):
response = await ds_client.get(f"/fixtures.message?{qs}")
signed = response.cookies["ds_messages"]
decoded = app_client.ds.unsign(signed, "messages")
decoded = ds_client.ds.unsign(signed, "messages")
assert expected == decoded
def test_messages_are_displayed_and_cleared(app_client):
@pytest.mark.ds_client
@pytest.mark.asyncio
async def test_messages_are_displayed_and_cleared(ds_client):
# First set the message cookie
set_msg_response = app_client.get("/fixtures.message?add_msg=xmessagex")
set_msg_response = await ds_client.get("/fixtures.message?add_msg=xmessagex")
# Now access a page that displays messages
response = app_client.get("/", cookies=set_msg_response.cookies)
response = await ds_client.get("/", cookies=set_msg_response.cookies)
# Messages should be in that HTML
assert "xmessagex" in response.text
# Cookie should have been set that clears messages