forked from Clueless-Community/fintech-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
108 lines (85 loc) · 3.13 KB
/
test_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from main import app
from fastapi import FastAPI
from fastapi.testclient import TestClient
import json
@app.get("/")
async def read_main():
return {"msg": "Hello World"}
client = TestClient(app)
def test_certificate_of_deposit():
response = client.get(
"/certificate_of_deposit/?principal_amount=5000.0&interest_rate=5.0&yrs=3&compounding_per_yr=1"
)
assert response.status_code == 200
assert response.json() == {
"Tag": "Certificate of Deposit (CD)",
"Principal amount": 5000.0,
"Interest Rate": 5.0,
"Time in Years": 3,
"Number of Compounding per Year": 1,
"Certificate of Deposit (CD)": "5788.125000000001",
}
# Compounding per year cannot be 0, as it is division by 0 error
def test_certificate_of_deposit_invalid_value():
response = client.get(
"/certificate_of_deposit/?principal_amount=5000.0&interest_rate=5.0&yrs=3&compounding_per_yr=0"
)
assert response.json()["status_code"] == 500
# Years cannot be a float, as it is a type error
def test_certificate_of_deposit_invalid_type():
response = client.get(
"/certificate_of_deposit/?principal_amount=5000.0&interest_rate=5.0&yrs=3.5&compounding_per_yr=1"
)
assert response.json() == {
"detail": [
{
"loc": ["query", "yrs"],
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
}
def test_simple_interest_rate_main():
response = client.get(
"/simple_interest_rate/?amount_paid=5000&principle_amount=4500&months=12"
)
assert response.status_code == 200
assert response.json() == {
"Tag": "Simple Interest Rate",
"Total amount paid": 5000,
"Principle amount": 4500,
"Interest Paid": 500,
"Interest Rate": f"11.11111111111111%",
}
def test_roi_main():
response = client.get("/roi/?current_value_of_investment=100&cost_of_investment=80")
assert response.status_code == 200
assert response.json() == {
"Tag": "Return on Investment",
"Current Value of Investment": 100,
"Cost of Investment": 80,
"Return on Investment": f"25.0%",
}
def test_calculate_enterprise_value_main():
response = client.get(
"/enterprise-value/?share_price=10.00&fully_diluted_shares_outstanding=100&total_debt=500.00&preferred_stock=500.00&non_controlling_interest=1000.00&cash_and_cash_equivalents=1000.00"
)
assert response.status_code == 200
assert response.json() == {
"Tag": "Enterprise Value",
"Equity Value": 1000,
"Total Debt": 500,
"Preferred Stock": 500,
"Non-Controlling Interest": 1000,
"Cash & Cash Equivalents": 1000,
"Enterprise Value": 2000,
}
def test_calculate_treynor_ratio():
response = client.get("/calculate_treynor_ratio/?returns=0.1,0.05,0.08,0.12,0.09&risk_free_rate=0.03")
assert response.status_code == 200
assert response.json() == {
"Tag": "Treynor Ratio",
"returns": [0.1, 0.05, 0.08, 0.12, 0.09],
"risk_free_rate": 0.03,
"treynor_ratio": 1.6
}