Skip to content

Commit c6e52a2

Browse files
CaedenPHsedatguzelsemme
authored andcommitted
Pytest locally fails due to API_KEY env variable (TheAlgorithms#8738)
* fix: Pytest locally fails due to API_KEY env variable (TheAlgorithms#8737) * chore: Fix ruff errors
1 parent b936d38 commit c6e52a2

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

web_programming/currency_converter.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88
import requests
99

1010
URL_BASE = "https://www.amdoren.com/api/currency.php"
11-
TESTING = os.getenv("CI", "")
12-
API_KEY = os.getenv("AMDOREN_API_KEY", "")
1311

14-
if not API_KEY and not TESTING:
15-
raise KeyError(
16-
"API key must be provided in the 'AMDOREN_API_KEY' environment variable."
17-
)
1812

1913
# Currency and their description
2014
list_of_currencies = """
@@ -175,20 +169,31 @@
175169

176170

177171
def convert_currency(
178-
from_: str = "USD", to: str = "INR", amount: float = 1.0, api_key: str = API_KEY
172+
from_: str = "USD", to: str = "INR", amount: float = 1.0, api_key: str = ""
179173
) -> str:
180174
"""https://www.amdoren.com/currency-api/"""
175+
# Instead of manually generating parameters
181176
params = locals()
177+
# from is a reserved keyword
182178
params["from"] = params.pop("from_")
183179
res = requests.get(URL_BASE, params=params).json()
184180
return str(res["amount"]) if res["error"] == 0 else res["error_message"]
185181

186182

187183
if __name__ == "__main__":
184+
TESTING = os.getenv("CI", "")
185+
API_KEY = os.getenv("AMDOREN_API_KEY", "")
186+
187+
if not API_KEY and not TESTING:
188+
raise KeyError(
189+
"API key must be provided in the 'AMDOREN_API_KEY' environment variable."
190+
)
191+
188192
print(
189193
convert_currency(
190194
input("Enter from currency: ").strip(),
191195
input("Enter to currency: ").strip(),
192196
float(input("Enter the amount: ").strip()),
197+
API_KEY,
193198
)
194199
)

0 commit comments

Comments
 (0)