Пример #1
0
    def __getitem__(self, item):
        """

        :type item: str
        """
        item = item.lower()
        item = {'random': ''}.get(item, item)
        if item not in self.proxies_lists:
            self.proxies_lists[item] = ProxiesList(item or None)
        return self.proxies_lists[item]
Пример #2
0
    def test_infinite_recursion_loop_solution(self, reload_provider_mock,
                                              find_db_proxy_mock):
        """This call was falling into a recursion loop. Now tries only twice and then raise
        an StopIteration exception."""
        from proxy_db.proxies import ProxiesList
        reload_provider_mock.return_value = None
        find_db_proxy_mock.return_value = None

        self.assertRaises(StopIteration, lambda: next(ProxiesList("country")))
        self.assertEqual(find_db_proxy_mock.call_count, 2)
        self.assertEqual(reload_provider_mock.call_count, 2)
Пример #3
0
 def test_provider_name(self):
     self.assertEqual(
         ProxiesList(provider=ProxyNovaCom.name).provider.name,
         ProxyNovaCom.name)
Пример #4
0
 def test_iter(self):
     p = ProxiesList()
     p._proxies = None
     p2 = iter(p)
     self.assertEqual(p2._proxies, set())
Пример #5
0
 def test_reload_provider(self, m):
     p = ProxiesList()
     p.reload_provider()
     m.return_value.request.assert_called_once_with(**p.request_options)
     m.return_value.request.return_value.now.assert_called_once()
Пример #6
0
 def test_find_provider(self, m):
     provider = ProxiesList().find_provider()
     self.assertEqual(provider, m.return_value[0])
Пример #7
0
 def test_random_find_db_proxy(self, m):
     ProxiesList().find_db_proxy()
     m.assert_called_once()
Пример #8
0
 def test_find_db_proxy(self, m):
     m.return_value.query.return_value.join.return_value.filter\
         .return_value.session.get_bind.return_value.name = 'sqlite'
     ProxiesList(strategy=RandomListingStrategy).find_db_proxy()
     m.assert_called_once()
Пример #9
0
 def test_available_providers_filtered(self):
     provider = next(
         iter(filter(lambda x: x.name == ProxyNovaCom.name, PROVIDERS)))
     proxies_list = ProxiesList(provider=provider)
     self.assertEqual(next(iter(proxies_list.available_providers())),
                      provider)
Пример #10
0
 def test_invalid_provider_name(self):
     with self.assertRaises(AssertionError):
         ProxiesList(provider='foo')
Пример #11
0
def main(args=None):
    """Console script for proxy_db."""
    click.echo("Replace this message by putting your code into "
               "proxy_db.cli.main")
    click.echo("See click documentation at http://click.pocoo.org/")
    print(next(ProxiesList(country='CL')))