def test_as_json_w_geo(): p = Proxy('8.8.8.8', '3128') p._runtimes = [1, 3, 3] p.types.update({'HTTP': 'Anonymous', 'HTTPS': None}) json_tpl = { 'host': '8.8.8.8', 'port': 3128, 'geo': { 'country': { 'code': 'US', 'name': 'United States', }, }, 'types': [ { 'type': 'HTTP', 'level': 'Anonymous' }, { 'type': 'HTTPS', 'level': '' }, ], 'avg_resp_time': 2.33, 'error_rate': 0, } assert p.as_json() == json_tpl
def test_repr(): p = Proxy('8.8.8.8', '80') p._runtimes = [1, 3, 3] p.types.update({'HTTP': 'Anonymous', 'HTTPS': None}) assert repr(p) == '<Proxy US 2.33s [HTTP: Anonymous, HTTPS] 8.8.8.8:80>' p = Proxy('4.4.4.4', '8080') p.types.update({'SOCKS4': None, 'SOCKS5': None}) assert repr(p) == '<Proxy US 0.00s [SOCKS4, SOCKS5] 4.4.4.4:8080>' p = Proxy('127.0.0.1', '3128') assert repr(p) == '<Proxy -- 0.00s [] 127.0.0.1:3128>'
def test_repr(self): p = Proxy('8.8.8.8', '80') p._runtimes = [1, 3, 2] p.types.update({'HTTP': 'Anonymous', 'HTTPS': None}) self.assertEqual(repr(p), '<Proxy US 2.00s [HTTP: Anonymous, HTTPS] 8.8.8.8:80>') p.types.clear() p.types.update({'SOCKS4': None, 'SOCKS5': None}) self.assertEqual(repr(p), '<Proxy US 2.00s [SOCKS4, SOCKS5] 8.8.8.8:80>') p = Proxy('127.0.0.1', '80') self.assertEqual(repr(p), '<Proxy -- 0.00s [] 127.0.0.1:80>')
def test_repr(self): p = Proxy("8.8.8.8", "80") p._runtimes = [1, 3, 2] p.types.update({"HTTP": "Anonymous", "HTTPS": None}) self.assertEqual(repr(p), "<Proxy US 2.00s [HTTP: Anonymous, HTTPS] 8.8.8.8:80>") p.types.clear() p.types.update({"SOCKS4": None, "SOCKS5": None}) self.assertEqual(repr(p), "<Proxy US 2.00s [SOCKS4, SOCKS5] 8.8.8.8:80>") p = Proxy("127.0.0.1", "80") self.assertEqual(repr(p), "<Proxy -- 0.00s [] 127.0.0.1:80>")
def test_repr(): p = Proxy('8.8.8.8', '80') p._runtimes = [1, 3, 3] p.types.update({'HTTP': 'Anonymous', 'HTTPS': None}) assert repr( p ) == '<Proxy geo:US avg:2.33s err:0 req:3 [HTTP: Anonymous, HTTPS] 8.8.8.8:80>' p = Proxy('4.4.4.4', '8080') p.types.update({'SOCKS4': None, 'SOCKS5': None}) assert repr( p ) == '<Proxy geo:US avg:0.00s err:0 req:0 [SOCKS4, SOCKS5] 4.4.4.4:8080>' p = Proxy('127.0.0.1', '3128') assert repr(p) == '<Proxy geo:-- avg:0.00s err:0 req:0 [] 127.0.0.1:3128>'
def test_avg_resp_time(): p = Proxy('127.0.0.1', '80') assert p.avg_resp_time == 0.0 p._runtimes = [1, 3, 4] assert p.avg_resp_time == 2.67
def test_avg_resp_time(self): p = Proxy('127.0.0.1', '80') self.assertEqual(p.avg_resp_time, 0.0) p._runtimes = [1, 3, 2] self.assertEqual(p.avg_resp_time, 2.0)
def test_avg_resp_time(self): p = Proxy("127.0.0.1", "80") self.assertEqual(p.avg_resp_time, 0.0) p._runtimes = [1, 3, 2] self.assertEqual(p.avg_resp_time, 2.0)