import pytest from flask import url_for def test_get_user_info_existing_user(app, client): with app.app_context(): user_id = url_for("users.get_user_info", username="test") response = client.get(user_id) assert response.status_code == 200 assert response.is_json assert response.json.get("id") in user_id assert {"inbox", "outbox"} <= set(response.json) assert "password" not in response.json def test_get_user_info_unknown_user(app, client): with app.app_context(): user_id = url_for("users.get_user_info", username="unknown_user") response = client.get(user_id) assert response.status_code == 404 def test_get_user_inbox_unauthorised(app, client): with app.app_context(): user_id = url_for("users.get_user_inbox", username="test") response = client.get(user_id) assert response.status_code == 403 def test_get_user_inbox_authorised(app, client, auth): with app.app_context(): inbox_id = url_for("users.get_user_inbox", username="test") auth.login() response = client.get(inbox_id) assert response.json.get("id") in inbox_id assert response.json.get("type") == "OrderedCollection" assert "first" in response.json assert response.json.get("totalItems") == 40 def test_get_user_inbox_wrong_user(app, client, auth): with app.app_context(): inbox_id = url_for("users.get_user_inbox", username="other") auth.login() response = client.get(inbox_id) assert response.status_code == 403 def test_get_user_inbox_page_authorised(app, client, auth): with app.app_context(): inbox_id = url_for("users.get_user_inbox", username="test") auth.login() inbox = client.get(inbox_id).json page_id = inbox["first"] response = client.get(page_id) assert {"items", "id"} <= set(response.json) assert ("next" in response.json) or ( len(response.json["items"]) == inbox["totalItems"] ) def test_get_user_inbox_page_after_logout(app, client, auth): with app.app_context(): inbox_id = url_for("users.get_user_inbox", username="test") auth.login() inbox = client.get(inbox_id).json page_id = inbox["first"] auth.logout() response = client.get(page_id) assert response.status_code == 403