1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
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
|