/
test_all.py
100 lines (78 loc) · 1.92 KB
/
test_all.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
import pytest
import requests
import json
import sys
sys.path.insert(1, './StockInfoPackage/')
import FinnhubStockManager as SM
import DatabaseManager as DM
import InfoManager as IM
import LocalDataManager as LM
import WebSecurity as WS
'''
Test helpers
'''
GENERIC_STOCK_NAME = 'AAPL'
RARE_STOCK_NAME = 'GM'
def about_equals(val_a, val_b, errorRange = 0.1):
return abs(val_a - val_b) < errorRange
'''
StockManager Tests
'''
def test_quote():
assert len(SM.getQuote(GENERIC_STOCK_NAME).keys()) != 0
def test_candle():
assert len(SM.getCandle(GENERIC_STOCK_NAME).keys()) != 0
'''
DatabaseManager Tests
'''
def test_store_db():
candle = SM.getCandle(RARE_STOCK_NAME)
candle["timeframe"] = "Y"
candle["quality"] = "high"
isStore = True
try:
DM.storeData(RARE_STOCK_NAME, candle)
except:
isStore = False
assert isStore
def test_get_db():
data = DM.getData(RARE_STOCK_NAME, "Y").keys()
assert len(data) != 0
def test_delete_db():
isDelete = True
try:
DM.removeData(RARE_STOCK_NAME, "Y")
except:
isDelete = False
assert isDelete
'''
LocalDataManager Tests
'''
def test_store_ls():
candle = SM.getCandle(RARE_STOCK_NAME)
candle["timeframe"] = "Y"
candle["quality"] = "high"
isStore = True
try:
LM.putData(RARE_STOCK_NAME, candle)
except:
isStore = False
assert isStore
def test_get_ls():
data = LM.getData(RARE_STOCK_NAME, "Y").keys()
assert len(data) != 0
'''
Web Security Tests
'''
zero_token = WS.getNewSessionID(0)
good_token = WS.getNewSessionID()
def test_session_token():
#Create a session with no lifetime
assert type(zero_token) == str
assert len(zero_token) > 10
def test_session_lifetime():
assert not WS.isSessionStored(zero_token)
assert WS.isSessionStored(good_token)
def test_clean_session_memory():
WS.resetStorage()
assert not WS.isSessionStored(good_token)