Add basic testing for new etf endpoints

This commit is contained in:
nectariosouzo
2023-09-27 14:05:02 -04:00
parent 0e4252efee
commit c57a82bed7
12 changed files with 378 additions and 2 deletions

View File

@@ -71,7 +71,6 @@ def get_stock_price_change(ticker: str, start_date: str, end_date: str) -> float
"""
current_user = get_current_user()
url = f'''https://financialmodelingprep.com/api/v3/historical-price-full/{ticker}?from={start_date}&to={end_date}&serietype=line&apikey={current_user.credentials.API_KEY_FINANCIALMODELINGPREP}'''
response = request(url)
if response.status_code != 200 or "Error Message" in response.json():
message = f"Error, Status Code: {response.status_code}."
@@ -117,7 +116,7 @@ def get_etf_holdings(ticker: str) -> List[Dict[str,any]]:
else message + "\n" + response.json()["Error Message"] + ".\n"
)
console.print(message)
return None
return []
return response.json()
@@ -137,6 +136,8 @@ def get_holdings_pct_change(ticker: str, start_date: str, end_date: str) -> pd.D
Calculated percentage change for each stock in the ETF, in descending order.
"""
holdings = get_etf_holdings(ticker=ticker)
if len(holdings) == 0:
return pd.DataFrame()
data_list = []
for stock in holdings:
if stock['asset']:

View File

@@ -2,6 +2,7 @@ etf
load spy
overview
holdings
holdings_perf --limit 3
weights
weights --raw
candle

View File

@@ -0,0 +1,48 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
method: GET
uri: https://financialmodelingprep.com/api/v3/etf-holder/ARKK?apikey=MOCK_API_KEY
response:
body:
string: "{\n \"Error Message\": \"Invalid API KEY. Please retry or visit our
documentation to create one FREE https://site.financialmodelingprep.com/developer/docs\"\n}"
headers:
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Headers:
- X-Requested-With, content-type, auth-token, Authorization, stripe-signature,
APPS
Access-Control-Allow-Methods:
- GET, POST, OPTIONS
Access-Control-Allow-Origin:
- '*'
Access-Control-Max-Age:
- '3600'
Connection:
- keep-alive
Content-Length:
- '154'
Content-Type:
- application/json; charset=utf-8
Date:
- Wed, 27 Sep 2023 14:51:51 GMT
ETag:
- W/"9a-ufKRTAmgqkT6Vv3bqU5trChBRE8"
Server:
- nginx/1.18.0 (Ubuntu)
X-Frame-Options:
- SAMEORIGIN
X-Powered-By:
- Express
status:
code: 401
message: Unauthorized
version: 1

View File

@@ -0,0 +1,48 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
method: GET
uri: https://financialmodelingprep.com/api/v3/etf-holder/VTI?apikey=MOCK_API_KEY
response:
body:
string: "{\n \"Error Message\": \"Invalid API KEY. Please retry or visit our
documentation to create one FREE https://site.financialmodelingprep.com/developer/docs\"\n}"
headers:
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Headers:
- X-Requested-With, content-type, auth-token, Authorization, stripe-signature,
APPS
Access-Control-Allow-Methods:
- GET, POST, OPTIONS
Access-Control-Allow-Origin:
- '*'
Access-Control-Max-Age:
- '3600'
Connection:
- keep-alive
Content-Length:
- '154'
Content-Type:
- application/json; charset=utf-8
Date:
- Wed, 27 Sep 2023 14:40:52 GMT
ETag:
- W/"9a-ufKRTAmgqkT6Vv3bqU5trChBRE8"
Server:
- nginx/1.18.0 (Ubuntu)
X-Frame-Options:
- SAMEORIGIN
X-Powered-By:
- Express
status:
code: 401
message: Unauthorized
version: 1

View File

@@ -0,0 +1,94 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
method: GET
uri: https://financialmodelingprep.com/api/v3/etf-holder/ARKK?apikey=MOCK_API_KEY
response:
body:
string: "{\n \"Error Message\": \"Invalid API KEY. Please retry or visit our
documentation to create one FREE https://site.financialmodelingprep.com/developer/docs\"\n}"
headers:
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Headers:
- X-Requested-With, content-type, auth-token, Authorization, stripe-signature,
APPS
Access-Control-Allow-Methods:
- GET, POST, OPTIONS
Access-Control-Allow-Origin:
- '*'
Access-Control-Max-Age:
- '3600'
Connection:
- keep-alive
Content-Length:
- '154'
Content-Type:
- application/json; charset=utf-8
Date:
- Wed, 27 Sep 2023 17:42:35 GMT
ETag:
- W/"9a-ufKRTAmgqkT6Vv3bqU5trChBRE8"
Server:
- nginx/1.18.0 (Ubuntu)
X-Frame-Options:
- SAMEORIGIN
X-Powered-By:
- Express
status:
code: 401
message: Unauthorized
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
method: GET
uri: https://financialmodelingprep.com/api/v3/etf-holder/ARKK?apikey=MOCK_API_KEY
response:
body:
string: "{\n \"Error Message\": \"Invalid API KEY. Please retry or visit our
documentation to create one FREE https://site.financialmodelingprep.com/developer/docs\"\n}"
headers:
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Headers:
- X-Requested-With, content-type, auth-token, Authorization, stripe-signature,
APPS
Access-Control-Allow-Methods:
- GET, POST, OPTIONS
Access-Control-Allow-Origin:
- '*'
Access-Control-Max-Age:
- '3600'
Connection:
- keep-alive
Content-Length:
- '154'
Content-Type:
- application/json; charset=utf-8
Date:
- Wed, 27 Sep 2023 17:43:14 GMT
ETag:
- W/"9a-ufKRTAmgqkT6Vv3bqU5trChBRE8"
Server:
- nginx/1.18.0 (Ubuntu)
X-Frame-Options:
- SAMEORIGIN
X-Powered-By:
- Express
status:
code: 401
message: Unauthorized
version: 1

View File

@@ -0,0 +1,48 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
method: GET
uri: https://financialmodelingprep.com/api/v3/etf-holder/TSLA?apikey=MOCK_API_KEY
response:
body:
string: "{\n \"Error Message\": \"Invalid API KEY. Please retry or visit our
documentation to create one FREE https://site.financialmodelingprep.com/developer/docs\"\n}"
headers:
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Headers:
- X-Requested-With, content-type, auth-token, Authorization, stripe-signature,
APPS
Access-Control-Allow-Methods:
- GET, POST, OPTIONS
Access-Control-Allow-Origin:
- '*'
Access-Control-Max-Age:
- '3600'
Connection:
- keep-alive
Content-Length:
- '154'
Content-Type:
- application/json; charset=utf-8
Date:
- Wed, 27 Sep 2023 17:42:36 GMT
ETag:
- W/"9a-ufKRTAmgqkT6Vv3bqU5trChBRE8"
Server:
- nginx/1.18.0 (Ubuntu)
X-Frame-Options:
- SAMEORIGIN
X-Powered-By:
- Express
status:
code: 401
message: Unauthorized
version: 1

View File

@@ -0,0 +1,48 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
method: GET
uri: https://financialmodelingprep.com/api/v3/etf-holder/TSLA?apikey=MOCK_API_KEY
response:
body:
string: "{\n \"Error Message\": \"Invalid API KEY. Please retry or visit our
documentation to create one FREE https://site.financialmodelingprep.com/developer/docs\"\n}"
headers:
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Headers:
- X-Requested-With, content-type, auth-token, Authorization, stripe-signature,
APPS
Access-Control-Allow-Methods:
- GET, POST, OPTIONS
Access-Control-Allow-Origin:
- '*'
Access-Control-Max-Age:
- '3600'
Connection:
- keep-alive
Content-Length:
- '154'
Content-Type:
- application/json; charset=utf-8
Date:
- Wed, 27 Sep 2023 17:52:02 GMT
ETag:
- W/"9a-ufKRTAmgqkT6Vv3bqU5trChBRE8"
Server:
- nginx/1.18.0 (Ubuntu)
X-Frame-Options:
- SAMEORIGIN
X-Powered-By:
- Express
status:
code: 401
message: Unauthorized
version: 1

View File

@@ -0,0 +1 @@
[]

View File

@@ -28,3 +28,66 @@ def test_get_etf_sector_weightings(recorder, name):
result = fmp_model.get_etf_sector_weightings(name)
recorder.capture(result)
@pytest.mark.vcr
@pytest.mark.parametrize(
"ticker",
[
"ARKK",
],
)
def test_get_etf_holdings(recorder, ticker):
result = fmp_model.get_etf_holdings(ticker)
assert result.count != 0
recorder.capture(result)
@pytest.mark.vcr(record_mode='all')
@pytest.mark.parametrize(
"ticker",
[
"ARKK",
],
)
@pytest.mark.parametrize(
"start_date",
[
"2022-09-01",
],
)
@pytest.mark.parametrize(
"end_date",
[
"2023-09-01",
],
)
def test_get_holdings_pct_change(recorder, ticker: str, start_date: str, end_date: str):
result = fmp_model.get_holdings_pct_change(ticker, start_date, end_date)
assert result.empty
recorder.capture(result)
@pytest.mark.vcr
@pytest.mark.parametrize(
"ticker",
[
"TSLA",
],
)
@pytest.mark.parametrize(
"start_date",
[
"2022-09-01",
],
)
@pytest.mark.parametrize(
"end_date",
[
"2023-09-01",
],
)
def test_get_stock_price_change(recorder, ticker: str, start_date: str, end_date: str):
result = fmp_model.get_holdings_pct_change(ticker, start_date, end_date)
recorder.capture(result)

View File

@@ -24,3 +24,25 @@ def vcr_config():
)
def test_display_etf_weightings(name):
fmp_view.display_etf_weightings(name, raw=True, export="")
@pytest.mark.vcr
@pytest.mark.parametrize(
"ticker",
[
"TSLA",
],
)
@pytest.mark.parametrize(
"start_date",
[
"2022-09-01",
],
)
@pytest.mark.parametrize(
"end_date",
[
"2023-09-01",
],
)
def test_view_etf_holdings_performance(ticker, start_date, end_date):
fmp_view.view_etf_holdings_performance(ticker, start_date, end_date, raw=True, export="")