diff options
| author | Tom Harley | 2021-07-10 21:41:09 +0000 |
|---|---|---|
| committer | Tom Harley | 2021-07-11 14:23:35 +0000 |
| commit | c4e848c21c028ca7c52846ea1abd7f3a38aff7d6 (patch) | |
| tree | fb886b06dcdd4d9ae4cc54ee9ea9f481ec124166 /tests/test_users.py | |
| parent | Add basic inbox/outbox functionality (diff) | |
| download | swap-master.tar.gz swap-master.zip | |
Still not even total coverage!
Need to:
- write more tests for outbox manipulation
- look into and implement receiving content from other servers (+ write tests)
off the top of my head.
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 |
