| 1 |
from .fixtures import app_client |
| 2 |
import pytest |
| 3 |
|
| 4 |
|
| 5 |
@pytest.mark.parametrize( |
| 6 |
"qs,expected", |
| 7 |
[ |
| 8 |
("add_msg=added-message", [["added-message", 1]]), |
| 9 |
("add_msg=added-warning&type=WARNING", [["added-warning", 2]]), |
| 10 |
("add_msg=added-error&type=ERROR", [["added-error", 3]]), |
| 11 |
], |
| 12 |
) |
| 13 |
def test_add_message_sets_cookie(app_client, qs, expected): |
| 14 |
response = app_client.get(f"/fixtures.message?{qs}") |
| 15 |
signed = response.cookies["ds_messages"] |
| 16 |
decoded = app_client.ds.unsign(signed, "messages") |
| 17 |
assert expected == decoded |
| 18 |
|
| 19 |
|
| 20 |
def test_messages_are_displayed_and_cleared(app_client): |
| 21 |
# First set the message cookie |
| 22 |
set_msg_response = app_client.get("/fixtures.message?add_msg=xmessagex") |
| 23 |
# Now access a page that displays messages |
| 24 |
response = app_client.get("/", cookies=set_msg_response.cookies) |
| 25 |
# Messages should be in that HTML |
| 26 |
assert "xmessagex" in response.text |
| 27 |
# Cookie should have been set that clears messages |
| 28 |
assert response.cookie_was_deleted("ds_messages") |