-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embedders - fix proxies, default on http, tests
- Loading branch information
1 parent
fabacdf
commit 5653e55
Showing
2 changed files
with
77 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import os | ||
import unittest | ||
|
||
from Orange.misc.utils.embedder_utils import get_proxies | ||
|
||
|
||
class TestProxies(unittest.TestCase): | ||
def setUp(self) -> None: | ||
self.previous_http = os.environ.get("http_proxy") | ||
self.previous_https = os.environ.get("https_proxy") | ||
os.environ.pop("http_proxy", None) | ||
os.environ.pop("https_proxy", None) | ||
|
||
def tearDown(self) -> None: | ||
os.environ.pop("http_proxy", None) | ||
os.environ.pop("https_proxy", None) | ||
if self.previous_http is not None: | ||
os.environ["http_proxy"] = self.previous_http | ||
if self.previous_https is not None: | ||
os.environ["https_proxy"] = self.previous_https | ||
|
||
def test_add_scheme(self): | ||
os.environ["http_proxy"] = "test1.com" | ||
os.environ["https_proxy"] = "test2.com" | ||
res = get_proxies() | ||
self.assertEqual("http://test1.com", res["http://"]) | ||
self.assertEqual("http://test2.com", res["https://"]) | ||
|
||
os.environ["http_proxy"] = "test1.com/path" | ||
os.environ["https_proxy"] = "test2.com/path" | ||
res = get_proxies() | ||
self.assertEqual("http://test1.com/path", res["http://"]) | ||
self.assertEqual("http://test2.com/path", res["https://"]) | ||
|
||
os.environ["http_proxy"] = "https://test1.com:123" | ||
os.environ["https_proxy"] = "https://test2.com:124" | ||
res = get_proxies() | ||
self.assertEqual("https://test1.com:123", res["http://"]) | ||
self.assertEqual("https://test2.com:124", res["https://"]) | ||
|
||
def test_both_urls(self): | ||
os.environ["http_proxy"] = "http://test1.com:123" | ||
os.environ["https_proxy"] = "https://test2.com:124" | ||
res = get_proxies() | ||
self.assertEqual("http://test1.com:123", res["http://"]) | ||
self.assertEqual("https://test2.com:124", res["https://"]) | ||
self.assertNotIn("all://", res) | ||
|
||
def test_http_only(self): | ||
os.environ["http_proxy"] = "http://test1.com:123" | ||
res = get_proxies() | ||
self.assertEqual("http://test1.com:123", res["all://"]) | ||
self.assertNotIn("http://", res) | ||
self.assertNotIn("https://", res) | ||
|
||
def test_https_only(self): | ||
os.environ["https_proxy"] = "https://test1.com:123" | ||
res = get_proxies() | ||
self.assertEqual("https://test1.com:123", res["all://"]) | ||
self.assertNotIn("http://", res) | ||
self.assertNotIn("https://", res) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters