Beispiel #1
0
 def test_json_results(self):
     import json
     from webcompare import Walker
     from webcompare import ErrorResult, BadOriginResult, BadTargetResult, GoodResult
     walker = Walker("origin", "target")
     walker.results.extend([ErrorResult("e1", 0),
                            BadOriginResult("bo1", 0), BadOriginResult("bo2", 0),
                            BadTargetResult("bt1", 0), BadTargetResult("bt2", 0),
                            GoodResult("g1", 0), GoodResult("g2", 0),
                            ])
     results = json.loads(walker.json_results())
     stats = results['results']['stats']
     self.assertEquals(stats['ErrorResult'], 1)
     self.assertEquals(stats['BadOriginResult'], 2)
     self.assertEquals(stats['BadTargetResult'], 2)
     self.assertEquals(stats['GoodResult'], 2)
Beispiel #2
0
 def test_normalize_url(self):
     from webcompare import Walker
     w = Walker("ignore", "ignore", ['\\?.*', '#.*', '/RSS.*', '<bound.*'])
     self.assertEquals(w._normalize_url("http://example.com?querystring"), "http://example.com")
     self.assertEquals(w._normalize_url("http://example.com#fragment"), "http://example.com")
     self.assertEquals(w._normalize_url("http://example.com/something"), "http://example.com/something")
     self.assertEquals(w._normalize_url("http://example.com/<bound method Application.absolute_url of <Application at >>"), "http://example.com/")
     self.assertEquals(w._normalize_url("http://example.com/something/RSS"), "http://example.com/something")
Beispiel #3
0
 def setUp(self):
     from webcompare import Walker
     self.walker = Walker("http://origin.int", "http://target.int")
Beispiel #4
0
class TestWebCompare(unittest.TestCase):

    def setUp(self):
        from webcompare import Walker
        self.walker = Walker("http://origin.int", "http://target.int")

    def test___init__(self):
        self.assertEquals(self.walker.origin_url_base, "http://origin.int")
        self.assertEquals(self.walker.target_url_base, "http://target.int")
        self.assertEquals(self.walker.target_url_parts.scheme, "http")

    def test_walker_texas_ranger(self):
        self.assert_("wannabe military type" in self.walker._texas_ranger())

    def test_fetch_url_content(self):
        response = self.walker._fetch_url("http://google.com")
        self.assert_("Feeling Lucky" in response.content)

    def test__get_target_url_abs(self):
        turl = self.walker._get_target_url("http://origin.int/foo/bar/stuff.png")
        self.assertEquals(turl, "http://target.int/foo/bar/stuff.png")

    def test__get_target_url_fragment(self):
        turl = self.walker._get_target_url("http://origin.int/centers/hq/home/#maincontent")
        self.assertEquals(turl, "http://target.int/centers/hq/home/#maincontent")
        turl = self.walker._get_target_url("http://origin.int/centers/hq/home/index.html#maincontent")
        self.assertEquals(turl, "http://target.int/centers/hq/home/index.html#maincontent")


    def test__get_target_url_rel(self):
        self.assertRaises(ValueError, self.walker._get_target_url, "/foo/bar/stuff.png")

    def test__is_within_origin(self):
        self.assertTrue(self.walker._is_within_origin("http://origin.int/some/where"))


    def test__get_urls_abs(self):
        urls = self.walker._get_urls('<body><a href="http://example.com/foo">foo</a></body>',
                                     base_href="IGNORED")
        urllist = list(urls)
        self.assertEquals(len(urllist), 1)
        self.assertEquals(urllist[0][2], "http://example.com/foo")

    def test__get_urls_based(self):
        urls = self.walker._get_urls('<body><a href="/bar">bar</a></body>',
                                     base_href="http://example.com")
        urllist = list(urls)
        self.assertEquals(len(urllist), 1)
        self.assertEquals(urllist[0][2], "http://example.com/bar")

    def test_add_comparator(self):
        def bogus_comparator(self):
            pass
        self.walker.add_comparator(bogus_comparator)
        self.assertEquals(self.walker.comparators[-1], bogus_comparator)

    def test_count_html_errors(self):
        self.assertEquals(len(self.walker.count_html_errors("")), 1)
        self.assertEquals(len(self.walker.count_html_errors("<html></html>")), 3)
        self.assertEquals(len(self.walker.count_html_errors("<html><head><title BROKEN><body><p>Missing P</html>")), 3)