-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
177 lines (152 loc) · 4.26 KB
/
tests.py
File metadata and controls
177 lines (152 loc) · 4.26 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import requests
import sqlite3
import json
import os
import time
# A server runs on 8080 using spile.db with and admin account
base = "http://localhost:8080"
# We make the admin account
admin_auth_token = requests.post(
base + "/create_user",
headers={"auth_token": "zaza"},
json={"email": "admin@test.com", "is_admin": True},
).json()["auth_token"]
## And create two users
user1_email = "user1@test.com"
user2_email = "user2@test.com"
user1_auth = requests.post(
base + "/create_user",
headers={"auth_token": admin_auth_token},
json={"email": user1_email, "is_admin": False},
).json()["auth_token"]
user2_auth = requests.post(
base + "/create_user",
headers={"auth_token": admin_auth_token},
json={"email": user2_email, "is_admin": True},
).json()["auth_token"]
print(user1_auth, user2_auth)
# Both users should have no items
for auth_token in [user1_auth, user2_auth]:
items = requests.get(
base + "/get_items", headers={"auth_token": auth_token}
).json()["items"]
assert len(items) == 0
# Artificially add items
for auth, email in [(user1_auth, user1_email), (user2_auth, user2_email)]:
res = requests.post(
base + "/add_item",
headers={"auth_token": auth},
json={
"title": f"Hello from {email}",
"content": "This is a long string of text",
"link": f"Link.de/subscriber_email={email}",
"type": "read",
},
)
# Now both users should get 1 item
for auth_token in [user1_auth, user2_auth]:
items = requests.get(
base + "/get_items", headers={"auth_token": auth_token}
).json()["items"]
assert len(items) == 1
# Now subscribe them to each other
resp = requests.post(
base + "/add_source",
headers={"auth_token": user1_auth},
json={"source": base + f"/get_feed/{user2_email}"},
)
assert resp.status_code == 200
resp = requests.post(
base + "/add_source",
headers={"auth_token": user2_auth},
json={"source": base + f"/get_feed/{user1_email}"},
)
assert resp.status_code == 200
time.sleep(1.5)
# They should still have 1 item each
for auth_token in [user1_auth, user2_auth]:
items = requests.get(
base + "/get_items", headers={"auth_token": auth_token}
).json()["items"]
assert len(items) == 1
# user1 reads and rates an item
res = requests.get(
base + "/get_items",
headers={"auth_token": user1_auth},
)
assert res.status_code == 200
read_item = res.json()["items"][0]
res = requests.post(
base + "/add_item",
headers={"auth_token": user1_auth},
json={
"content": "95",
"link": read_item["uid"],
"type": "resonance",
},
)
time.sleep(3)
items = requests.get(base + "/get_items", headers={"auth_token": user2_auth}).json()[
"items"
]
assert len(items) == 2
# User 2 reads and rates, it has low resonance
res = requests.get(
base + "/get_items",
headers={"auth_token": user2_auth},
)
assert res.status_code == 200
read_item = res.json()["items"][0]
res = requests.post(
base + "/add_item",
headers={"auth_token": user2_auth},
json={
"content": "10",
"link": read_item["uid"],
"type": "resonance",
},
)
time.sleep(1.5)
items = requests.get(base + "/get_items", headers={"auth_token": user1_auth}).json()[
"items"
]
assert len(items) == 1
# Test Item Archive and Order
items = requests.get(base + "/get_items", headers={"auth_token": user2_auth}).json()[
"items"
]
resp = requests.post(
base + "/archive",
headers={"auth_token": user2_auth},
json={
"uid": items[0]["uid"],
"archived": True,
},
)
assert resp.status_code == 200
items = requests.get(base + "/get_items", headers={"auth_token": user2_auth}).json()[
"items"
]
assert len(items) == 1
resp = requests.post(
base + "/done",
headers={"auth_token": user2_auth},
json={
"uid": items[0]["uid"],
"done": True,
},
)
assert resp.status_code == 200
# Subscribe user1 to nintil's RSS
resp = requests.post(
base + "/add_source",
headers={"auth_token": user1_auth},
json={"source": "https://nintil.com/rss.xml"},
)
time.sleep(15)
items = requests.get(base + "/get_items", headers={"auth_token": user1_auth}).json()[
"items"
]
print(len(items))
assert 400 > len(items) > 5
print("All tests passed")