class DiscountTestCase(TestCase): def setUp(self): self.discount = DiscountFactory() def test_discount_to_string(self): self.assertEqual(str(self.discount), self.discount.name) def test_is_valid_property(self): self.assertFalse(self.discount.is_valid()) today = datetime.now().date() self.discount.start_date = today + timedelta(days=5) self.assertFalse(self.discount.is_valid(purchased_date=today)) discount = DiscountFactory(end_date=date(2018, 5, 6)) self.assertFalse(discount.is_valid(purchased_date=today)) def test_display_name(self): spring_discount = DiscountFactory(name='Spring bulk', discount_type=PERCENT_DISCOUNT, percent=10, value=20) autumn_discount = DiscountFactory(name='Autumn bulk', discount_type=VALUE_DISCOUNT, percent=10, value=20) self.assertEqual(spring_discount.display_name, 'Spring bulk -10%') self.assertEqual(autumn_discount.display_name, 'Autumn bulk -$20')
def test_is_valid_property(self): self.assertFalse(self.discount.is_valid()) today = datetime.now().date() self.discount.start_date = today + timedelta(days=5) self.assertFalse(self.discount.is_valid(purchased_date=today)) discount = DiscountFactory(end_date=date(2018, 5, 6)) self.assertFalse(discount.is_valid(purchased_date=today))