summaryrefslogtreecommitdiff
path: root/tests/unit/engines/test_subtitleseeker.py
blob: a22ee74b952cbb505ba70394b08d5dcfdaf10d47 (plain)
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
from collections import defaultdict
import mock
from searx.engines import subtitleseeker
from searx.testing import SearxTestCase


class TestSubtitleseekerEngine(SearxTestCase):

    def test_request(self):
        query = 'test_query'
        dicto = defaultdict(dict)
        dicto['pageno'] = 1
        dicto['language'] = 'fr-FR'
        params = subtitleseeker.request(query, dicto)
        self.assertTrue('url' in params)
        self.assertTrue(query in params['url'])
        self.assertTrue('subtitleseeker.com' in params['url'])

    def test_response(self):
        dicto = defaultdict(dict)
        dicto['language'] = 'fr-FR'
        response = mock.Mock(search_params=dicto)

        self.assertRaises(AttributeError, subtitleseeker.response, None)
        self.assertRaises(AttributeError, subtitleseeker.response, [])
        self.assertRaises(AttributeError, subtitleseeker.response, '')
        self.assertRaises(AttributeError, subtitleseeker.response, '[]')

        response = mock.Mock(text='<html></html>', search_params=dicto)
        self.assertEqual(subtitleseeker.response(response), [])

        html = """
        <div class="boxRows">
            <div class="boxRowsInner" style="width:600px;">
                <img src="http://static.subtitleseeker.com/images/movie.gif"
                    style="width:16px; height:16px;" class="icon">
                <a href="http://this.is.the.url/"
                    class="blue" title="Title subtitle" >
                    This is the Title
                </a>
                <br><br>
                <span class="f10b grey-dark arial" style="padding:0px 0px 5px 20px">
                    "Alternative Title"
                </span>
            </div>
            <div class="boxRowsInner f12b red" style="width:70px;">
                1998
            </div>
            <div class="boxRowsInner grey-web f12" style="width:120px;">
                <img src="http://static.subtitleseeker.com/images/basket_put.png"
                    style="width:16px; height:16px;" class="icon">
                1039 Subs
            </div>
            <div class="boxRowsInner grey-web f10" style="width:130px;">
                <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
                    style="width:16px; height:16px;" class="icon">
                1 hours ago
            </div>
            <div class="clear"></div>
        </div>
        """
        response = mock.Mock(text=html, search_params=dicto)
        results = subtitleseeker.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0]['title'], 'This is the Title')
        self.assertEqual(results[0]['url'], 'http://this.is.the.url/French/')
        self.assertIn('1998', results[0]['content'])
        self.assertIn('1039 Subs', results[0]['content'])
        self.assertIn('Alternative Title', results[0]['content'])

        dicto['language'] = 'pt-BR'
        results = subtitleseeker.response(response)
        self.assertEqual(results[0]['url'], 'http://this.is.the.url/Brazilian/')

        html = """
        <div class="boxRows">
            <div class="boxRowsInner" style="width:600px;">
                <img src="http://static.subtitleseeker.com/images/movie.gif"
                    style="width:16px; height:16px;" class="icon">
                <a href="http://this.is.the.url/"
                    class="blue" title="Title subtitle" >
                    This is the Title
                </a>
            </div>
            <div class="boxRowsInner f12b red" style="width:70px;">
                1998
            </div>
            <div class="boxRowsInner grey-web f12" style="width:120px;">
                <img src="http://static.subtitleseeker.com/images/basket_put.png"
                    style="width:16px; height:16px;" class="icon">
                1039 Subs
            </div>
            <div class="boxRowsInner grey-web f10" style="width:130px;">
                <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
                    style="width:16px; height:16px;" class="icon">
                1 hours ago
            </div>
            <div class="clear"></div>
        </div>
        """
        dicto['language'] = 'all'
        response = mock.Mock(text=html, search_params=dicto)
        results = subtitleseeker.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0]['title'], 'This is the Title')
        self.assertEqual(results[0]['url'], 'http://this.is.the.url/')
        self.assertIn('1998', results[0]['content'])
        self.assertIn('1039 Subs', results[0]['content'])

        html = """
        <div class="boxRows">
            <div class="boxRowsInner" style="width:600px;">
                <img src="http://static.subtitleseeker.com/images/movie.gif"
                    style="width:16px; height:16px;" class="icon">
                <a href="http://this.is.the.url/"
                    class="blue" title="Title subtitle" >
                    This is the Title
                </a>
            </div>
            <div class="boxRowsInner f12b red" style="width:70px;">
                1998
            </div>
            <div class="boxRowsInner grey-web f12" style="width:120px;">
                <img src="http://static.subtitleseeker.com/images/basket_put.png"
                    style="width:16px; height:16px;" class="icon">
                1039 Subs
            </div>
            <div class="boxRowsInner grey-web f10" style="width:130px;">
                <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
                    style="width:16px; height:16px;" class="icon">
                1 hours ago
            </div>
            <div class="clear"></div>
        </div>
        """
        subtitleseeker.language = 'English'
        response = mock.Mock(text=html, search_params=dicto)
        results = subtitleseeker.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0]['title'], 'This is the Title')
        self.assertEqual(results[0]['url'], 'http://this.is.the.url/English/')
        self.assertIn('1998', results[0]['content'])
        self.assertIn('1039 Subs', results[0]['content'])

        html = """
        <div class="boxRowsInner" style="width:600px;">
            <img src="http://static.subtitleseeker.com/images/movie.gif"
                style="width:16px; height:16px;" class="icon">
            <a href="http://this.is.the.url/"
                class="blue" title="Title subtitle" >
                This is the Title
            </a>
        </div>
        <div class="boxRowsInner f12b red" style="width:70px;">
            1998
        </div>
        <div class="boxRowsInner grey-web f12" style="width:120px;">
            <img src="http://static.subtitleseeker.com/images/basket_put.png"
                style="width:16px; height:16px;" class="icon">
            1039 Subs
        </div>
        <div class="boxRowsInner grey-web f10" style="width:130px;">
            <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
                style="width:16px; height:16px;" class="icon">
            1 hours ago
        </div>
        """
        response = mock.Mock(text=html, search_params=dicto)
        results = subtitleseeker.response(response)
        self.assertEqual(type(results), list)
        self.assertEqual(len(results), 0)