Skip to content

Commit

Permalink
refactor to test
Browse files Browse the repository at this point in the history
  • Loading branch information
SermetPekin committed Aug 2, 2024
1 parent 64af6c2 commit d4a7ad4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
20 changes: 10 additions & 10 deletions evdspy/EVDSlocal/console/proxy_for_menu.py
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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()
14 changes: 14 additions & 0 deletions evdspy/EVDSlocal/tests/test_get_proxies_env.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d4a7ad4

Please sign in to comment.