← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/maas/update-buildout-etc-simple-redux into lp:maas

 

Gavin Panella has proposed merging lp:~allenap/maas/update-buildout-etc-simple-redux into lp:maas.

Commit message:
Disable all HTTP/HTTPS proxies set in the environment during browser testing.

The code to do this resides in a new fixture, ProxiesDisabledFixture.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~allenap/maas/update-buildout-etc-simple-redux/+merge/128350

Fix the build.

-- 
https://code.launchpad.net/~allenap/maas/update-buildout-etc-simple-redux/+merge/128350
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/update-buildout-etc-simple-redux into lp:maas.
=== modified file 'src/maasserver/tests/test_js.py'
--- src/maasserver/tests/test_js.py	2012-05-28 19:50:46 +0000
+++ src/maasserver/tests/test_js.py	2012-10-06 11:08:24 +0000
@@ -25,6 +25,7 @@
 from maastesting import yui3
 from maastesting.fixtures import (
     DisplayFixture,
+    ProxiesDisabledFixture,
     SSTFixture,
     )
 from maastesting.httpd import HTTPServerFixture
@@ -132,7 +133,8 @@
             # This test has been cloned; just call-up to run the test.
             super(YUIUnitTestsBase, self).__call__(result)
         else:
-            self.multiply(result)
+            with ProxiesDisabledFixture():
+                self.multiply(result)
 
     def test_YUI3_unit_tests(self):
         # Load the page and then wait for #suite to contain

=== modified file 'src/maastesting/fixtures.py'
--- src/maastesting/fixtures.py	2012-05-25 16:13:57 +0000
+++ src/maastesting/fixtures.py	2012-10-06 11:08:24 +0000
@@ -13,12 +13,16 @@
 __all__ = [
     "DisplayFixture",
     "LoggerSilencerFixture",
+    "ProxiesDisabledFixture",
     "SSTFixture",
     ]
 
 import logging
 
-from fixtures import Fixture
+from fixtures import (
+    EnvironmentVariableFixture,
+    Fixture,
+    )
 from pyvirtualdisplay import Display
 from sst.actions import (
     start,
@@ -78,3 +82,12 @@
         start(self.browser_name)
         self.useFixture(LoggerSilencerFixture(self.logger_names))
         self.addCleanup(stop)
+
+
+class ProxiesDisabledFixture(Fixture):
+    """Disables all HTTP/HTTPS proxies set in the environment."""
+
+    def setUp(self):
+        super(ProxiesDisabledFixture, self).setUp()
+        self.useFixture(EnvironmentVariableFixture("http_proxy"))
+        self.useFixture(EnvironmentVariableFixture("https_proxy"))

=== added file 'src/maastesting/tests/test_fixtures.py'
--- src/maastesting/tests/test_fixtures.py	1970-01-01 00:00:00 +0000
+++ src/maastesting/tests/test_fixtures.py	2012-10-06 11:08:24 +0000
@@ -0,0 +1,44 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for `maastesting.fixtures`."""
+
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
+
+__metaclass__ = type
+__all__ = []
+
+import os
+
+from fixtures import EnvironmentVariableFixture
+from maastesting.factory import factory
+from maastesting.fixtures import ProxiesDisabledFixture
+from maastesting.testcase import TestCase
+
+
+class TestProxiedDisabledFixture(TestCase):
+    """Tests for :class:`ProxiesDisabledFixture`."""
+
+    def test_removes_http_proxy_from_environment(self):
+        http_proxy = factory.make_name("http-proxy")
+        initial = EnvironmentVariableFixture("http_proxy", http_proxy)
+        self.useFixture(initial)
+        # On entry, http_proxy is removed from the environment.
+        with ProxiesDisabledFixture():
+            self.assertNotIn("http_proxy", os.environ)
+        # On exit, http_proxy is restored.
+        self.assertEqual(http_proxy, os.environ.get("http_proxy"))
+
+    def test_removes_https_proxy_from_environment(self):
+        https_proxy = factory.make_name("https-proxy")
+        initial = EnvironmentVariableFixture("https_proxy", https_proxy)
+        self.useFixture(initial)
+        # On entry, https_proxy is removed from the environment.
+        with ProxiesDisabledFixture():
+            self.assertNotIn("https_proxy", os.environ)
+        # On exit, http_proxy is restored.
+        self.assertEqual(https_proxy, os.environ.get("https_proxy"))