This is an automated email from the ASF dual-hosted git repository.
altay pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new 34a4e37 [BEAM-7046] Restore os.environ in HttpClientTest
new e93cdf1 Merge pull request #8266 from udim/http_proxy
34a4e37 is described below
commit 34a4e37f10eab0d1d83188739cdf7baf58d2922c
Author: Udi Meiri <[email protected]>
AuthorDate: Tue Apr 9 15:57:39 2019 -0700
[BEAM-7046] Restore os.environ in HttpClientTest
This was causing warnings about parsing http_proxy in other tests that
use grpc.
---
.../apache_beam/internal/http_client_test.py | 87 +++++++++++-----------
1 file changed, 44 insertions(+), 43 deletions(-)
diff --git a/sdks/python/apache_beam/internal/http_client_test.py
b/sdks/python/apache_beam/internal/http_client_test.py
index 460b1db..9755edf 100644
--- a/sdks/python/apache_beam/internal/http_client_test.py
+++ b/sdks/python/apache_beam/internal/http_client_test.py
@@ -21,6 +21,7 @@ from __future__ import absolute_import
import os
import unittest
+import mock
from httplib2 import ProxyInfo
from apache_beam.internal.http_client import DEFAULT_HTTP_TIMEOUT_SECONDS
@@ -31,52 +32,52 @@ from apache_beam.internal.http_client import
proxy_info_from_environment_var
class HttpClientTest(unittest.TestCase):
def test_proxy_from_env_http_with_port(self):
- os.environ['http_proxy'] = 'http://localhost:9000'
- proxy_info = proxy_info_from_environment_var('http_proxy')
- expected = ProxyInfo(3, 'localhost', 9000)
- self.assertEquals(str(expected), str(proxy_info))
+ with mock.patch.dict(os.environ, http_proxy='http://localhost:9000'):
+ proxy_info = proxy_info_from_environment_var('http_proxy')
+ expected = ProxyInfo(3, 'localhost', 9000)
+ self.assertEquals(str(expected), str(proxy_info))
def test_proxy_from_env_https_with_port(self):
- os.environ['https_proxy'] = 'https://localhost:9000'
- proxy_info = proxy_info_from_environment_var('https_proxy')
- expected = ProxyInfo(3, 'localhost', 9000)
- self.assertEquals(str(expected), str(proxy_info))
+ with mock.patch.dict(os.environ, https_proxy='https://localhost:9000'):
+ proxy_info = proxy_info_from_environment_var('https_proxy')
+ expected = ProxyInfo(3, 'localhost', 9000)
+ self.assertEquals(str(expected), str(proxy_info))
def test_proxy_from_env_http_without_port(self):
- os.environ['http_proxy'] = 'http://localhost'
- proxy_info = proxy_info_from_environment_var('http_proxy')
- expected = ProxyInfo(3, 'localhost', 80)
- self.assertEquals(str(expected), str(proxy_info))
+ with mock.patch.dict(os.environ, http_proxy='http://localhost'):
+ proxy_info = proxy_info_from_environment_var('http_proxy')
+ expected = ProxyInfo(3, 'localhost', 80)
+ self.assertEquals(str(expected), str(proxy_info))
def test_proxy_from_env_https_without_port(self):
- os.environ['https_proxy'] = 'https://localhost'
- proxy_info = proxy_info_from_environment_var('https_proxy')
- expected = ProxyInfo(3, 'localhost', 443)
- self.assertEquals(str(expected), str(proxy_info))
+ with mock.patch.dict(os.environ, https_proxy='https://localhost'):
+ proxy_info = proxy_info_from_environment_var('https_proxy')
+ expected = ProxyInfo(3, 'localhost', 443)
+ self.assertEquals(str(expected), str(proxy_info))
def test_proxy_from_env_http_without_method(self):
- os.environ['http_proxy'] = 'localhost:8000'
- proxy_info = proxy_info_from_environment_var('http_proxy')
- expected = ProxyInfo(3, 'localhost', 8000)
- self.assertEquals(str(expected), str(proxy_info))
+ with mock.patch.dict(os.environ, http_proxy='localhost:8000'):
+ proxy_info = proxy_info_from_environment_var('http_proxy')
+ expected = ProxyInfo(3, 'localhost', 8000)
+ self.assertEquals(str(expected), str(proxy_info))
def test_proxy_from_env_https_without_method(self):
- os.environ['https_proxy'] = 'localhost:8000'
- proxy_info = proxy_info_from_environment_var('https_proxy')
- expected = ProxyInfo(3, 'localhost', 8000)
- self.assertEquals(str(expected), str(proxy_info))
+ with mock.patch.dict(os.environ, https_proxy='localhost:8000'):
+ proxy_info = proxy_info_from_environment_var('https_proxy')
+ expected = ProxyInfo(3, 'localhost', 8000)
+ self.assertEquals(str(expected), str(proxy_info))
def test_proxy_from_env_http_without_port_without_method(self):
- os.environ['http_proxy'] = 'localhost'
- proxy_info = proxy_info_from_environment_var('http_proxy')
- expected = ProxyInfo(3, 'localhost', 80)
- self.assertEquals(str(expected), str(proxy_info))
+ with mock.patch.dict(os.environ, http_proxy='localhost'):
+ proxy_info = proxy_info_from_environment_var('http_proxy')
+ expected = ProxyInfo(3, 'localhost', 80)
+ self.assertEquals(str(expected), str(proxy_info))
def test_proxy_from_env_https_without_port_without_method(self):
- os.environ['https_proxy'] = 'localhost'
- proxy_info = proxy_info_from_environment_var('https_proxy')
- expected = ProxyInfo(3, 'localhost', 443)
- self.assertEquals(str(expected), str(proxy_info))
+ with mock.patch.dict(os.environ, https_proxy='localhost'):
+ proxy_info = proxy_info_from_environment_var('https_proxy')
+ expected = ProxyInfo(3, 'localhost', 443)
+ self.assertEquals(str(expected), str(proxy_info))
def test_proxy_from_env_invalid_var(self):
proxy_info = proxy_info_from_environment_var('http_proxy_host')
@@ -84,21 +85,21 @@ class HttpClientTest(unittest.TestCase):
self.assertEquals(str(expected), str(proxy_info))
def test_proxy_from_env_wrong_method_in_var_name(self):
- os.environ['smtp_proxy'] = 'localhost'
- with self.assertRaises(KeyError):
- proxy_info_from_environment_var('smtp_proxy')
+ with mock.patch.dict(os.environ, smtp_proxy='localhost'):
+ with self.assertRaises(KeyError):
+ proxy_info_from_environment_var('smtp_proxy')
def test_proxy_from_env_wrong_method_in_url(self):
- os.environ['http_proxy'] = 'smtp://localhost:8000'
- proxy_info = proxy_info_from_environment_var('http_proxy')
- expected = ProxyInfo(3, 'smtp', 80) # wrong proxy info generated
- self.assertEquals(str(expected), str(proxy_info))
+ with mock.patch.dict(os.environ, http_proxy='smtp://localhost:8000'):
+ proxy_info = proxy_info_from_environment_var('http_proxy')
+ expected = ProxyInfo(3, 'smtp', 80) # wrong proxy info generated
+ self.assertEquals(str(expected), str(proxy_info))
def test_get_new_http_proxy_info(self):
- os.environ['http_proxy'] = 'localhost'
- http = get_new_http()
- expected = ProxyInfo(3, 'localhost', 80)
- self.assertEquals(str(http.proxy_info), str(expected))
+ with mock.patch.dict(os.environ, http_proxy='localhost'):
+ http = get_new_http()
+ expected = ProxyInfo(3, 'localhost', 80)
+ self.assertEquals(str(http.proxy_info), str(expected))
def test_get_new_http_timeout(self):
http = get_new_http()