def test_many_coupon_same_user(self): """ Test with many coupons of the same uid. Expect output to match correct data. """ rc1 = Redeemed_Coupons(rcid=121, cid=32, uid=12, rid=12, valid=1) rc2 = Redeemed_Coupons(rcid=131238, cid=36, uid=12, rid=12, valid=1) db.session.add(rc1) db.session.add(rc2) db.session.commit() rcid1 = rchelper.find_rcid_by_cid_and_uid(rc1.cid, rc1.uid) rcid2 = rchelper.find_rcid_by_cid_and_uid(rc2.cid, rc2.uid) self.assertEqual(rcid1, rc1.rcid) self.assertEqual(rcid2, rc2.rcid)
def test_mult_coupon_first_valid(self): """ Test for multi redeemed coupons with same cid owned by the same user Check if it returns the first valid coupon (rcid) """ rc1 = Redeemed_Coupons(rcid=121, cid=32, uid=12, rid=12, valid=0) rc2 = Redeemed_Coupons(rcid=125, cid=32, uid=12, rid=12, valid=1) rc3 = Redeemed_Coupons(rcid=129, cid=32, uid=12, rid=12, valid=1) db.session.add(rc1) db.session.add(rc2) db.session.add(rc3) db.session.commit() rcid = rchelper.find_rcid_by_cid_and_uid(32, 12) self.assertEqual(rcid, rc2.rcid)
def test_invalid_coupon(self): """ Test function also works on invalid coupon. Expect data in database remain the same """ rc1 = Redeemed_Coupons(cid=32, uid=12, rid=12, valid=0) db.session.add(rc1) db.session.commit() rchelper.mark_redeem_coupon_used_by_rcid(1) self.assertEqual(rc1.valid, 0)
def test_valid_coupon(self): """ Test mark on one valid coupon. Expect output to match correct data. """ rc = Redeemed_Coupons(cid=32, uid=12, rid=12, valid=1) db.session.add(rc) db.session.commit() rchelper.mark_redeem_coupon_used_by_rcid(1) self.assertEqual(rc.valid, 0)
def test_coupon_invalid_coupon(self): """ Test coupon with cid and uid but not valid. Expect an error message. """ rc = Redeemed_Coupons(rcid=121, cid=32, uid=12, rid=12, valid=0) db.session.add(rc) db.session.commit() rcid = rchelper.find_rcid_by_cid_and_uid(32, 12) self.assertEqual(rcid, "Not Found")
def test_coupon_diff_user(self): """ Test coupon not redeemed by given user. Expect an error message. """ rc = Redeemed_Coupons(rcid=121, cid=32, uid=12, rid=12, valid=1) db.session.add(rc) db.session.commit() rcid = rchelper.find_rcid_by_cid_and_uid(32, 10) self.assertEqual(rcid, "Not Found")
def test_one_coupon(self): """ Test with one standard coupon. Expect output to match correct data. """ rc = Redeemed_Coupons(rcid=18, cid=32, uid=12, rid=12, valid=1) db.session.add(rc) db.session.commit() rcid = rchelper.find_rcid_by_cid_and_uid(rc.cid, rc.uid) self.assertEqual(rcid, rc.rcid)
def insert_redeemed_coupon(cid, uid, rid): """ Insert a redeemed coupon to database Args: cid: The coupon ID that corresponds to the Coupon that is fetched. uid: The user ID that corresponds to the User that is fetched. rid: The restaurant ID that corresponds to the Restaurant that is fetched. Returns: the rcid of the inserted coupon """ coupon = Redeemed_Coupons(cid=cid, uid=uid, rid=rid, valid=1) db.session.add(coupon) db.session.commit() return coupon.rcid