mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 21:12:16 +00:00
* add EIA daily spot prices data via FRED * line too long * comment out the test skipped test * fix test? * delete commented out sections * unused argument * name things like Minh says --------- Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""Test Commodity API endpoints."""
|
|
|
|
import base64
|
|
|
|
import pytest
|
|
import requests
|
|
from openbb_core.env import Env
|
|
from openbb_core.provider.utils.helpers import get_querystring
|
|
|
|
# pylint: disable=redefined-outer-name
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def headers():
|
|
"""Get the headers for the API request."""
|
|
userpass = f"{Env().API_USERNAME}:{Env().API_PASSWORD}"
|
|
userpass_bytes = userpass.encode("ascii")
|
|
base64_bytes = base64.b64encode(userpass_bytes)
|
|
|
|
return {"Authorization": f"Basic {base64_bytes.decode('ascii')}"}
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"params",
|
|
[
|
|
(
|
|
{
|
|
"commodity": "all",
|
|
"start_date": None,
|
|
"end_date": None,
|
|
"frequency": None,
|
|
"transform": None,
|
|
"aggregation_method": None,
|
|
"provider": "fred",
|
|
}
|
|
),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_commodity_price_spot(params, headers):
|
|
"""Test the commodity spot prices endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://0.0.0.0:8000/api/v1/commodity/price/spot?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|