~landscape/smart/staging

« back to all changes in this revision

Viewing changes to tests/plugins/test_landscape.py

  • Committer: Andreas Hasenack
  • Date: 2009-03-04 18:50:13 UTC
  • mfrom: (818.6.14 trunk)
  • mto: This revision was merged to the branch mainline in revision 837.
  • Revision ID: andreas@canonical.com-20090304185013-5nwi2uyzitzic8yv
Merge latest fixes from trunk for the proxy environment variable handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
"""
21
21
 
22
22
 
 
23
class EnvironSnapshot(object):
 
24
 
 
25
    def __init__(self):
 
26
        self._snapshot = os.environ.copy()
 
27
 
 
28
    def restore(self):
 
29
        os.environ.update(self._snapshot)
 
30
        for key in list(os.environ):
 
31
            if key not in self._snapshot:
 
32
                del os.environ[key]
 
33
 
 
34
 
23
35
class LandscapePluginTest(MockerTestCase):
24
36
 
25
37
    def setUp(self):
131
143
        self.assertEquals(sysconf.get("http-proxy"), None)
132
144
        self.assertEquals(sysconf.get("https-proxy"), None)
133
145
        self.assertEquals(sysconf.get("ftp-proxy"), None)
 
146
 
 
147
    def test_do_not_override_environment_variable(self):
 
148
        """
 
149
        If the environment variable is set for some variable, do not
 
150
        import the setting from Landscape.
 
151
        """
 
152
        environ_snapshot = EnvironSnapshot()
 
153
        self.addCleanup(environ_snapshot.restore)
 
154
        
 
155
        os.environ["http_proxy"] = "http_from_environ"
 
156
        os.environ["https_proxy"] = "https_from_environ"
 
157
        os.environ["ftp_proxy"] = "ftp_from_environ"
 
158
 
 
159
        sysconf.set("use-landscape-proxies", True)
 
160
        landscape.run()
 
161
 
 
162
        self.assertEquals(sysconf.get("http-proxy"), None)
 
163
        self.assertEquals(sysconf.get("https-proxy"), None)
 
164
        self.assertEquals(sysconf.get("ftp-proxy"), None)
 
165