def testProxyBypassConary(self):
        if not os.path.exists(rephelp.HTTPProxy.proxyBinPath):
            raise testhelp.SkipTestException('testProxyBypass depends on squid being installed')

        class Controller(ServerController):
            class XMLRPCHandler:
                def ping(self):
                    return [True]

            def handlerFactory(self):
                return self.XMLRPCHandler()

        environ = os.environ.copy()
        self.mock(os, 'environ', environ)

        sc = Controller()
        h = None
        oldLocalHosts = httputils.LocalHosts
        try:
            h = rephelp.HTTPProxy(os.path.join(self.workDir, "http-cache"))
            proxyUri = h.start()

            proxyMap = proxy_map.ProxyMap()
            proxyMap.addStrategy('*', ['conary://' + proxyUri])

            tsp = transport.Transport(proxyMap=proxyMap)
            sp = util.ServerProxy(url=sc.url(), transport=tsp)

            # Now mangle localhosts. Proxy is 127.0.0.1, server is on
            # localhost.
            # Make the proxy appear to be remote
            localhosts = set(httputils.LocalHosts)
            localhosts.remove('127.0.0.1')
            httputils.LocalHosts = localhosts

            # Remote proxy, local host. Go direct
            logsz0 = h.getAccessLogSize()
            sp.ping()
            self.sleep(1)
            logsz1 = h.getAccessLogSize()
            self.assertEqual(logsz1, logsz0)

            # Local proxy, remote host. Proxy
            localhosts.add('127.0.0.1')
            localhosts.remove('localhost')

            logsz0 = h.getAccessLogSize()
            sp.ping()
            self.sleep(1)
            logsz1 = h.getAccessLogSize()
            self.assertTrue(logsz1 > logsz0, "Proxy should have been used")

            environ['no_proxy'] = '*'
            # Proxy should still be used, the environemnt variable should
            # not affect the result since it's a Conary proxy
            logsz0 = h.getAccessLogSize()
            sp.ping()
            self.sleep(1)
            logsz1 = h.getAccessLogSize()
            self.assertTrue(logsz1 > logsz0, "Proxy should have been used")
        finally:
            httputils.LocalHosts = oldLocalHosts
            sc.kill()
            if h:
                h.stop()
Test that no_proxy does not affect conary proxies (CNY-3349)
dataset/ETHPy150Open sassoftware/conary/conary_test/repositorytest/transporttest.py/TransportTest.testProxyBypassConary