def setUp(self): self.parser = PageProcessor() self.parser._theme = ['lorem', 'ipsum'] self.parser._my_data.base_url = "http://www.test.fr"
class PageProcessor_test(unittest.TestCase): def setUp(self): self.parser = PageProcessor() self.parser._theme = ['lorem', 'ipsum'] self.parser._my_data.base_url = "http://www.test.fr" def test_keyword(self): test_page = '<html><head><meta name="keywords" content="test, bla,\ python" /></head></html>' keywords = self.parser._parse('http://localhost', test_page)['keywords'] self.assertEqual(keywords, ['test', 'bla', 'python']) def test_none_keyword(self): test_page = '<html><head><meta name="keywords"\ content="None" /></head></html>' keywords = self.parser._parse('http://localhost', test_page)['keywords'] self.assertEqual(keywords, []) def test_link(self): test_page = u'<html><head><title>Test</title></head><body>\ <a href="/local" /></body></html>' links = self.parser._parse('http://localhost', test_page)['links'] self.assertEqual(links, ['/local']) def test_calculate_score(self): test_page = '<html><body><p>Lorem Ipsum</p></body></html>' self.parser._parse('http://localhost', test_page) self.assertEqual(self.parser.calculate_score(test_page),1) def test_calculate_score2(self): test_page = '<html><body><p>Georges Brassens</p></body></html>' self.parser._parse('http://localhost', test_page) self.assertEqual(self.parser.calculate_score(test_page),0) def test_data(self): test_page = '<html><body><p>Georges Brassens</p></body></html>' text_content = \ self.parser._parse('http://localhost', test_page)['text_content'] self.assertEqual(text_content, 'Georges Brassens') def test_anchor(self): test_page = u'<html><head><title>Test</title></head><body>\ <a href="/local">Bouh</a></body></html>' link, anchor = self.parser._parse('http://localhost', test_page)['anchors'][0] self.assertEqual(anchor, 'bouh') def test_script(self): test_page = u'<html><head><title>Test</title></head><body>\ <script>LFDKNG</script><a href="/local">Bouh</a></body></html>' link, anchor = self.parser._parse('http://localhost', test_page)['anchors'][0] self.assertEqual(anchor, 'bouh')