-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquery_cases.py
65 lines (51 loc) · 1.91 KB
/
query_cases.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
# coding=utf8
import json
import re
import sys
import unittest
# workaround for python2 vs python3 compatibility
if sys.version_info[0] > 2:
from urllib.request import quote
def u_code(string):
return string
else:
from urllib import quote
def u_code(string):
return string.encode('utf8')
channel = 'НТВ'
m3u_re = re.compile('#EXTM3U\n#EXTINF:-1,[0-9]+\\. ' + channel +
'.*\n.*/ace/getstream\\?infohash=[0-9a-f]+')
class TestCases(unittest.TestCase):
def probe(self, args):
'''Make actual query to the service. Redefined in child class'''
pass
def test_query(self):
args = 'query=' + quote(channel)
self.assertIsNotNone(m3u_re.match(self.probe(args)))
def test_name(self):
args = 'name=' + quote(channel)
self.assertIsNotNone(m3u_re.match(self.probe(args)))
def test_group(self):
args = 'query=' + quote(channel)
args += '&group_by_channels=1'
self.assertIsNotNone(m3u_re.match(self.probe(args)))
def test_epg(self):
args = 'query=' + quote(channel)
args += '&name=' + quote(channel)
args += '&show_epg=1'
self.assertIsNotNone(re.match('#EXTM3U\n#EXTINF:-1 tvg-id="[0-9]+",[0-9]+\\. ' + channel +
'.*\n.*/ace/getstream\\?infohash=[0-9a-f]+',
self.probe(args)))
def test_json(self):
args = 'query=' + quote(channel)
args += '&json=1'
item = json.loads(self.probe(args))[0]['items'][0]
self.assertTrue(channel in u_code(item['name']) and
re.match('[0-9a-f]+', item['infohash']))
'''
def test_xml(self):
args = 'query=' + quote(channel)
args += '&xml_epg=1'
self.assertIsNotNone(re.search(' +<channel id="[0-9]+">\\n +<display-name lang="ru">'
+ channel, self.probe(args)))
'''