mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
add http basic header to integration tests
This commit is contained in:
@@ -15,6 +15,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
||||
OPENBB_API_AUTH: true
|
||||
OPENBB_API_USERNAME: 'USER'
|
||||
OPENBB_API_PASSWORD: 'PASS'
|
||||
|
||||
steps:
|
||||
- name: Slack Notification - Starting
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
import pytest
|
||||
import requests
|
||||
from extensions.tests.utils.helpers import get_auth
|
||||
from openbb_provider.utils.helpers import get_querystring
|
||||
|
||||
|
||||
def get_token():
|
||||
return requests.post(
|
||||
"http://0.0.0.0:8000/api/v1/account/token",
|
||||
data={"username": "openbb", "password": "openbb"},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def headers():
|
||||
access_token = get_token().json()["access_token"]
|
||||
return {"Authorization": f"Bearer {access_token}"}
|
||||
return {"Authorization": get_auth()}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -1,37 +1,22 @@
|
||||
import json
|
||||
import random
|
||||
from extensions.tests.utils.helpers import get_auth
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
from openbb_provider.utils.helpers import get_querystring
|
||||
|
||||
|
||||
def get_token():
|
||||
return requests.post(
|
||||
"http://0.0.0.0:8000/api/v1/account/token",
|
||||
data={"username": "openbb", "password": "openbb"},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
|
||||
def auth_header():
|
||||
access_token = get_token().json()["access_token"]
|
||||
return {"Authorization": f"Bearer {access_token}"}
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def headers():
|
||||
h = {}
|
||||
auth = auth_header()
|
||||
h.update(auth)
|
||||
return h
|
||||
return {"Authorization": get_auth()}
|
||||
|
||||
|
||||
def get_data(menu: str, symbol: str, provider: str):
|
||||
def get_data(menu: str, symbol: str, provider: str, headers):
|
||||
"""Randomly pick a symbol and a provider and get data from the selected menu."""
|
||||
|
||||
url = f"http://0.0.0.0:8000/api/v1/{menu}/load?symbol={symbol}&provider={provider}"
|
||||
result = requests.get(url, headers=auth_header(), timeout=10)
|
||||
result = requests.get(url, headers=headers, timeout=10)
|
||||
return result.json()["results"]
|
||||
|
||||
|
||||
@@ -45,7 +30,9 @@ def get_stocks_data():
|
||||
symbol = random.choice(["AAPL", "NVDA", "MSFT", "TSLA", "AMZN", "V"]) # noqa: S311
|
||||
provider = random.choice(["fmp", "intrinio", "polygon", "yfinance"]) # noqa: S311
|
||||
|
||||
data["stocks_data"] = get_data("stocks", symbol=symbol, provider=provider)
|
||||
data["stocks_data"] = get_data(
|
||||
"stocks", symbol=symbol, provider=provider, headers=headers
|
||||
)
|
||||
return data["stocks_data"]
|
||||
|
||||
|
||||
@@ -57,7 +44,9 @@ def get_crypto_data():
|
||||
symbol = random.choice(["BTC"]) # noqa: S311
|
||||
provider = random.choice(["fmp"]) # noqa: S311
|
||||
|
||||
data["crypto_data"] = get_data(menu="crypto", symbol=symbol, provider=provider)
|
||||
data["crypto_data"] = get_data(
|
||||
menu="crypto", symbol=symbol, provider=provider, headers=headers
|
||||
)
|
||||
return data["crypto_data"]
|
||||
|
||||
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
import pytest
|
||||
import requests
|
||||
from extensions.tests.utils.helpers import get_auth
|
||||
from openbb_provider.utils.helpers import get_querystring
|
||||
|
||||
|
||||
def get_token():
|
||||
return requests.post(
|
||||
"http://0.0.0.0:8000/api/v1/account/token",
|
||||
data={"username": "openbb", "password": "openbb"},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def headers():
|
||||
access_token = get_token().json()["access_token"]
|
||||
return {"Authorization": f"Bearer {access_token}"}
|
||||
return {"Authorization": get_auth()}
|
||||
return {"Authorization": get_auth()}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
import pytest
|
||||
import requests
|
||||
from extensions.tests.utils.helpers import get_auth
|
||||
from openbb_provider.utils.helpers import get_querystring
|
||||
|
||||
|
||||
def get_token():
|
||||
return requests.post(
|
||||
"http://0.0.0.0:8000/api/v1/account/token",
|
||||
data={"username": "openbb", "password": "openbb"},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def headers():
|
||||
access_token = get_token().json()["access_token"]
|
||||
return {"Authorization": f"Bearer {access_token}"}
|
||||
return {"Authorization": get_auth()}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
import pytest
|
||||
import requests
|
||||
from extensions.tests.utils.helpers import get_auth
|
||||
from openbb_provider.utils.helpers import get_querystring
|
||||
|
||||
|
||||
def get_token():
|
||||
return requests.post(
|
||||
"http://0.0.0.0:8000/api/v1/account/token",
|
||||
data={"username": "openbb", "password": "openbb"},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def headers():
|
||||
access_token = get_token().json()["access_token"]
|
||||
return {"Authorization": f"Bearer {access_token}"}
|
||||
return {"Authorization": get_auth()}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
import pytest
|
||||
import requests
|
||||
from extensions.tests.utils.helpers import get_auth
|
||||
from openbb_provider.utils.helpers import get_querystring
|
||||
|
||||
|
||||
def get_token():
|
||||
return requests.post(
|
||||
"http://0.0.0.0:8000/api/v1/account/token",
|
||||
data={"username": "openbb", "password": "openbb"},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def headers():
|
||||
access_token = get_token().json()["access_token"]
|
||||
return {"Authorization": f"Bearer {access_token}"}
|
||||
return {"Authorization": get_auth()}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
import pytest
|
||||
import requests
|
||||
from extensions.tests.utils.helpers import get_auth
|
||||
from openbb_provider.utils.helpers import get_querystring
|
||||
|
||||
|
||||
def get_token():
|
||||
return requests.post(
|
||||
"http://0.0.0.0:8000/api/v1/account/token",
|
||||
data={"username": "openbb", "password": "openbb"},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def headers():
|
||||
access_token = get_token().json()["access_token"]
|
||||
return {"Authorization": f"Bearer {access_token}"}
|
||||
return {"Authorization": get_auth()}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -3,35 +3,20 @@ import random
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
from extensions.tests.utils.helpers import get_auth
|
||||
from openbb_provider.utils.helpers import get_querystring
|
||||
|
||||
|
||||
def get_token():
|
||||
return requests.post(
|
||||
"http://0.0.0.0:8000/api/v1/account/token",
|
||||
data={"username": "openbb", "password": "openbb"},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
|
||||
def auth_header():
|
||||
access_token = get_token().json()["access_token"]
|
||||
return {"Authorization": f"Bearer {access_token}"}
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def headers():
|
||||
h = {}
|
||||
auth = auth_header()
|
||||
h.update(auth)
|
||||
return h
|
||||
return {"Authorization": get_auth()}
|
||||
|
||||
|
||||
def get_data(menu: str, symbol: str, provider: str):
|
||||
def get_data(menu: str, symbol: str, provider: str, headers):
|
||||
"""Randomly pick a symbol and a provider and get data from the selected menu."""
|
||||
|
||||
url = f"http://0.0.0.0:8000/api/v1/{menu}/load?symbol={symbol}&provider={provider}"
|
||||
result = requests.get(url, headers=auth_header(), timeout=10)
|
||||
result = requests.get(url, headers=headers, timeout=10)
|
||||
return result.json()["results"]
|
||||
|
||||
|
||||
@@ -45,7 +30,9 @@ def get_stocks_data():
|
||||
symbol = random.choice(["AAPL", "NVDA", "MSFT", "TSLA", "AMZN", "V"]) # noqa: S311
|
||||
provider = random.choice(["fmp", "intrinio", "polygon", "yfinance"]) # noqa: S311
|
||||
|
||||
data["stocks_data"] = get_data("stocks", symbol=symbol, provider=provider)
|
||||
data["stocks_data"] = get_data(
|
||||
"stocks", symbol=symbol, provider=provider, headers=headers
|
||||
)
|
||||
return data["stocks_data"]
|
||||
|
||||
|
||||
@@ -57,7 +44,9 @@ def get_crypto_data():
|
||||
symbol = random.choice(["BTC"]) # noqa: S311
|
||||
provider = random.choice(["fmp"]) # noqa: S311
|
||||
|
||||
data["crypto_data"] = get_data(menu="crypto", symbol=symbol, provider=provider)
|
||||
data["crypto_data"] = get_data(
|
||||
menu="crypto", symbol=symbol, provider=provider, headers=headers
|
||||
)
|
||||
return data["crypto_data"]
|
||||
|
||||
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
import pytest
|
||||
import requests
|
||||
from extensions.tests.utils.helpers import get_auth
|
||||
from openbb_provider.utils.helpers import get_querystring
|
||||
|
||||
|
||||
def get_token():
|
||||
return requests.post(
|
||||
"http://0.0.0.0:8000/api/v1/account/token",
|
||||
data={"username": "openbb", "password": "openbb"},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def headers():
|
||||
access_token = get_token().json()["access_token"]
|
||||
return {"Authorization": f"Bearer {access_token}"}
|
||||
return {"Authorization": get_auth()}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -3,35 +3,20 @@ import random
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
from extensions.tests.utils.helpers import get_auth
|
||||
from openbb_provider.utils.helpers import get_querystring
|
||||
|
||||
|
||||
def get_token():
|
||||
return requests.post(
|
||||
"http://0.0.0.0:8000/api/v1/account/token",
|
||||
data={"username": "openbb", "password": "openbb"},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
|
||||
def auth_header():
|
||||
access_token = get_token().json()["access_token"]
|
||||
return {"Authorization": f"Bearer {access_token}"}
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def headers():
|
||||
h = {}
|
||||
auth = auth_header()
|
||||
h.update(auth)
|
||||
return h
|
||||
return {"Authorization": get_auth()}
|
||||
|
||||
|
||||
def get_data(menu: str, symbol: str, provider: str):
|
||||
def get_data(menu: str, symbol: str, provider: str, headers):
|
||||
"""Randomly pick a symbol and a provider and get data from the selected menu."""
|
||||
|
||||
url = f"http://0.0.0.0:8000/api/v1/{menu}/load?symbol={symbol}&provider={provider}"
|
||||
result = requests.get(url, headers=auth_header(), timeout=10)
|
||||
result = requests.get(url, headers=headers, timeout=10)
|
||||
return result.json()["results"]
|
||||
|
||||
|
||||
@@ -45,7 +30,9 @@ def get_stocks_data():
|
||||
symbol = random.choice(["AAPL", "NVDA", "MSFT", "TSLA", "AMZN", "V"]) # noqa: S311
|
||||
provider = random.choice(["fmp", "intrinio", "polygon", "yfinance"]) # noqa: S311
|
||||
|
||||
data["stocks_data"] = get_data("stocks", symbol=symbol, provider=provider)
|
||||
data["stocks_data"] = get_data(
|
||||
"stocks", symbol=symbol, provider=provider, headers=headers
|
||||
)
|
||||
return data["stocks_data"]
|
||||
|
||||
|
||||
@@ -57,7 +44,9 @@ def get_crypto_data():
|
||||
symbol = random.choice(["BTC"]) # noqa: S311
|
||||
provider = random.choice(["fmp"]) # noqa: S311
|
||||
|
||||
data["crypto_data"] = get_data(menu="crypto", symbol=symbol, provider=provider)
|
||||
data["crypto_data"] = get_data(
|
||||
menu="crypto", symbol=symbol, provider=provider, headers=headers
|
||||
)
|
||||
return data["crypto_data"]
|
||||
|
||||
|
||||
|
||||
13
openbb_platform/extensions/tests/utils/helpers.py
Normal file
13
openbb_platform/extensions/tests/utils/helpers.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import base64
|
||||
|
||||
from openbb_core.env import Env
|
||||
|
||||
|
||||
def get_auth() -> str:
|
||||
"""Returns the basic auth header."""
|
||||
|
||||
userpass = f"{Env().API_USERNAME}:{Env().API_PASSWORD}"
|
||||
userpass_bytes = userpass.encode("ascii")
|
||||
base64_bytes = base64.b64encode(userpass_bytes)
|
||||
|
||||
return f"Basic {base64_bytes.decode('ascii')}"
|
||||
@@ -24,21 +24,12 @@ def write_init_test_template(http_method: str, path: str):
|
||||
template += """
|
||||
import pytest
|
||||
import requests
|
||||
from extensions.tests.utils.helpers import get_auth
|
||||
from openbb_provider.utils.helpers import get_querystring
|
||||
|
||||
|
||||
def get_token():
|
||||
return requests.post(
|
||||
"http://0.0.0.0:8000/api/v1/account/token",
|
||||
data={"username": "openbb", "password": "openbb"},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def headers():
|
||||
access_token = get_token().json()["access_token"]
|
||||
return {"Authorization": f"Bearer {access_token}"}
|
||||
return {"Authorization": get_auth()}
|
||||
"""
|
||||
|
||||
with open(path, "w") as f:
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
# TODO: See if we can dynamically import the test modules under the openbb_platform
|
||||
# file structure.
|
||||
# f
|
||||
|
||||
# TODO: Add global fixture for headers here
|
||||
|
||||
Reference in New Issue
Block a user