~diegosarmentero/ubuntuone-client/syncdaemon-q

« back to all changes in this revision

Viewing changes to tests/proxy/test_tunnel_server.py

  • Committer: Tarmac
  • Author(s): Alejandro J. Cura
  • Date: 2012-03-15 19:34:46 UTC
  • mfrom: (1196.6.23 proxy-tunnel-fix)
  • Revision ID: tarmac-20120315193446-zapb9mdiqovbk5zv
QNetwork must use the proxy built; forward disconnections in the tunnel client.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
)
43
43
 
44
44
FAKE_SETTINGS = {
45
 
    "host": "myhost",
46
 
    "port": "8888",
 
45
    "http": {
 
46
        "host": "myhost",
 
47
        "port": 8888,
 
48
    }
47
49
}
48
50
 
49
51
SAMPLE_HOST = "samplehost.com"
384
386
        return [self]
385
387
 
386
388
 
387
 
class IsProxyEnabledTestCase(TestCase):
388
 
    """Tests for the is_proxy_enabled function."""
 
389
class CheckProxyEnabledTestCase(TestCase):
 
390
    """Tests for the check_proxy_enabled function."""
 
391
 
 
392
    @defer.inlineCallbacks
 
393
    def setUp(self):
 
394
        """Initialize this testcase."""
 
395
        yield super(CheckProxyEnabledTestCase, self).setUp()
 
396
        self.app_proxy = []
389
397
 
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)
395
405
 
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)
409
420
 
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)
414
426
 
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)
420
433
 
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)
426
440
 
427
441
 
428
442
class FakeQCoreApp(object):
461
475
            self.called.append(args)
462
476
            return self.proxies_enabled
463
477
 
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)