def set_proxy_settings(self, config, server, authenticated, username, password, pac_url): config = str(config) or 'System' url = str(server) settings = ProxySettings(config=config) if config == 'Manual': settings.from_url(url) elif config == 'Automatic': settings.pac_url = str(pac_url) settings.authenticated = authenticated settings.username = str(username) settings.password = str(password) return self._manager.set_proxy_settings(settings)
def set_proxy_settings(self, config='System', server=None, authenticated=False, username=None, password=None): try: config = str(config) url = str(server) settings = ProxySettings(config=config) if config == "Manual": settings.from_url(url) settings.authenticated = "true" == authenticated settings.username = str(username) settings.password = str(password) return self._manager.set_proxy_settings(settings) except Exception as e: log.exception(e) return ""
def set_proxy_settings(self, config='System', server=None, authenticated=False, username=None, password=None, pac_url=None): try: config = str(config) url = str(server) settings = ProxySettings(config=config) if config == "Manual": settings.from_url(url) elif config == "Automatic": settings.pac_url = str(pac_url) settings.authenticated = "true" == authenticated settings.username = str(username) settings.password = str(password) return self._manager.set_proxy_settings(settings) except Exception as e: log.exception(e) return ""
def test_proxy_settings(self): proxy = ProxySettings() proxy.from_url("localhost:3128") self.assertEqual(proxy.username, None) self.assertEqual(proxy.password, None) self.assertEqual(proxy.authenticated, False) self.assertEqual(proxy.server, "localhost") self.assertEqual(proxy.port, 3128) self.assertEqual(proxy.proxy_type, None) self.assertEqual(proxy.to_url(), 'localhost:3128') self.assertEqual(proxy.to_url(False), 'localhost:3128') proxy.from_url("user@localhost:3128") self.assertEqual(proxy.username, "user") self.assertEqual(proxy.password, None) self.assertEqual(proxy.authenticated, False) self.assertEqual(proxy.server, "localhost") self.assertEqual(proxy.port, 3128) self.assertEqual(proxy.proxy_type, None) self.assertEqual(proxy.to_url(), 'localhost:3128') self.assertEqual(proxy.to_url(False), 'localhost:3128') proxy.from_url("user:password@localhost:3128") self.assertEqual(proxy.username, "user") self.assertEqual(proxy.password, "password") self.assertEqual(proxy.authenticated, True) self.assertEqual(proxy.server, "localhost") self.assertEqual(proxy.port, 3128) self.assertEqual(proxy.proxy_type, None) self.assertEqual(proxy.to_url(), 'user:password@localhost:3128') self.assertEqual(proxy.to_url(False), 'localhost:3128') proxy.from_url("http://*****:*****@localhost:3128") self.assertEqual(proxy.username, "user") self.assertEqual(proxy.password, "password") self.assertEqual(proxy.authenticated, True) self.assertEqual(proxy.server, "localhost") self.assertEqual(proxy.port, 3128) self.assertEqual(proxy.proxy_type, 'http') self.assertEqual(proxy.to_url(), 'http://*****:*****@localhost:3128') self.assertEqual(proxy.to_url(False), 'http://*****:*****@localhost:3129") self.assertEqual(proxy.username, "user") self.assertEqual(proxy.password, "password") self.assertEqual(proxy.authenticated, True) self.assertEqual(proxy.server, "localhost") self.assertEqual(proxy.port, 3129) self.assertEqual(proxy.proxy_type, 'https') self.assertEqual(proxy.to_url(), 'https://*****:*****@localhost:3129') self.assertEqual(proxy.to_url(False), 'https://localhost:3129')