387
class IsProxyEnabledTestCase(TestCase):
388
"""Tests for the is_proxy_enabled function."""
389
class CheckProxyEnabledTestCase(TestCase):
390
"""Tests for the check_proxy_enabled function."""
392
@defer.inlineCallbacks
394
"""Initialize this testcase."""
395
yield super(CheckProxyEnabledTestCase, self).setUp()
390
398
def _assert_proxy_state(self, platform, state, assertion):
391
399
"""Assert the proxy is in a given state."""
400
self.patch(tunnel_server.QNetworkProxy, "setApplicationProxy",
401
lambda proxy: self.app_proxy.append(proxy))
392
402
self.patch(tunnel_server.sys, "platform", platform)
393
ret = tunnel_server.is_proxy_enabled(SAMPLE_HOST, str(SAMPLE_PORT))
403
ret = tunnel_server.check_proxy_enabled(SAMPLE_HOST, str(SAMPLE_PORT))
394
404
self.assertTrue(ret == state, assertion)
396
406
def _assert_proxy_enabled(self, platform):
406
416
self.patch(tunnel_server.gsettings, "get_proxy_settings",
407
417
lambda: FAKE_SETTINGS)
408
418
self._assert_proxy_enabled("linux3")
419
self.assertEqual(len(self.app_proxy), 1)
410
421
def test_platform_linux_disabled(self):
411
422
"""Tests for the linux platform with proxies disabled."""
412
423
self.patch(tunnel_server.gsettings, "get_proxy_settings", lambda: {})
413
424
self._assert_proxy_disabled("linux3")
425
self.assertEqual(len(self.app_proxy), 0)
415
427
def test_platform_other_enabled(self):
416
428
"""Tests for any other platform with proxies enabled."""
417
429
fake_netproxfact = FakeNetworkProxyFactoryClass(True)
418
430
self.patch(tunnel_server, "QNetworkProxyFactory", fake_netproxfact)
419
431
self._assert_proxy_enabled("windows 1.0")
432
self.assertEqual(len(self.app_proxy), 0)
421
434
def test_platform_other_disabled(self):
422
435
"""Tests for any other platform with proxies disabled."""
423
436
fake_netproxfact = FakeNetworkProxyFactoryClass(False)
424
437
self.patch(tunnel_server, "QNetworkProxyFactory", fake_netproxfact)
425
438
self._assert_proxy_disabled("windows 1.0")
439
self.assertEqual(len(self.app_proxy), 0)
428
442
class FakeQCoreApp(object):
461
475
self.called.append(args)
462
476
return self.proxies_enabled
464
self.patch(tunnel_server, "is_proxy_enabled", fake_is_proxy_enabled)
478
self.patch(tunnel_server, "check_proxy_enabled", fake_is_proxy_enabled)
465
479
self.fake_stdout = StringIO()
466
480
self.patch(tunnel_server.sys, "stdout", self.fake_stdout)
467
481
self.patch(tunnel_server, "QCoreApplication", FakeQCoreApp)