-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_test.py
210 lines (173 loc) · 6.3 KB
/
table_test.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
from appHolder import db
import unittest, datetime, sys, os
from random import randint
from budg_tables import create_a_thing,Account, CashFlow, Expense, Transfer, Actual
'''this file runs some tests on the budget tables created
'''
class test1_accountTests(unittest.TestCase):
'''tests run on the account to verify random things are working
'''
def test001_addAccount(self):
'''adds an account
'''
name="TESTACCOUNT"+str(randint(0,100))
create_a_thing(Account,[name,100])
self.assertTrue(db.session.query(Account).filter_by(title=name).all()!=[])
def test002_displayAccounts(self):
'''test to display available accounts and their expense data
'''
accs=db.session.query(Account)
for acc in accs:
print '--------------------'
print acc
self.assertTrue(True)
class test2_expenseTests(unittest.TestCase):
def test001_addExpense(self):
#create an account
name="TestExpense"+str(randint(0,100))
acc=db.session.query(Account).all()[0]
create_a_thing(Expense,[acc.id,name,5,datetime.datetime.today()])
self.assertTrue(db.session.query(Expense).filter_by(title=name).all()!=[])
def test002_displayExpenses(self):
#acc=db.session.query(Account).all()[0]
exps=db.session.query(Expense).all()
for exp in exps:
print '--------------------'
print exp
self.assertTrue(True)
class test3_transferTests(unittest.TestCase):
def test001_addTransfer(self):
#create an account
acc=db.session.query(Account).all()
if len(acc)<2:
create_a_thing(Account,["TESTACCOUNT"+str(randint(0,100)),100])
acc=db.session.query(Account).all()
acc1=acc[0]
acc2=acc[1]
create_a_thing(Transfer,['TestTransfer'+str(randint(0,100)),50,acc1.id,acc2.id,datetime.datetime.today()])
self.assertTrue(True)
def test002_displayTransfer(self):
#acc=db.session.query(Account).all()[0]
tf=db.session.query(Transfer).all()[0]
print '--------------------'
print tf
print tf.date.date()
self.assertTrue(True)
def test003_reverseTrackTransfer(self0:
'''a test to find the transfers associated with an account'''
pass
class test4_cashFlowTests(unittest.TestCase):
'''
tests run to verify the cashflows are working
'''
def test001_addCashFlow(self):
#create an account
name="TestCashFlow"+str(randint(0,100))
acc=db.session.query(Account).all()[0]
oneYear=datetime.datetime.today()+datetime.timedelta(365)
create_a_thing(CashFlow,[acc.id,name,500,datetime.datetime.today(),"Day",10,oneYear])
self.assertTrue(db.session.query(CashFlow).filter_by(title=name).all()!=[])
def test002_displayCashFlow(self):
#acc=db.session.query(Account).all()[0]
cfs=db.session.query(CashFlow).all()
for cf in cfs:
print '--------------------'
print cf
self.assertTrue(True)
def test003_estimateTest(self):
'''
this will test the ability of the cashflow to create an associated estimate
'''
today=datetime.datetime.today()
oneYear=today+datetime.timedelta(365)
acc=db.session.query(Account).all()[0]
create_a_thing(CashFlow,[acc.id,"Groceries",-100,datetime.datetime.today(),"Week",1,oneYear,True])
cf=db.session.query(CashFlow).filter_by(title="Groceries").all()[0]
ind_cf=cf.createSeries()[0]
create_a_thing(Actual,[cf.id,cf.title+"_"+str(ind_cf.date.date()),-90,ind_cf.date,today])
actual=db.session.query(Actual).all()[0]
#the new series value which we replaced should reflect the estamate value
if cf.createSeries()[0].value==actual.value and cf.createSeries()[0].date==actual.date:
print "**CASHFLOW[0]**"
print cf.createSeries()[0]
print "**ACTUAL**"
print actual
self.assertTrue(True)
else:
print "**CASHFLOW[0]**"
print cf.createSeries()[0]
print "**ACTUAL**"
print actual
self.assertTrue(False)
class test5_checkSum(unittest.TestCase):
'''tests run on the account to verify random things are working
'''
tomorrow=datetime.datetime.today()+datetime.timedelta(1) #a date for summing purposes
def test001_checkExpenses(self):
'''this function will validate the expense values are totaled in the getExpense function
'''
accs=db.session.query(Account).all()
exps=db.session.query(Expense)
for acc in accs:
total=0
exps_a=exps.filter_by(account_id=acc.id).all() #all expenses associated with acc
for exp in exps_a:
total+=exp.value
if total!=acc.getExpenseValues(self.tomorrow):
print "Manual total: %s"%total
print "Automat total: %s"%acc.getExpenseValues(self.tomorrow)
self.assertTrue(False)
self.assertTrue(True)
def test002_checkTransfers(self):
'''
test to validate the transfers are effecting the accounts as they should be
'''
tfs=db.session.query(Transfer).all()
accs=db.session.query(Account).all()
#db.session.query(Transfer).filter_by(f_account_id=accs[0].id).all()
for thing in accs:
print "*************"
print "Account: %s"%thing.id
print thing.getTransfers()
print thing.getTransferValues()
self.assertTrue(True)
def test003_checkAll(self):
'''
this function checks to verify all of the items affecting an account are tallied up in
the account datevalue function
'''
exps=db.session.query(Expense).all()
cfs=db.session.query(CashFlow).all()
tfs=db.session.query(Transfer).all()
accs=db.session.query(Account).all()
oneYear=datetime.datetime.today()+datetime.timedelta(365)
for acc in accs:
transTotal=acc.getTransferValues(oneYear)[0]+acc.getTransferValues(oneYear)[1]
cfTotal=acc.getPaymentValues(oneYear)
expsTotal=acc.getExpenseValues(oneYear)
if acc.getDateValue(oneYear)!=acc.entVal+expsTotal+transTotal+cfTotal: self.assertTrue(False)
else:
print "*****************"
print "Account: %s"%acc.title
print "Value: %s"%acc.getDateValue(oneYear)
print "Start Amount: %s"%acc.entVal
print "Total transfered: %s"%transTotal
print "Total CashFlow: %s"%cfTotal
print "Total Expense: %s"%expsTotal
self.assertTrue(True)
def clear_test_db():
path="C:\\Users\Charles\Dropbox\Programming\DataBases\\budget.db"
if os.path.exists(path):
os.remove(path)
db.create_all()
def main():
'''from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
path="Users/Charles/Dropbox/Programming/DataBases/budget.db"
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////'+path
db = SQLAlchemy(app)'''
clear_test_db()
unittest.main()
if __name__=="__main__":
main()