def test_overlap_with_others(self): """Test unit overlap with others for updating""" start1 = datetime.strptime('2018-09-01 17:00:00', "%Y-%m-%d %H:%M:%S") end1 = datetime.strptime('2019-09-15 17:00:00', '%Y-%m-%d %H:%M:%S') start2 = datetime.strptime('2019-09-01 17:00:00', '%Y-%m-%d %H:%M:%S') end2 = datetime.strptime('2019-09-15 17:00:00', '%Y-%m-%d %H:%M:%S') v1 = Voucher(code='SNSD', value=5000, start=start1, end=end1) v2 = Voucher(code='SNSD', value=10000, start=start2, end=end2) db.session.add(v1) db.session.add(v2) db.session.commit() v2.start = datetime.strptime('2018-09-01 17:00:00', "%Y-%m-%d %H:%M:%S") v2.end = datetime.strptime('2019-09-15 17:00:00', '%Y-%m-%d %H:%M:%S') self.assertEqual(v2.is_overlap_with_other(), True) v2.start = datetime.strptime('2020-09-01 17:00:00', "%Y-%m-%d %H:%M:%S") v2.end = datetime.strptime('2021-09-01 17:00:00', "%Y-%m-%d %H:%M:%S") self.assertEqual(v2.is_overlap_with_other(), False)
def test_overlap(self): """Test unit overlap""" start1 = datetime.strptime('2018-09-01 17:00:00', "%Y-%m-%d %H:%M:%S") end1 = datetime.strptime('2019-09-15 17:00:00', '%Y-%m-%d %H:%M:%S') start2 = datetime.strptime('2019-09-01 17:00:00', '%Y-%m-%d %H:%M:%S') end2 = datetime.strptime('2019-09-15 17:00:00', '%Y-%m-%d %H:%M:%S') v1 = Voucher(code='SNSD', value=5000, start=start1, end=end1) v2 = Voucher(code='SNSD', value=10000, start=start2, end=end2) db.session.add(v1) db.session.add(v2) db.session.commit() start3 = datetime.strptime('2019-09-14 17:00:00', "%Y-%m-%d %H:%M:%S") end3 = datetime.strptime('2019-09-15 17:00:00', "%Y-%m-%d %H:%M:%S") v3 = Voucher(code='SNSD', value=10000, start=start3, end=end3) self.assertEqual(v3.is_overlap(), True) """Test unit overlap Fails""" v3.start = datetime.strptime('2020-09-14 17:00:00', "%Y-%m-%d %H:%M:%S") v3.end = datetime.strptime('2021-09-14 17:00:00', "%Y-%m-%d %H:%M:%S") self.assertEqual(v3.is_overlap(), False)