def test_giveback(self): model = model_giveback.ModelGiveback() model.get_borrnow = mock.Mock(return_value=None) self.assertFalse(model.giveback("", "")) borrnow = mock.Mock() model.get_borrnow = mock.Mock(return_value=borrnow) model.get_bookins = mock.Mock(return_value=None) self.assertFalse(model.giveback("", "")) self.assertEqual(borrnow, model.borrnow) bookins = mock.Mock() model.get_bookins = mock.Mock(return_value=bookins) model.get_reader = mock.Mock(return_value=None) self.assertFalse(model.giveback("", "")) self.assertEqual(bookins, model.bookins) reader = mock.Mock() model.get_reader = mock.Mock(return_value=reader) model.calc_overdays = mock.Mock(return_value=0) model.calc_overprice = mock.Mock(return_value=0) model.post_giveback = mock.Mock() model.log = mock.Mock() self.assertTrue(model.giveback("", "")) self.assertEqual(reader, model.reader) self.assertTrue(model.post_giveback.called) self.assertTrue(model.log.called)
def test_calc_overprice(self): model = model_giveback.ModelGiveback() self.assertEqual(0, model.calc_overprice(0, None)) self.assertEqual(0, model.calc_overprice(-1, None)) overdays = 12 reader = mock.Mock(typoverprice=0.3) self.assertEqual(12 * 0.3, model.calc_overprice(overdays, reader))
def get_bookins(self): fn_db.ins("LIT_BORRNOW", readerid="T_R_NO", readercardno="T_C_NO", bookinsid="T_BI5", renewtimes=1) model = model_giveback.ModelGiveback() self.assertFalse(model.giveback("operator", "T_BI5")) self.assertNotEqual(model.bookins, None)
def test_calc_overdays(self): model = model_giveback.ModelGiveback() borrnow = mock.Mock() days = 12 borrnow.borrexpdt = datetime.datetime.now() + datetime.timedelta( days=days) self.assertEqual(0 - days, model.calc_overdays(borrnow)) borrnow.borrexpdt = datetime.datetime.now() - datetime.timedelta( days=days) self.assertEqual(days, model.calc_overdays(borrnow))
def deface_cash(self): fn_db.db.delete("LIT_BORRLOG", where="borrhisid='T_HIS_deface_cash'") kw = dict(borrhisid="T_HIS_deface_cash", insby="operator", updby="operator", readerid="T_R02", readercardno="T_C02", bookinsid="T_BI1") fn_db.ins("LIT_BORRHIS", **kw) model = model_giveback.ModelGiveback() model.deface("operator2", "T_HIS_deface_cash", 12.5, "CASH", "NOTE") borrhis = model.get_borrhis("T_HIS_deface_cash") self.assertEqual(borrhis.defaceprice, 12.5) self.assertEqual(borrhis.defacepaycd, "CASH") self.assertEqual(borrhis.defacenote, "NOTE") log = fn_db.db.select( "LIT_BORRLOG", where="borrhisid='T_HIS_deface_cash' and actcd='DEFACE'")[0] self.assertEqual(log.paycd, "CASH") self.assertEqual(log.actval, 12.5)
def overdue_cash(self): fn_db.db.delete("LIT_BORRLOG", where="borrhisid='T_HIS_overdue_cash'") kw = dict(borrhisid="T_HIS_overdue_cash", insby="operator", updby="operator", readerid="T_R02", readercardno="T_C02", bookinsid="T_BI1", overprice=12.5) fn_db.ins("LIT_BORRHIS", **kw) model = model_giveback.ModelGiveback() model.overdue("operator2", "T_HIS_overdue_cash", "CASH") borrhis = model.get_borrhis("T_HIS_overdue_cash") self.assertEqual(borrhis.overprice, 12.5) self.assertEqual(borrhis.overpaycd, "CASH") log = fn_db.db.select( "LIT_BORRLOG", where="borrhisid='T_HIS_overdue_cash' and actcd='OVERDUE'")[0] self.assertEqual(log.paycd, "CASH") self.assertEqual(log.actval, 12.5)
def deface_acc(self): fn_db.db.delete("LIT_BORRLOG", where="borrhisid='T_HIS_deface_acc'") kw = dict(borrhisid="T_HIS_deface_acc", insby="operator", updby="operator", readerid="T_R02", readercardno="T_C02", bookinsid="T_BI1") fn_db.ins("LIT_BORRHIS", **kw) fn_db.upd("LIM_READER", "readerid", "T_R02", deposit=100) model = model_giveback.ModelGiveback() model.deface("operator2", "T_HIS_deface_acc", 12.5, "ACC", "NOTE") self.assertEqual( fn_db.get("LIM_READER", "readerid", "T_R02").deposit, 100 - 12.5) borrhis = model.get_borrhis("T_HIS_deface_acc") self.assertEqual(borrhis.defaceprice, 12.5) self.assertEqual(borrhis.defacepaycd, "ACC") self.assertEqual(borrhis.defacenote, "NOTE") log = fn_db.db.select( "LIT_BORRLOG", where="borrhisid='T_HIS_deface_acc' and actcd='DEFACE'")[0] self.assertEqual(log.paycd, "ACC") self.assertEqual(log.actval, 12.5)
def model(self): return model_giveback.ModelGiveback()
def giveback_over(self): model = model_giveback.ModelGiveback() self.assertTrue(model.giveback("operator", "T_BI6"))
def get_borrnow(self): model = model_giveback.ModelGiveback() self.assertFalse(model.giveback("operator", "NO")) self.assertFalse(model.giveback("operator", "T_BI_NO")) self.assertNotEqual(model.borrnow, None)