-
-
Notifications
You must be signed in to change notification settings - Fork 454
/
test_live.py
277 lines (235 loc) · 10.3 KB
/
test_live.py
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
"""Test praw.models.LiveThread"""
from unittest import mock
import pytest
from praw.const import API_PATH
from praw.exceptions import RedditAPIException
from praw.models import LiveThread, LiveUpdate, Redditor, RedditorList, Submission
from ... import IntegrationTest
class TestLiveUpdate(IntegrationTest):
def test_attributes(self):
update = LiveUpdate(
self.reddit, "ukaeu1ik4sw5", "7827987a-c998-11e4-a0b9-22000b6a88d2"
)
with self.use_cassette():
assert isinstance(update.author, Redditor)
assert update.author == "umbrae"
assert update.name == "LiveUpdate_7827987a-c998-11e4-a0b9-22000b6a88d2"
assert update.body.startswith("Small change")
class TestLiveThread(IntegrationTest):
def test_contributor(self):
thread = LiveThread(self.reddit, "ukaeu1ik4sw5")
with self.use_cassette():
contributors = thread.contributor()
assert isinstance(contributors, RedditorList)
assert len(contributors) > 0
for contributor in contributors:
assert "permissions" in contributor.__dict__
assert isinstance(contributor, Redditor)
@mock.patch("time.sleep", return_value=None)
def test_contributor__with_manage_permission(self, _):
# see issue #710 for more info
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
url = API_PATH["live_contributors"].format(id=thread.id)
with self.use_cassette():
data = thread._reddit.request(method="GET", path=url)
contributors = thread.contributor()
assert isinstance(data, list)
assert isinstance(contributors, RedditorList)
assert len(contributors) > 0
def test_init(self):
thread = LiveThread(self.reddit, "ukaeu1ik4sw5")
with self.use_cassette():
assert thread.title == "reddit updates"
def test_discussions(self):
thread = LiveThread(self.reddit, "ukaeu1ik4sw5")
with self.use_cassette():
for submission in thread.discussions(limit=None):
assert isinstance(submission, Submission)
assert submission.title == "reddit updates"
def test_report(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "ydwwxneu7vsa")
with self.use_cassette():
thread.report("spam")
@mock.patch("time.sleep", return_value=None)
def test_updates(self, _):
thread = LiveThread(self.reddit, "ukaeu1ik4sw5")
with self.use_cassette():
for update in thread.updates(limit=None):
assert update.thread == thread
assert update.body.startswith("Small change:")
class TestLiveThreadStream(IntegrationTest):
@property
def live_thread(self):
return self.reddit.live("ta535s1hq2je")
@mock.patch("time.sleep", return_value=None)
def test_updates(self, _):
with self.use_cassette():
generator = self.live_thread.stream.updates()
for i in range(101):
assert isinstance(next(generator), LiveUpdate)
class TestLiveContributorRelationship(IntegrationTest):
def test_accept_invite(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
with self.use_cassette():
thread.contributor.accept_invite()
@mock.patch("time.sleep", return_value=None)
def test_invite__already_invited(self, _):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
with self.use_cassette():
thread.contributor.invite("nmtake")
with pytest.raises(RedditAPIException) as excinfo:
thread.contributor.invite("nmtake")
assert excinfo.value.items[0].error_type == "LIVEUPDATE_ALREADY_CONTRIBUTOR"
def test_invite__empty_list(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
with self.use_cassette():
thread.contributor.invite("nmtake", permissions=[])
def test_invite__limited(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
with self.use_cassette():
thread.contributor.invite("nmtake", permissions=["manage", "edit"])
def test_invite__none(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
with self.use_cassette():
thread.contributor.invite("nmtake", permissions=None)
def test_invite__redditor(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
redditor = Redditor(self.reddit, _data={"name": "nmtake", "id": "ll32z"})
with self.use_cassette():
thread.contributor.invite(redditor)
def test_leave(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
with self.use_cassette():
thread.contributor.leave()
def test_remove__fullname(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
with self.use_cassette():
thread.contributor.remove("t2_ll32z")
def test_remove__redditor(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
redditor = Redditor(self.reddit, _data={"name": "nmtake", "id": "ll32z"})
with self.use_cassette():
thread.contributor.remove(redditor)
def test_remove_invite__fullname(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
with self.use_cassette():
thread.contributor.remove_invite("t2_ll32z")
def test_remove_invite__redditor(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
redditor = Redditor(self.reddit, _data={"name": "nmtake", "id": "ll32z"})
with self.use_cassette():
thread.contributor.remove_invite(redditor)
def test_update__empty_list(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "ydwwxneu7vsa")
with self.use_cassette():
thread.contributor.update("nmtake", permissions=[])
def test_update__limited(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "ydwwxneu7vsa")
with self.use_cassette():
thread.contributor.update("nmtake", permissions=["manage", "edit"])
def test_update__none(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "ydwwxneu7vsa")
with self.use_cassette():
thread.contributor.update("nmtake", permissions=None)
def test_update_invite__empty_list(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "ydwwxneu7vsa")
with self.use_cassette():
thread.contributor.update_invite("nmtake", [])
def test_update_invite__limited(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "ydwwxneu7vsa")
with self.use_cassette():
thread.contributor.update_invite("nmtake", ["manage", "edit"])
def test_update_invite__none(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "ydwwxneu7vsa")
with self.use_cassette():
thread.contributor.update_invite("nmtake", None)
class TestLiveThreadContribution(IntegrationTest):
def test_add(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
with self.use_cassette():
thread.contrib.add("* `LiveThreadContribution.add() test`")
def test_close(self):
self.reddit.read_only = False
thread = LiveThread(self.reddit, "ya2tmqiyb064")
with self.use_cassette():
thread.contrib.close()
@mock.patch("time.sleep", return_value=None)
def test_update__partial_settings(self, _):
old_settings = {
"title": "old title",
"description": "## old description",
"nsfw": False,
"resources": "## old resources",
}
new_settings = {"title": "new title", "nsfw": True}
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
with self.use_cassette():
thread.contrib.update(**new_settings)
assert thread.title == new_settings["title"]
assert thread.description == old_settings["description"]
assert thread.nsfw == new_settings["nsfw"]
assert thread.resources == old_settings["resources"]
@mock.patch("time.sleep", return_value=None)
def test_update__full_settings(self, _):
new_settings = {
"title": "new title 2",
"description": "## new description 2",
"nsfw": True,
"resources": "## new resources 2",
}
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
with self.use_cassette():
thread.contrib.update(**new_settings)
assert thread.title == new_settings["title"]
assert thread.description == new_settings["description"]
assert thread.nsfw == new_settings["nsfw"]
assert thread.resources == new_settings["resources"]
@mock.patch("time.sleep", return_value=None)
def test_update__other_settings(self, _):
new_settings = {
"title": "new title",
"other1": "other 1",
"other2": "other 2",
}
self.reddit.read_only = False
thread = LiveThread(self.reddit, "xyu8kmjvfrww")
with self.use_cassette():
thread.contrib.update(**new_settings)
class TestLiveUpdateContribution(IntegrationTest):
@mock.patch("time.sleep", return_value=None)
def test_remove(self, _):
self.reddit.read_only = False
update = LiveUpdate(
self.reddit, "xyu8kmjvfrww", "5d556760-dbee-11e6-9f46-0e78de675452"
)
with self.use_cassette():
update.contrib.remove()
def test_strike(self):
self.reddit.read_only = False
update = LiveUpdate(
self.reddit, "xyu8kmjvfrww", "cb5fe532-dbee-11e6-9a91-0e6d74fabcc4"
)
with self.use_cassette():
update.contrib.strike()