mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-02 07:23:25 +00:00
* quick econ fix * black * keys and feature flags * terminal name 👀 * some more replacements * some more replacements * edit pyproject * gst -> openbb * add example portfolios back to git * Update api from gst * sorry. skipping some tests * another round of names * another round of test edits * Missed some .gst refs and update timezone * water mark stuff * Fixing Names in terminal.spec and name of GTFF_DEFAULTS to OBBFF_DEFAULTS * fix more GST to OpenBB Terminal * Logging : merge conflicts with main * Revert wrong files Co-authored-by: Andrew <andrew.kenreich@gmail.com> Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt> Co-authored-by: Chavithra PARANA <chavithra@gmail.com>
95 lines
2.3 KiB
Python
95 lines
2.3 KiB
Python
# IMPORTATION STANDARD
|
|
import gzip
|
|
import json
|
|
|
|
# IMPORTATION THIRDPARTY
|
|
import pandas as pd
|
|
import pytest
|
|
|
|
# IMPORTATION INTERNAL
|
|
from openbb_terminal.cryptocurrency.defi import llama_model
|
|
|
|
|
|
def filter_json_data(response):
|
|
"""To reduce cassette size."""
|
|
|
|
headers = response["headers"]
|
|
if "FILTERED" in headers:
|
|
return response
|
|
|
|
limit = 10
|
|
content = response["body"]["string"]
|
|
|
|
if content.decode().startswith("H4sI"):
|
|
content = gzip.decompress(content).decode()
|
|
content = json.loads(content)
|
|
else:
|
|
content = json.loads(content)
|
|
|
|
if isinstance(content, list):
|
|
new_content = content[:limit]
|
|
elif isinstance(content, dict):
|
|
new_content = {k: content[k] for k in list(content)[:limit]}
|
|
else:
|
|
raise AttributeError(f"Content type not supported : {content}")
|
|
|
|
new_content_json = json.dumps(new_content)
|
|
new_content_gz = gzip.compress(new_content_json.encode())
|
|
response["body"]["string"] = new_content_gz
|
|
|
|
response["headers"]["Content-Encoding"] = ["gzip"]
|
|
response["headers"]["FILTERED"] = ["TRUE"]
|
|
|
|
return response
|
|
|
|
|
|
def gzip_data(response):
|
|
"""To reduce cassette size."""
|
|
|
|
headers = response["headers"]
|
|
if "COMPRESSED" in headers:
|
|
return response
|
|
|
|
content = response["body"]["string"].decode()
|
|
|
|
if content.startswith("H4sI"):
|
|
content = gzip.decompress(content)
|
|
|
|
new_content_gz = gzip.compress(content.encode())
|
|
response["body"]["string"] = new_content_gz
|
|
|
|
response["headers"]["Content-Encoding"] = ["gzip"]
|
|
response["headers"]["COMPRESSED"] = ["TRUE"]
|
|
|
|
return response
|
|
|
|
|
|
@pytest.mark.vcr(before_record_response=gzip_data)
|
|
@pytest.mark.vcr
|
|
@pytest.mark.parametrize(
|
|
"protocol",
|
|
[
|
|
"anchor",
|
|
],
|
|
)
|
|
def test_get_defi_protocol(protocol, recorder):
|
|
df = llama_model.get_defi_protocol(protocol)
|
|
recorder.capture(df)
|
|
|
|
|
|
@pytest.mark.vcr(before_record_response=filter_json_data)
|
|
def test_get_defi_protocols():
|
|
df = llama_model.get_defi_protocols()
|
|
|
|
# recorder not used
|
|
# somehow there are some whitespace diff between captured/recorded
|
|
assert isinstance(df, pd.DataFrame)
|
|
assert not df.empty
|
|
|
|
|
|
@pytest.mark.skip
|
|
@pytest.mark.vcr(before_record_response=gzip_data)
|
|
def test_get_defi_tvl(recorder):
|
|
df = llama_model.get_defi_tvl()
|
|
recorder.capture(df)
|