-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtests.py
298 lines (209 loc) · 9.03 KB
/
tests.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
import imp
import os
import shutil
import sys
import unittest
import mock
import simplemedia
import simpleplugin
import xbmc
import xbmcaddon
cwd = os.path.dirname(os.path.abspath(__file__))
addon_name = 'plugin.video.filmix'
temp_dir = os.path.join(cwd, 'addon_data')
if not os.path.exists(temp_dir):
os.mkdir(temp_dir)
sm_dir = simplemedia.where()
sm_config_dir = os.path.join(temp_dir, 'script.module.simplemedia')
xbmcaddon.init_addon(sm_dir, sm_config_dir)
addon_dir = os.path.join(cwd, addon_name)
addon_config_dir = os.path.join(temp_dir, addon_name)
xbmcaddon.init_addon(addon_dir, addon_config_dir, True)
# Import our module being tested
sys.path.append(addon_dir)
def run_script():
imp.load_source('__main__', os.path.join(addon_dir, 'default.py'))
def setUpModule():
# prepare search history
addon = simpleplugin.Addon()
with addon.get_storage('__history__.pcl') as storage:
history = ['Нюхач', 'Я Легенда', 'Supernatural', 'Смешарики', 'Deadpool', 'Маша и медведь',
'Домики', 'Мстители', 'Stranger Things', 'Breaking Bad']
storage['history'] = history
def tearDownModule():
print('Removing temporary directory: {0}'.format(temp_dir))
shutil.rmtree(temp_dir, True)
class PluginActionsTestCase(unittest.TestCase):
def setUp(self):
print("Running test: {0}".format(self.id().split('.')[-1]))
@staticmethod
def test_00_login():
with mock.patch('simpleplugin.sys') as mock_sys:
mock_sys.argv = ['plugin://{0}/login'.format(addon_name), '0', '']
run_script()
with mock.patch('simpleplugin.sys') as mock_sys:
mock_sys.argv = ['plugin://{0}/check_device'.format(addon_name), '0', '']
addon = xbmcaddon.Addon()
user_dev_id = os.getenv('user_dev_id', None)
if user_dev_id is not None:
addon.setSetting('user_dev_id', user_dev_id)
else:
print('user_dev_id not defined')
user_dev_token = os.getenv('user_dev_token', None)
if user_dev_token is not None:
addon.setSetting('user_dev_token', user_dev_token)
else:
print('user_dev_token not defined')
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', ['plugin://{0}/'.format(addon_name), '1', ''])
def test_01_root():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', ['plugin://{0}/movies/'.format(addon_name), '2', '?page=3'])
def test_02_catalog():
run_script()
# @staticmethod
# @mock.patch('simpleplugin.sys.argv', ['plugin://{0}/movies/2896-ya-legenda-i-am-legend-2007/'.format(addon_name), '3', ''])
# def test_03_video_info_movie():
#
# run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/movies/2896-ya-legenda-i-am-legend-2007/play/'.format(addon_name), '4', '?strm=1'])
def test_04_play_video_movie():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/movies/2896-ya-legenda-i-am-legend-2007/play/'.format(addon_name), '5',
'?t=%D0%94%D1%83%D0%B1%D0%BB%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%BD%D1%8B%D0%B9+%5B4%D0%9A%2C+SDR%5D'])
def test_05_play_video_movie_translation():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/serials/6379-smotret-onlajn-sverxestestvennoe-6-sezon-2010/'.format(addon_name), '6',
''])
def test_06_serial_info():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/serials/6379-smotret-onlajn-sverxestestvennoe-6-sezon-2010/episodes/'.format(addon_name),
'7', '?s=8'])
def test_07_serial_episodes():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/serials/6379-smotret-onlajn-sverxestestvennoe-6-sezon-2010/episodes/'.format(addon_name),
'8', '?s=8&t=LostFilm'])
def test_08_serial_episodes_translation():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/serials/6379-smotret-onlajn-sverxestestvennoe-6-sezon-2010/play/'.format(addon_name),
'9', '?e=18&s=8'])
def test_09_play_video_serial_episodes():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/serials/6379-smotret-onlajn-sverxestestvennoe-6-sezon-2010/play/'.format(addon_name),
'10', '?e=18&s=8&t=LostFilm'])
def test_10_play_video_serial_episodes_translation():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', ['plugin://{0}/search'.format(addon_name), '11', ''])
def test_11_search():
xbmc.Keyboard.strings.append('Смешарики')
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', ['plugin://{0}/search/history/'.format(addon_name), '12', ''])
def test_12_search_history():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', ['plugin://{0}/favorites/'.format(addon_name), '13', ''])
def test_13_favorites():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', ['plugin://{0}/watch_history/'.format(addon_name), '14', ''])
def test_14_watch_history():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', ['plugin://{0}/watch_later/'.format(addon_name), '15', ''])
def test_15_watch_history():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', ['plugin://{0}/popular/'.format(addon_name), '16', ''])
def test_16_popular():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', ['plugin://{0}/top_views/'.format(addon_name), '17', ''])
def test_17_top_views():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/dokumentalenye/14624-skorost-zhizni-2010/'.format(addon_name), '18', ''])
def test_18_serial_seasons_without_seasons():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/dokumentalenye/14624-skorost-zhizni-2010/episodes/'.format(addon_name), '19', ''])
def test_19_serial_episodes_without_seasons():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/dokumentalenye/14624-skorost-zhizni-2010/episodes/'.format(addon_name), '20',
'?t=%D0%9F%D0%BB%D0%B5%D0%B5%D1%80+1'])
def test_20_serial_episodes_without_seasons_translation():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', ['plugin://{0}/search'.format(addon_name), '21',
'?keyword=%D0%A1%D0%BC%D0%B5%D1%88%D0%B0%D1%80%D0%B8%D0%BA%D0%B8'])
def test_21_search_keyword():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/toogle_favorites'.format(addon_name), '22', '?id=14624&value=1'])
def test_22_add_favorite():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/toogle_favorites'.format(addon_name), '23', '?id=14624&value=0'])
def test_23_remove_favorite():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/toogle_watch_later'.format(addon_name), '24', '?id=14624&value=1'])
def test_24_add_watch_later():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/toogle_watch_later'.format(addon_name), '25', '?id=14624&value=0'])
def test_25_remove_watch_later():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv',
['plugin://{0}/movies/6379-smotret-onlajn-sverxestestvennoe-6-sezon-2010/trailer'.format(addon_name),
'26', ''])
def test_26_play_trailer():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', [
'plugin://{0}/serialy/70388-transformery-energon-transformer-super-link-multserial-2004/'.format(addon_name),
'27', ''])
def test_27_serial_seasons_without_seasons():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', ['plugin://{0}/search/remove/0'.format(addon_name), '28', ''])
def test_28_search_remove():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', ['plugin://{0}/search/clear'.format(addon_name), '29', ''])
def test_29_search_clear():
run_script()
@staticmethod
@mock.patch('simpleplugin.sys.argv', ['plugin://{0}/select_videoserver'.format(addon_name), '32', ''])
def test_32_select_videoserver():
run_script()
if __name__ == '__main__':
unittest.main()