-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_upd_employee_salary.py
63 lines (44 loc) · 1.9 KB
/
test_upd_employee_salary.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
import sys, unittest
import logic_bank_utils.util as logic_bank_utils
from datetime import datetime
from decimal import Decimal
(did_fix_path, sys_env_info) = \
logic_bank_utils.add_python_path(project_dir="LogicBank", my_file=__file__)
if __name__ == '__main__':
print("\nStarted from cmd line - launch unittest and exit\n")
sys.argv = [sys.argv[0]]
unittest.main(module="examples.nw.tests.test_update_employee_salary")
exit(0)
else:
print("Started from unittest: " + __name__)
from examples.nw import tests
tests.copy_gold_over_db()
import examples.nw.db.models as models
from examples.nw.logic import session, engine # opens db, activates rules <--
# activate rules: LogicBank.activate(session=session, activator=declare_logic)
from logic_bank.util import prt
print("\n" + sys_env_info + "\n\n")
class Test(unittest.TestCase):
def setUp(self): # banner
self.started_at = str(datetime.now())
tests.setUp(file=__file__)
def tearDown(self):
tests.tearDown(file=__file__, started_at=self.started_at, engine=engine, session=session)
def test_run(self):
""" Test State Transition Logic - raise over 20%
should fail due to credit limit exceeded (catch exception to verify)
"""
bad_employee_raise = session.query(models.Employee).filter(models.Employee.Id == 1).one()
bad_employee_raise.Salary = bad_employee_raise.Salary * Decimal('1.1')
did_fail_as_expected = False
try:
session.commit()
except:
session.rollback()
did_fail_as_expected = True
if not did_fail_as_expected:
self.fail("too-small should have failed constraint, but succeeded")
else:
print("\n" + prt("puny raise failed constraint as expected."))
print("\nupd_employee_salary, ran to completion")
self.assertTrue(True)