mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Fix nasdaq top retail working without a key resulting in an error (#5811)
* raise error if no api key found * check for empty strings * black * fix test * less verbose --------- Co-authored-by: Diogo Sousa <montezdesousa@gmail.com> Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>
This commit is contained in:
@@ -48,14 +48,15 @@ class QueryExecutor:
|
||||
credentials = {}
|
||||
|
||||
for c in provider.credentials:
|
||||
credential_value = credentials.get(c)
|
||||
if c not in credentials or credential_value is None:
|
||||
v = credentials.get(c)
|
||||
secret = v.get_secret_value() if v else None
|
||||
if c not in credentials or not secret:
|
||||
if require_credentials:
|
||||
website = provider.website or ""
|
||||
extra_msg = f"Check {website} to get it." if website else ""
|
||||
raise OpenBBError(f"Missing credential '{c}'. {extra_msg}")
|
||||
extra_msg = f" Check {website} to get it." if website else ""
|
||||
raise OpenBBError(f"Missing credential '{c}'.{extra_msg}")
|
||||
else:
|
||||
filtered_credentials[c] = credential_value.get_secret_value()
|
||||
filtered_credentials[c] = secret
|
||||
|
||||
return filtered_credentials
|
||||
|
||||
|
||||
@@ -78,6 +78,19 @@ def test_filter_credentials_missing_require(mock_query_executor):
|
||||
mock_query_executor.filter_credentials(credentials, provider, True)
|
||||
|
||||
|
||||
def test_filter_credentials_empty_require(mock_query_executor):
|
||||
"""Test if the proper error is raised when a credential is missing."""
|
||||
provider = mock_query_executor.get_provider("test_provider")
|
||||
provider.credentials = ["test_provider_api_key"]
|
||||
credentials = {
|
||||
"test_provider_api_key": SecretStr(""),
|
||||
"other_api_key": SecretStr("12345"),
|
||||
}
|
||||
|
||||
with pytest.raises(OpenBBError, match="Missing credential"):
|
||||
mock_query_executor.filter_credentials(credentials, provider, True)
|
||||
|
||||
|
||||
def test_filter_credentials_missing_dont_require(mock_query_executor):
|
||||
"""Test if the proper error is raised when a credential is missing."""
|
||||
provider = mock_query_executor.get_provider("test_provider")
|
||||
|
||||
Reference in New Issue
Block a user