From d4a7ad416725f9510b2bd162cf04a5778339101c Mon Sep 17 00:00:00 2001 From: "sermet.pekin" Date: Fri, 2 Aug 2024 10:07:23 +0300 Subject: [PATCH] refactor to test --- evdspy/EVDSlocal/console/proxy_for_menu.py | 20 +++++++++---------- .../EVDSlocal/tests/test_get_proxies_env.py | 14 +++++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 evdspy/EVDSlocal/tests/test_get_proxies_env.py diff --git a/evdspy/EVDSlocal/console/proxy_for_menu.py b/evdspy/EVDSlocal/console/proxy_for_menu.py index 0f722db..43a152c 100644 --- a/evdspy/EVDSlocal/console/proxy_for_menu.py +++ b/evdspy/EVDSlocal/console/proxy_for_menu.py @@ -1,19 +1,11 @@ import os - -def get_proxies_env() -> dict: - from ..config.dotenv import load_env +def get_proxies_env_helper(a , b , a1 , b1 ) -> dict: def get_one(x, y): if x is None: return y return x - load_env() # http_proxy - a = os.getenv("http_proxy") - a1 = os.getenv("PROXY_http") - - b = os.getenv("https_proxy") - b1 = os.getenv("PROXY_https") a = get_one(a, a1) b = get_one(b, b1) @@ -27,5 +19,13 @@ def get_one(x, y): "http": a, "https": b } +def get_proxies_env() -> dict: + from ..config.dotenv import load_env + load_env() # http_proxy + a = os.getenv("http_proxy") + a1 = os.getenv("PROXY_http") + b = os.getenv("https_proxy") + b1 = os.getenv("PROXY_https") + return get_proxies_env_helper( a , b, a1 , b1 ) + -# check_proxy() diff --git a/evdspy/EVDSlocal/tests/test_get_proxies_env.py b/evdspy/EVDSlocal/tests/test_get_proxies_env.py new file mode 100644 index 0000000..5fae7d8 --- /dev/null +++ b/evdspy/EVDSlocal/tests/test_get_proxies_env.py @@ -0,0 +1,14 @@ +from evdspy.EVDSlocal.console.proxy_for_menu import get_proxies_env_helper + + +def test_get_proxies_env_helper(capsys): + x1 = (["example:80", None, "example:80", None], {'http': 'example:80'}) + x2 = (["example:80", "example:80", "example:80", None], {'http': 'example:80', 'https': 'example:80'}) + x3 = (["example:80", "example:89", "example:90", "example:91"], {'http': 'example:80', 'https': 'example:89'}) + x4 = ([None, None, "example:90", "example:91"], {'http': 'example:90', 'https': 'example:91'}) + liste = [x1, x2, x3, x4] + with capsys.disabled(): + for x, expected in liste: + res = get_proxies_env_helper(*x) + print(res) + assert res == expected