def makeup(self): handler = ThumbnailHandler(self.url) file_name, name = handler.create_thumbnail() self.img = file_name self.name = name return self
def test_sub_domain_return_title_and_thumbnail(self): url = 'https://www.google.com/search?' + \ 'source=hp&ei=RT3VXIXyJfSMr7wPjI6M6Ac&q=' + \ 'urlparse&oq=urlp&gs_l=psy-ab.1.1.0l5j0i10j0l4.2477.3781..5473...2.0..0.87.451.6......0....1..gws-wiz.....0.FWwWVpuif-g' t = ThumbnailHandler(url) result = t.create_thumbnail() self.assertIsNotNone(result[1]) self.assertIsNotNone(result[0])
def test_return_favicon_image(self, mock_requests): mock_res = mock.patch('requests.Response') mock_res.status_code = 200 mock_res.text = """ <html> <head> <link rel="icon" href="/test.com"/> <title> testTItle </title> </head> <body> </body> </html> """ mock_requests.get.return_value = mock_res t = ThumbnailHandler('http://test.test') result = t.create_thumbnail() self.assertEqual('testTItle', result[1].strip()) self.assertEqual('http://test.test/test.com', result[0].strip())
def test_return_og_image(self, mock_requests): mock_res = mock.patch('requests.Response') mock_res.status_code = 200 mock_res.text = """ <html> <head> <meta property="og:image" content="testmeta"/> <title> testTItle </title> </head> <body> </body> </html> """ mock_requests.get.return_value = mock_res t = ThumbnailHandler('http://test.test') result = t.create_thumbnail() self.assertEqual('testTItle', result[1].strip()) self.assertEqual('https://testmeta', result[0].strip())
def test_reuturn_none_thumbnail_name(self, mock_requests): mock_res = mock.patch('requests.Response') mock_res.status_code = 200 mock_res.text = """ <html> <head> <meta charset="utf8" content="testmeta"/> <title> testTItle </title> </head> <body> </body> </html> """ mock_requests.get.return_value = mock_res t = ThumbnailHandler('test.test') result = t.create_thumbnail() self.assertEqual('testTItle', result[1].strip()) self.assertIsNone(result[0])
def test_return_title_thumbnail_path(self): t = ThumbnailHandler('https://google.com') result = t.create_thumbnail() self.assertIsNotNone(result[1]) self.assertIsNotNone(result[0])