Repository navigation
Expand file tree
/
Copy pathtest_types.py
More file actions
373 lines (349 loc) · 11.4 KB
/
Copy pathtest_types.py
File metadata and controls
373 lines (349 loc) · 11.4 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
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
import pytest
from byte_api.types import *
def test_json():
json_type_dict = {
'test': 123
}
assert JsonDeserializable.check_json(json_type_dict) == json_type_dict
json_type_str = '{"test": 123}'
assert JsonDeserializable.check_json(json_type_str) == json_type_dict
with pytest.raises(ValueError):
json_type_int = 123
JsonDeserializable.check_json(json_type_int)
def test_error():
data = {
'code': 1,
'message': 'test message'
}
error = Error.de_json(data)
assert error.code == data['code']
assert error.message == data['message']
def test_response():
data = {
'data': {'1': 2},
'error': {
'code': 1,
'message': 'test message'
},
'success': 1
}
response = Response.de_json(data)
assert response.data == data['data']
assert type(response.error) == Error
assert response.success == data['success']
def test_range():
data = {
'start': 0,
'stop': 10
}
range = Range.de_json(data)
assert range.start == data['start']
assert range.stop == data['stop']
def test_mention():
data = {
'accountID': 'TEST',
'username': 'bixnel',
'text': '@bixnel',
'range': {
'start': 61,
'stop': 75
},
'byteRange': {
'start': 67,
'stop': 81
}
}
mention = Mention.de_json(data)
assert mention.account_id == data['accountID']
assert mention.username == data['username']
assert mention.text == data['text']
assert type(mention.range) == Range
assert type(mention.byte_range) == Range
def test_account():
data = {
'backgroundColor': '#000000',
'followerCount': 0,
'followingCount': 0,
'foregroundColor': '#CCD6E9',
'id': 'test_id',
'isChannel': False,
'loopCount': 0,
'loopsConsumedCount': 0,
'registrationDate': 1580228662,
'username': 'bixnel',
'avatarURL': 'avatar/url',
'isDeactivated': False,
'isRegistered': True,
'isBlocked': False,
'bio': 'test bio',
'isFollowing': False,
'isFollowed': False,
'isSuspended': False,
'displayName': 'byte-api'
}
account = Account.de_json(data)
assert account.background_color == data['backgroundColor']
assert account.follower_count == data['followerCount']
assert account.following_count == data['followingCount']
assert account.foreground_color == data['foregroundColor']
assert account.id == data['id']
assert account.is_channel == data['isChannel']
assert account.loop_count == data['loopCount']
assert account.loops_consumed_count == data['loopsConsumedCount']
assert account.registration_date == data['registrationDate']
assert account.username == data['username']
assert account.avatar_url == data['avatarURL']
assert account.is_deactivated == data['isDeactivated']
assert account.is_registered == data['isRegistered']
assert account.is_blocked == data['isBlocked']
assert account.bio == data['bio']
assert account.is_following == data['isFollowing']
assert account.is_followed == data['isFollowed']
assert account.is_suspended == data['isSuspended']
assert account.display_name == data['displayName']
def test_comment():
data = {
'id': 'TEST_ID',
'postID': 'TEST_POST',
'authorID': 'TEST_AUTHOR',
'body': 'test test',
'mentions': [],
'date': 1580089742,
'accounts': {
'test_id': {
'avatarURL': 'avatar/url',
'backgroundColor': '#000000',
'followerCount': 0,
'followingCount': 0,
'foregroundColor': '#CCD6E9',
'id': 'test_id',
'isBlocked': False,
'isChannel': False,
'isFollowed': False,
'isFollowing': False,
'loopCount': 0,
'loopsConsumedCount': 0,
'registrationDate': 1580228662,
'username': 'bixnel'
}
}
}
comment = Comment.de_json(data)
assert comment.id == data['id']
assert comment.post_id == data['postID']
assert comment.author_id == data['authorID']
assert comment.body == data['body']
assert comment.mentions == data['mentions']
assert comment.date == data['date']
assert type(comment.accounts) == dict
assert type(comment.accounts['test_id']) == Account
def test_post():
data = {
'id': 'TEST',
'type': 0,
'authorID': 'TETS_AUTHOR',
'caption': '',
'allowCuration': True,
'allowRemix': False,
'category': 'wierd',
'mentions': [
{
'accountID': 'TEST',
'username': 'bixnel',
'text': '@bixnel',
'range': {
'start': 61,
'stop': 75
},
'byteRange': {
'start': 67,
'stop': 81
}
}
],
'date': 1580089743,
'videoSrc': 'TEST_VIDEO',
'thumbSrc': 'TEST_THUMB',
'commentCount': 0,
'comments': [
{
'id': 'TEST_ID',
'postID': 'TEST_POST',
'authorID': 'TEST_AUTHOR',
'body': 'test test',
'mentions': [],
'date': 1580089742,
'accounts': {
'test_id': {
'avatarURL': 'avatar/url',
'backgroundColor': '#000000',
'followerCount': 0,
'followingCount': 0,
'foregroundColor': '#CCD6E9',
'id': 'test_id',
'isBlocked': False,
'isChannel': False,
'isFollowed': False,
'isFollowing': False,
'loopCount': 0,
'loopsConsumedCount': 0,
'registrationDate': 1580228662,
'username': 'bixnel'
}
}
}
],
'likeCount': 0,
'likedByMe': False,
'loopCount': 0,
'rebytedByMe': False
}
post = Post.de_json(data)
assert post.id == data['id']
assert post.type == data['type']
assert post.author_id == data['authorID']
assert post.caption == data['caption']
assert post.allow_curation == data['allowCuration']
assert post.allow_remix == data['allowRemix']
assert post.category == data['category']
assert all(type(mention) == Mention for mention in post.mentions)
assert post.date == data['date']
assert post.video_src == data['videoSrc']
assert post.thumb_src == data['thumbSrc']
assert post.comment_count == data['commentCount']
assert all(type(comment) == Comment for comment in post.comments)
assert post.like_count == data['likeCount']
assert post.liked_by_me == data['likedByMe']
assert post.loop_count == data['loopCount']
assert post.rebyted_by_me == data['rebytedByMe']
def test_color():
data = {
'background': '#000000',
'foreground': '#CCD6E9',
'id': 1
}
color = Color.de_json(data)
assert color.background == data['background']
assert color.foreground == data['foreground']
assert color.id == data['id']
def test_colors():
data = {
'colors': [
{
'background': '#000000',
'foreground': '#CCD6E9',
'id': 1
},
{
"background": "#00B6B6",
"foreground": "#E2E9FF",
"id": 2
}
]
}
colors = Colors.de_json(data)
assert all(type(color) == Color for color in colors.colors)
def test_loop_counter():
data = {
'postID': 'test_id',
'loopCount': 10
}
loop_counter = LoopCounter.de_json(data)
assert loop_counter.id == data['postID']
assert loop_counter.loop_count == data['loopCount']
def test_rebyte():
data = {
'accounts': {
'test_id': {
'backgroundColor': '#000000',
'followerCount': 0,
'followingCount': 0,
'foregroundColor': '#CCD6E9',
'id': 'test_id',
'isChannel': False,
'loopCount': 0,
'loopsConsumedCount': 0,
'registrationDate': 1580228662,
'username': 'bixnel',
'avatarURL': 'avatar/url',
'isDeactivated': False,
'isRegistered': True,
'isBlocked': False,
'bio': 'test bio',
'isFollowing': False,
'isFollowed': False,
'isSuspended': False,
'displayName': 'byte-api'
}
},
'authorID': 'AUTHOR_ID',
'date': 1580228662,
'id': 'TEST_ID',
'post': {
'id': 'TEST',
'type': 0,
'authorID': 'TETS_AUTHOR',
'caption': '',
'allowCuration': True,
'allowRemix': False,
'category': 'wierd',
'mentions': [
{
'accountID': 'TEST',
'username': 'bixnel',
'text': '@bixnel',
'range': {
'start': 61,
'stop': 75
},
'byteRange': {
'start': 67,
'stop': 81
}
}
],
'date': 1580089743,
'videoSrc': 'TEST_VIDEO',
'thumbSrc': 'TEST_THUMB',
'commentCount': 0,
'comments': [
{
'id': 'TEST_ID',
'postID': 'TEST_POST',
'authorID': 'TEST_AUTHOR',
'body': 'test test',
'mentions': [],
'date': 1580089742,
'accounts': {
'test_id': {
'avatarURL': 'avatar/url',
'backgroundColor': '#000000',
'followerCount': 0,
'followingCount': 0,
'foregroundColor': '#CCD6E9',
'id': 'test_id',
'isBlocked': False,
'isChannel': False,
'isFollowed': False,
'isFollowing': False,
'loopCount': 0,
'loopsConsumedCount': 0,
'registrationDate': 1580228662,
'username': 'bixnel'
}
}
}
],
'likeCount': 0,
'likedByMe': False,
'loopCount': 0,
'rebytedByMe': False
}
}
rebyte = Rebyte.de_json(data)
assert all(type(rebyte.accounts[account]) == Account
for account in rebyte.accounts.keys())
assert rebyte.author_id == data['authorID']
assert rebyte.date == data['date']
assert rebyte.id == data['id']
assert type(rebyte.post) == Post