def test_clean_url(self): finder = URLFinder() finder.is_blacklisted = MagicMock() finder.untiny.extract = MagicMock() finder.follow_redirects = MagicMock() finder.clean_params = MagicMock() finder.is_blacklisted.return_value = True self.assertEquals( finder.clean_url("http://tiny.com"), None ) self.assertEquals(finder.is_blacklisted.call_count, 1) finder.is_blacklisted.return_value = False finder.untiny.extract.side_effect = lambda url: "http://redirect.com" if url == "http://tiny.com" else url finder.follow_redirects.side_effect = lambda url: "http://final.com" if url == "http://redirect.com" else url finder.clean_params.side_effect = lambda url: "http://cleaned.com" if url == "http://final.com" else url self.assertEquals( finder.clean_url("http://tiny.com"), "http://cleaned.com", ) self.assertEquals(finder.is_blacklisted.call_count, 4) self.assertEquals(finder.untiny.extract.call_count, 3) self.assertEquals(finder.follow_redirects.call_count, 2) self.assertEquals(finder.clean_params.call_count, 1)
def test_is_blacklisted(self): finder = URLFinder() self.assertTrue(finder.is_blacklisted("http://instagr.am/12345")) self.assertFalse(finder.is_blacklisted("http://example.com"))