def test_proxyscrape_success(self): with open(os.path.join(cwd, 'mock_pages', 'proxyscrape.txt'), 'r') as html: response = Mock() response.text = html.read() response.ok = True self.requests.get = lambda url: response resource_name = get_proxyscrape_resource() expected = { Proxy('179.124.59.232', '53281', None, None, False, None, resource_name), Proxy('200.107.59.98', '8080', None, None, False, None, resource_name), Proxy('217.172.244.7', '8080', None, None, False, None, resource_name) } func = pss.RESOURCE_MAP[resource_name] pr = ProxyResource(func, 10) _, proxies = pr.refresh() for proxy in proxies: self.assertIn(proxy, expected)
def test_proxyscrape_not_ok(self): response = Mock() response.ok = False self.requests.get = lambda url: response resource_name = get_proxyscrape_resource() func = pss.RESOURCE_MAP[resource_name] pr = ProxyResource(func, 10) refreshed, proxies = pr.refresh() self.assertEqual(False, refreshed) self.assertIsNone(proxies)
def test_us_proxies_invalid_html(self): with open(os.path.join(cwd, 'mock_pages', 'empty.html'), 'r') as html: response = Mock() response.text = html.read() response.ok = True self.requests.get = lambda url: response resource_name = get_proxyscrape_resource() func = pss.RESOURCE_MAP[resource_name] pr = ProxyResource(func, 10) refreshed, proxies = pr.refresh() self.assertEqual(False, refreshed) self.assertIsNone(proxies)
def test_get_proxyscrape_resource_invalid_country(self): with self.assertRaises(ValueError): get_proxyscrape_resource(country='')
def test_get_proxyscrape_resource_invalid_anonymity(self): with self.assertRaises(ValueError): get_proxyscrape_resource(anonymity='')
def test_get_proxyscrape_resource_invalid_ssl(self): with self.assertRaises(ValueError): get_proxyscrape_resource(ssl='')
def test_get_proxyscrape_resource_invalid_timeout(self): with self.assertRaises(ValueError): get_proxyscrape_resource(timeout=0)
def test_get_proxyscrape_resource_duplicate(self): resource_name1 = get_proxyscrape_resource() resource_name2 = get_proxyscrape_resource() self.assertEqual(resource_name1, resource_name2) self.assertIn(resource_name2, pss.RESOURCE_MAP)
def test_get_proxyscrape_resource_success(self): resource_name = get_proxyscrape_resource() self.assertIn(resource_name, pss.RESOURCE_MAP)