diff options
Diffstat (limited to 'tests/test_users.py')
| -rw-r--r-- | tests/test_users.py | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/tests/test_users.py b/tests/test_users.py index dfd7a06..8bfd058 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -1,6 +1,8 @@ import pytest -from flask import url_for +from flask import url_for, session + +from sw.db import get_db def test_get_user_info_existing_user(app, client): @@ -69,3 +71,47 @@ def test_get_user_inbox_page_after_logout(app, client, auth): auth.logout() response = client.get(page_id) assert response.status_code == 403 + + +def test_get_user_inbox_page_latest(app, client, auth): + with app.app_context(): + target_url = url_for( + "users.get_user_inbox_page", username="test", page_index="latest" + ) + auth.login() + response = client.get(target_url) + assert response.status_code == 200 + assert response.is_json + + +# Still TODO server verification, though that will mostly be checked through from_trusted_server tests + + +@pytest.mark.parametrize( + ("payload", "expected_status_code", "expected_inbox_size_increase"), + (('{"id": "dummy_id"}', 200, 1), ("", 400, 0),), +) +def test_post_user_inbox_item( + app, client, auth, payload, expected_status_code, expected_inbox_size_increase +): + db = None + + with app.app_context(): + db = get_db() + + with client: + auth.login() + + old_inbox_size = db.execute( + "select inbox_size from users where username=?;", ("test",) + ).fetchone()["inbox_size"] + inbox_id = url_for("users.post_user_inbox_item", username="test") + response = client.post( + inbox_id, data=payload, headers={"Content-Type": "application/ld+json"} + ) + new_inbox_size = db.execute( + "select inbox_size from users where username=?;", ("test",) + ).fetchone()["inbox_size"] + + assert response.status_code == expected_status_code + assert new_inbox_size - old_inbox_size == expected_inbox_size_increase |
