mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
Pytest locally fails due to API_KEY env variable (#8738)
* fix: Pytest locally fails due to API_KEY env variable (#8737) * chore: Fix ruff errors
This commit is contained in:
parent
3a9e5fa5ec
commit
80d95fccc3
|
@ -8,13 +8,7 @@ import os
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
URL_BASE = "https://www.amdoren.com/api/currency.php"
|
URL_BASE = "https://www.amdoren.com/api/currency.php"
|
||||||
TESTING = os.getenv("CI", "")
|
|
||||||
API_KEY = os.getenv("AMDOREN_API_KEY", "")
|
|
||||||
|
|
||||||
if not API_KEY and not TESTING:
|
|
||||||
raise KeyError(
|
|
||||||
"API key must be provided in the 'AMDOREN_API_KEY' environment variable."
|
|
||||||
)
|
|
||||||
|
|
||||||
# Currency and their description
|
# Currency and their description
|
||||||
list_of_currencies = """
|
list_of_currencies = """
|
||||||
|
@ -175,20 +169,31 @@ ZMW Zambian Kwacha
|
||||||
|
|
||||||
|
|
||||||
def convert_currency(
|
def convert_currency(
|
||||||
from_: str = "USD", to: str = "INR", amount: float = 1.0, api_key: str = API_KEY
|
from_: str = "USD", to: str = "INR", amount: float = 1.0, api_key: str = ""
|
||||||
) -> str:
|
) -> str:
|
||||||
"""https://www.amdoren.com/currency-api/"""
|
"""https://www.amdoren.com/currency-api/"""
|
||||||
|
# Instead of manually generating parameters
|
||||||
params = locals()
|
params = locals()
|
||||||
|
# from is a reserved keyword
|
||||||
params["from"] = params.pop("from_")
|
params["from"] = params.pop("from_")
|
||||||
res = requests.get(URL_BASE, params=params).json()
|
res = requests.get(URL_BASE, params=params).json()
|
||||||
return str(res["amount"]) if res["error"] == 0 else res["error_message"]
|
return str(res["amount"]) if res["error"] == 0 else res["error_message"]
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
TESTING = os.getenv("CI", "")
|
||||||
|
API_KEY = os.getenv("AMDOREN_API_KEY", "")
|
||||||
|
|
||||||
|
if not API_KEY and not TESTING:
|
||||||
|
raise KeyError(
|
||||||
|
"API key must be provided in the 'AMDOREN_API_KEY' environment variable."
|
||||||
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
convert_currency(
|
convert_currency(
|
||||||
input("Enter from currency: ").strip(),
|
input("Enter from currency: ").strip(),
|
||||||
input("Enter to currency: ").strip(),
|
input("Enter to currency: ").strip(),
|
||||||
float(input("Enter the amount: ").strip()),
|
float(input("Enter the amount: ").strip()),
|
||||||
|
API_KEY,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user