| 1 |
from http import HTTPStatus |
| 2 |
|
| 3 |
from django.test.client import Client |
| 4 |
from django.urls import reverse |
| 5 |
|
| 6 |
|
| 7 |
def test_app_session_gone(db, user): |
| 8 |
# intentionally use a vanilla Django test client |
| 9 |
client = Client() |
| 10 |
# Force login, creates a Django session |
| 11 |
client.force_login(user) |
| 12 |
# That Django session should not play any role. |
| 13 |
resp = client.get( |
| 14 |
reverse("headless:app:account:current_session"), HTTP_X_SESSION_TOKEN="gone" |
| 15 |
) |
| 16 |
assert resp.status_code == HTTPStatus.GONE |
| 17 |
|
| 18 |
|
| 19 |
def test_logout(auth_client, headless_reverse): |
| 20 |
# That Django session should not play any role. |
| 21 |
resp = auth_client.get(headless_reverse("headless:account:current_session")) |
| 22 |
assert resp.status_code == HTTPStatus.OK |
| 23 |
resp = auth_client.delete(headless_reverse("headless:account:current_session")) |
| 24 |
assert resp.status_code == HTTPStatus.UNAUTHORIZED |
| 25 |
resp = auth_client.get(headless_reverse("headless:account:current_session")) |
| 26 |
assert resp.status_code in [HTTPStatus.UNAUTHORIZED, HTTPStatus.GONE] |
| 27 |
|
| 28 |
|
| 29 |
def test_logout_no_token(app_client, user): |
| 30 |
app_client.force_login(user) |
| 31 |
resp = app_client.get(reverse("headless:app:account:current_session")) |
| 32 |
assert resp.status_code == HTTPStatus.OK |
| 33 |
resp = app_client.delete(reverse("headless:app:account:current_session")) |
| 34 |
assert resp.status_code == HTTPStatus.UNAUTHORIZED |
| 35 |
assert "session_token" not in resp.json()["meta"] |