Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
 def test_get_proxyscrape_resource_invalid_country(self):
     with self.assertRaises(ValueError):
         get_proxyscrape_resource(country='')
Пример #5
0
 def test_get_proxyscrape_resource_invalid_anonymity(self):
     with self.assertRaises(ValueError):
         get_proxyscrape_resource(anonymity='')
Пример #6
0
 def test_get_proxyscrape_resource_invalid_ssl(self):
     with self.assertRaises(ValueError):
         get_proxyscrape_resource(ssl='')
Пример #7
0
 def test_get_proxyscrape_resource_invalid_timeout(self):
     with self.assertRaises(ValueError):
         get_proxyscrape_resource(timeout=0)
Пример #8
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)
Пример #9
0
 def test_get_proxyscrape_resource_success(self):
     resource_name = get_proxyscrape_resource()
     self.assertIn(resource_name, pss.RESOURCE_MAP)