|  | @@ -0,0 +1,169 @@
 | 
	
		
			
			|  | 1 | +from collections import defaultdict
 | 
	
		
			
			|  | 2 | +import mock
 | 
	
		
			
			|  | 3 | +from searx.engines import subtitleseeker
 | 
	
		
			
			|  | 4 | +from searx.testing import SearxTestCase
 | 
	
		
			
			|  | 5 | +
 | 
	
		
			
			|  | 6 | +
 | 
	
		
			
			|  | 7 | +class TestSubtitleseekerEngine(SearxTestCase):
 | 
	
		
			
			|  | 8 | +
 | 
	
		
			
			|  | 9 | +    def test_request(self):
 | 
	
		
			
			|  | 10 | +        query = 'test_query'
 | 
	
		
			
			|  | 11 | +        dicto = defaultdict(dict)
 | 
	
		
			
			|  | 12 | +        dicto['pageno'] = 1
 | 
	
		
			
			|  | 13 | +        params = subtitleseeker.request(query, dicto)
 | 
	
		
			
			|  | 14 | +        self.assertTrue('url' in params)
 | 
	
		
			
			|  | 15 | +        self.assertTrue(query in params['url'])
 | 
	
		
			
			|  | 16 | +        self.assertTrue('subtitleseeker.com' in params['url'])
 | 
	
		
			
			|  | 17 | +
 | 
	
		
			
			|  | 18 | +    def test_response(self):
 | 
	
		
			
			|  | 19 | +        dicto = defaultdict(dict)
 | 
	
		
			
			|  | 20 | +        dicto['language'] = 'fr_FR'
 | 
	
		
			
			|  | 21 | +        response = mock.Mock(search_params=dicto)
 | 
	
		
			
			|  | 22 | +
 | 
	
		
			
			|  | 23 | +        self.assertRaises(AttributeError, subtitleseeker.response, None)
 | 
	
		
			
			|  | 24 | +        self.assertRaises(AttributeError, subtitleseeker.response, [])
 | 
	
		
			
			|  | 25 | +        self.assertRaises(AttributeError, subtitleseeker.response, '')
 | 
	
		
			
			|  | 26 | +        self.assertRaises(AttributeError, subtitleseeker.response, '[]')
 | 
	
		
			
			|  | 27 | +
 | 
	
		
			
			|  | 28 | +        response = mock.Mock(text='<html></html>', search_params=dicto)
 | 
	
		
			
			|  | 29 | +        self.assertEqual(subtitleseeker.response(response), [])
 | 
	
		
			
			|  | 30 | +
 | 
	
		
			
			|  | 31 | +        html = """
 | 
	
		
			
			|  | 32 | +        <div class="boxRows">
 | 
	
		
			
			|  | 33 | +            <div class="boxRowsInner" style="width:600px;">
 | 
	
		
			
			|  | 34 | +                <img src="http://static.subtitleseeker.com/images/movie.gif"
 | 
	
		
			
			|  | 35 | +                    style="width:16px; height:16px;" class="icon">
 | 
	
		
			
			|  | 36 | +                <a href="http://this.is.the.url/"
 | 
	
		
			
			|  | 37 | +                    class="blue" title="Title subtitle" >
 | 
	
		
			
			|  | 38 | +                    This is the Title
 | 
	
		
			
			|  | 39 | +                </a>
 | 
	
		
			
			|  | 40 | +                <br><br>
 | 
	
		
			
			|  | 41 | +                <span class="f10b grey-dark arial" style="padding:0px 0px 5px 20px">
 | 
	
		
			
			|  | 42 | +                    "Alternative Title"
 | 
	
		
			
			|  | 43 | +                </span>
 | 
	
		
			
			|  | 44 | +            </div>
 | 
	
		
			
			|  | 45 | +            <div class="boxRowsInner f12b red" style="width:70px;">
 | 
	
		
			
			|  | 46 | +                1998
 | 
	
		
			
			|  | 47 | +            </div>
 | 
	
		
			
			|  | 48 | +            <div class="boxRowsInner grey-web f12" style="width:120px;">
 | 
	
		
			
			|  | 49 | +                <img src="http://static.subtitleseeker.com/images/basket_put.png"
 | 
	
		
			
			|  | 50 | +                    style="width:16px; height:16px;" class="icon">
 | 
	
		
			
			|  | 51 | +                1039 Subs
 | 
	
		
			
			|  | 52 | +            </div>
 | 
	
		
			
			|  | 53 | +            <div class="boxRowsInner grey-web f10" style="width:130px;">
 | 
	
		
			
			|  | 54 | +                <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
 | 
	
		
			
			|  | 55 | +                    style="width:16px; height:16px;" class="icon">
 | 
	
		
			
			|  | 56 | +                1 hours ago
 | 
	
		
			
			|  | 57 | +            </div>
 | 
	
		
			
			|  | 58 | +            <div class="clear"></div>
 | 
	
		
			
			|  | 59 | +        </div>
 | 
	
		
			
			|  | 60 | +        """
 | 
	
		
			
			|  | 61 | +        response = mock.Mock(text=html, search_params=dicto)
 | 
	
		
			
			|  | 62 | +        results = subtitleseeker.response(response)
 | 
	
		
			
			|  | 63 | +        self.assertEqual(type(results), list)
 | 
	
		
			
			|  | 64 | +        self.assertEqual(len(results), 1)
 | 
	
		
			
			|  | 65 | +        self.assertEqual(results[0]['title'], 'This is the Title')
 | 
	
		
			
			|  | 66 | +        self.assertEqual(results[0]['url'], 'http://this.is.the.url/French/')
 | 
	
		
			
			|  | 67 | +        self.assertIn('1998', results[0]['content'])
 | 
	
		
			
			|  | 68 | +        self.assertIn('1039 Subs', results[0]['content'])
 | 
	
		
			
			|  | 69 | +        self.assertIn('Alternative Title', results[0]['content'])
 | 
	
		
			
			|  | 70 | +
 | 
	
		
			
			|  | 71 | +        html = """
 | 
	
		
			
			|  | 72 | +        <div class="boxRows">
 | 
	
		
			
			|  | 73 | +            <div class="boxRowsInner" style="width:600px;">
 | 
	
		
			
			|  | 74 | +                <img src="http://static.subtitleseeker.com/images/movie.gif"
 | 
	
		
			
			|  | 75 | +                    style="width:16px; height:16px;" class="icon">
 | 
	
		
			
			|  | 76 | +                <a href="http://this.is.the.url/"
 | 
	
		
			
			|  | 77 | +                    class="blue" title="Title subtitle" >
 | 
	
		
			
			|  | 78 | +                    This is the Title
 | 
	
		
			
			|  | 79 | +                </a>
 | 
	
		
			
			|  | 80 | +            </div>
 | 
	
		
			
			|  | 81 | +            <div class="boxRowsInner f12b red" style="width:70px;">
 | 
	
		
			
			|  | 82 | +                1998
 | 
	
		
			
			|  | 83 | +            </div>
 | 
	
		
			
			|  | 84 | +            <div class="boxRowsInner grey-web f12" style="width:120px;">
 | 
	
		
			
			|  | 85 | +                <img src="http://static.subtitleseeker.com/images/basket_put.png"
 | 
	
		
			
			|  | 86 | +                    style="width:16px; height:16px;" class="icon">
 | 
	
		
			
			|  | 87 | +                1039 Subs
 | 
	
		
			
			|  | 88 | +            </div>
 | 
	
		
			
			|  | 89 | +            <div class="boxRowsInner grey-web f10" style="width:130px;">
 | 
	
		
			
			|  | 90 | +                <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
 | 
	
		
			
			|  | 91 | +                    style="width:16px; height:16px;" class="icon">
 | 
	
		
			
			|  | 92 | +                1 hours ago
 | 
	
		
			
			|  | 93 | +            </div>
 | 
	
		
			
			|  | 94 | +            <div class="clear"></div>
 | 
	
		
			
			|  | 95 | +        </div>
 | 
	
		
			
			|  | 96 | +        """
 | 
	
		
			
			|  | 97 | +        dicto['language'] = 'all'
 | 
	
		
			
			|  | 98 | +        response = mock.Mock(text=html, search_params=dicto)
 | 
	
		
			
			|  | 99 | +        results = subtitleseeker.response(response)
 | 
	
		
			
			|  | 100 | +        self.assertEqual(type(results), list)
 | 
	
		
			
			|  | 101 | +        self.assertEqual(len(results), 1)
 | 
	
		
			
			|  | 102 | +        self.assertEqual(results[0]['title'], 'This is the Title')
 | 
	
		
			
			|  | 103 | +        self.assertEqual(results[0]['url'], 'http://this.is.the.url/')
 | 
	
		
			
			|  | 104 | +        self.assertIn('1998', results[0]['content'])
 | 
	
		
			
			|  | 105 | +        self.assertIn('1039 Subs', results[0]['content'])
 | 
	
		
			
			|  | 106 | +
 | 
	
		
			
			|  | 107 | +        html = """
 | 
	
		
			
			|  | 108 | +        <div class="boxRows">
 | 
	
		
			
			|  | 109 | +            <div class="boxRowsInner" style="width:600px;">
 | 
	
		
			
			|  | 110 | +                <img src="http://static.subtitleseeker.com/images/movie.gif"
 | 
	
		
			
			|  | 111 | +                    style="width:16px; height:16px;" class="icon">
 | 
	
		
			
			|  | 112 | +                <a href="http://this.is.the.url/"
 | 
	
		
			
			|  | 113 | +                    class="blue" title="Title subtitle" >
 | 
	
		
			
			|  | 114 | +                    This is the Title
 | 
	
		
			
			|  | 115 | +                </a>
 | 
	
		
			
			|  | 116 | +            </div>
 | 
	
		
			
			|  | 117 | +            <div class="boxRowsInner f12b red" style="width:70px;">
 | 
	
		
			
			|  | 118 | +                1998
 | 
	
		
			
			|  | 119 | +            </div>
 | 
	
		
			
			|  | 120 | +            <div class="boxRowsInner grey-web f12" style="width:120px;">
 | 
	
		
			
			|  | 121 | +                <img src="http://static.subtitleseeker.com/images/basket_put.png"
 | 
	
		
			
			|  | 122 | +                    style="width:16px; height:16px;" class="icon">
 | 
	
		
			
			|  | 123 | +                1039 Subs
 | 
	
		
			
			|  | 124 | +            </div>
 | 
	
		
			
			|  | 125 | +            <div class="boxRowsInner grey-web f10" style="width:130px;">
 | 
	
		
			
			|  | 126 | +                <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
 | 
	
		
			
			|  | 127 | +                    style="width:16px; height:16px;" class="icon">
 | 
	
		
			
			|  | 128 | +                1 hours ago
 | 
	
		
			
			|  | 129 | +            </div>
 | 
	
		
			
			|  | 130 | +            <div class="clear"></div>
 | 
	
		
			
			|  | 131 | +        </div>
 | 
	
		
			
			|  | 132 | +        """
 | 
	
		
			
			|  | 133 | +        subtitleseeker.language = 'English'
 | 
	
		
			
			|  | 134 | +        response = mock.Mock(text=html, search_params=dicto)
 | 
	
		
			
			|  | 135 | +        results = subtitleseeker.response(response)
 | 
	
		
			
			|  | 136 | +        self.assertEqual(type(results), list)
 | 
	
		
			
			|  | 137 | +        self.assertEqual(len(results), 1)
 | 
	
		
			
			|  | 138 | +        self.assertEqual(results[0]['title'], 'This is the Title')
 | 
	
		
			
			|  | 139 | +        self.assertEqual(results[0]['url'], 'http://this.is.the.url/English/')
 | 
	
		
			
			|  | 140 | +        self.assertIn('1998', results[0]['content'])
 | 
	
		
			
			|  | 141 | +        self.assertIn('1039 Subs', results[0]['content'])
 | 
	
		
			
			|  | 142 | +
 | 
	
		
			
			|  | 143 | +        html = """
 | 
	
		
			
			|  | 144 | +        <div class="boxRowsInner" style="width:600px;">
 | 
	
		
			
			|  | 145 | +            <img src="http://static.subtitleseeker.com/images/movie.gif"
 | 
	
		
			
			|  | 146 | +                style="width:16px; height:16px;" class="icon">
 | 
	
		
			
			|  | 147 | +            <a href="http://this.is.the.url/"
 | 
	
		
			
			|  | 148 | +                class="blue" title="Title subtitle" >
 | 
	
		
			
			|  | 149 | +                This is the Title
 | 
	
		
			
			|  | 150 | +            </a>
 | 
	
		
			
			|  | 151 | +        </div>
 | 
	
		
			
			|  | 152 | +        <div class="boxRowsInner f12b red" style="width:70px;">
 | 
	
		
			
			|  | 153 | +            1998
 | 
	
		
			
			|  | 154 | +        </div>
 | 
	
		
			
			|  | 155 | +        <div class="boxRowsInner grey-web f12" style="width:120px;">
 | 
	
		
			
			|  | 156 | +            <img src="http://static.subtitleseeker.com/images/basket_put.png"
 | 
	
		
			
			|  | 157 | +                style="width:16px; height:16px;" class="icon">
 | 
	
		
			
			|  | 158 | +            1039 Subs
 | 
	
		
			
			|  | 159 | +        </div>
 | 
	
		
			
			|  | 160 | +        <div class="boxRowsInner grey-web f10" style="width:130px;">
 | 
	
		
			
			|  | 161 | +            <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
 | 
	
		
			
			|  | 162 | +                style="width:16px; height:16px;" class="icon">
 | 
	
		
			
			|  | 163 | +            1 hours ago
 | 
	
		
			
			|  | 164 | +        </div>
 | 
	
		
			
			|  | 165 | +        """
 | 
	
		
			
			|  | 166 | +        response = mock.Mock(text=html, search_params=dicto)
 | 
	
		
			
			|  | 167 | +        results = subtitleseeker.response(response)
 | 
	
		
			
			|  | 168 | +        self.assertEqual(type(results), list)
 | 
	
		
			
			|  | 169 | +        self.assertEqual(len(results), 0)
 |