mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 13:32:08 +00:00
* rename oecd_utils to oecd and populate all models there when openbb-economy is not installed * linting
347 lines
9.5 KiB
Python
347 lines
9.5 KiB
Python
"""Test OECD API endpoints."""
|
|
|
|
import base64
|
|
|
|
import pytest
|
|
import requests
|
|
from openbb_core.env import Env
|
|
from openbb_core.provider.utils.helpers import get_querystring
|
|
|
|
|
|
@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", [{}])
|
|
@pytest.mark.integration
|
|
def test_oecd_list_topic_choices(params, headers):
|
|
"""Test oecd_list_topic_choices endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://localhost:8000/api/v1/oecd/list_topic_choices?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"params",
|
|
[
|
|
{
|
|
"topic": None,
|
|
},
|
|
{
|
|
"topic": "ECO",
|
|
},
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_oecd_list_subtopic_choices(params, headers):
|
|
"""Test oecd_list_subtopic_choices endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://localhost:8000/api/v1/oecd/list_subtopic_choices?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"params",
|
|
[
|
|
{
|
|
"topic": None,
|
|
"subtopic": None,
|
|
},
|
|
{
|
|
"topic": "ECO",
|
|
"subtopic": None,
|
|
},
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_oecd_list_dataflows(params, headers):
|
|
"""Test oecd_list_dataflows endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://localhost:8000/api/v1/oecd/list_dataflows?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@pytest.mark.parametrize("params", [{}])
|
|
@pytest.mark.integration
|
|
def test_oecd_list_dataflow_choices(params, headers):
|
|
"""Test oecd_list_dataflow_choices endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://localhost:8000/api/v1/oecd/list_dataflow_choices?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"params",
|
|
[
|
|
{
|
|
"query": None,
|
|
},
|
|
{
|
|
"query": "health",
|
|
},
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_oecd_list_topics(params, headers):
|
|
"""Test oecd_list_topics endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://localhost:8000/api/v1/oecd/list_topics?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"params",
|
|
[
|
|
{
|
|
"dataflow_id": "DF_PRICES_ALL",
|
|
"output_format": "json",
|
|
},
|
|
{
|
|
"dataflow_id": "DF_PRICES_ALL",
|
|
"output_format": "markdown",
|
|
},
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_oecd_get_dataflow_parameters(params, headers):
|
|
"""Test oecd_get_dataflow_parameters endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://localhost:8000/api/v1/oecd/get_dataflow_parameters?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"params",
|
|
[
|
|
{
|
|
"query": None,
|
|
"topic": None,
|
|
"subtopic": None,
|
|
"dataflow_id": None,
|
|
},
|
|
{
|
|
"query": "GDP",
|
|
"topic": None,
|
|
"subtopic": None,
|
|
"dataflow_id": None,
|
|
},
|
|
{
|
|
"query": None,
|
|
"topic": "HEA",
|
|
"subtopic": None,
|
|
"dataflow_id": None,
|
|
},
|
|
{
|
|
"query": None,
|
|
"topic": None,
|
|
"subtopic": None,
|
|
"dataflow_id": "DF_PRICES_ALL",
|
|
},
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_oecd_list_tables(params, headers):
|
|
"""Test oecd_list_tables endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://localhost:8000/api/v1/oecd/list_tables?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"params",
|
|
[
|
|
{
|
|
"table_id": "DF_PRICES_ALL",
|
|
},
|
|
{
|
|
"table_id": "DF_T725R_Q",
|
|
},
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_oecd_get_table_detail(params, headers):
|
|
"""Test oecd_get_table_detail endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://localhost:8000/api/v1/oecd/get_table_detail?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"params",
|
|
[
|
|
{
|
|
"topic": None,
|
|
},
|
|
{
|
|
"topic": "ECO",
|
|
},
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_oecd_list_table_choices(params, headers):
|
|
"""Test oecd_list_table_choices endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://localhost:8000/api/v1/oecd/list_table_choices?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"params",
|
|
[
|
|
{
|
|
"symbol": "DF_PRICES_ALL::CPI",
|
|
"country": None,
|
|
"frequency": None,
|
|
"transform": None,
|
|
"dimension_values": None,
|
|
},
|
|
{
|
|
"symbol": "DF_PRICES_ALL::CPI",
|
|
"country": "true",
|
|
"frequency": None,
|
|
"transform": None,
|
|
"dimension_values": None,
|
|
},
|
|
{
|
|
"symbol": "DF_PRICES_ALL::CPI",
|
|
"country": "USA",
|
|
"frequency": "true",
|
|
"transform": None,
|
|
"dimension_values": None,
|
|
},
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_oecd_indicator_choices(params, headers):
|
|
"""Test oecd_indicator_choices endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://localhost:8000/api/v1/oecd/indicator_choices?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"params",
|
|
[
|
|
{
|
|
"topic": None,
|
|
"subtopic": None,
|
|
"table": None,
|
|
"country": None,
|
|
"frequency": None,
|
|
},
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_oecd_presentation_table_choices(params, headers):
|
|
"""Test oecd_presentation_table_choices endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://localhost:8000/api/v1/oecd/presentation_table_choices?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"params",
|
|
[
|
|
{
|
|
"table": "DF_QNA::T0101",
|
|
"country": "USA",
|
|
"dimension": "unit_measure",
|
|
"frequency": None,
|
|
},
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_oecd_presentation_table_dim_choices(params, headers):
|
|
"""Test oecd_presentation_table_dim_choices endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = (
|
|
f"http://localhost:8000/api/v1/oecd/presentation_table_dim_choices?{query_str}"
|
|
)
|
|
result = requests.get(url, headers=headers, timeout=30)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"params",
|
|
[
|
|
{
|
|
"topic": None,
|
|
"subtopic": None,
|
|
"table": "DF_PRICES_ALL",
|
|
"country": "USA",
|
|
"counterpart": None,
|
|
"frequency": "M",
|
|
"unit_measure": None,
|
|
"adjustment": None,
|
|
"transformation": None,
|
|
"dimension_values": None,
|
|
"limit": 2,
|
|
"start_date": None,
|
|
"end_date": None,
|
|
},
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_oecd_presentation_table(params, headers):
|
|
"""Test oecd_presentation_table endpoint."""
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://localhost:8000/api/v1/oecd/presentation_table?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=30)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|