Debian Codegraph @

tests/utils/test_crawl.py

raw
1 # -*- coding: utf-8 -*-
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License
13 # along with this program; if not, write to the Free Software
14 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15 # MA 02110-1301, USA.
16 #
17 # Author: Mauro Soria
18
19 from unittest import TestCase
20
21 from lib.core.settings import DUMMY_URL
22 from lib.utils.crawl import Crawler
23
24
25 class TestCrawl(TestCase):
26 def test_text_crawl(self):
27 html_doc = f'Link: {DUMMY_URL}foobar'
28 self.assertEqual(Crawler.text_crawl(DUMMY_URL, DUMMY_URL, html_doc), {"foobar"})
29
30 def test_html_crawl(self):
31 html_doc = f'<a href="{DUMMY_URL}foo">link</a><script src="/bar.js"><img src="/bar.png">'
32 self.assertEqual(Crawler.html_crawl(DUMMY_URL, DUMMY_URL, html_doc), {"foo", "bar.js"})
33
34 def test_robots_crawl(self):
35 robots_txt = """
36 User-agent: Googlebot
37 Disallow: /path1
38
39 User-agent: *
40 Allow: /path2"""
41 self.assertEqual(Crawler.robots_crawl(DUMMY_URL, DUMMY_URL, robots_txt), {"path1", "path2"})