

def test_expiring_price(self):
    'Test whether a price with an expiration date is used in preference to a non-expiring price.'
    product = Product.objects.get(slug='PY-Rocks')
    self.assertEqual(product.unit_price, Decimal('19.50'))
    today = datetime.datetime.now()
    aweek = datetime.timedelta(days=7)
    lastwk = (today - aweek)
    nextwk = (today + aweek)
    price = Price.objects.create(product=product, quantity=Decimal('1'), price=Decimal('10.00'), expires=nextwk)
    self.assertEqual(product.unit_price, Decimal('10.00'))
    price.expires = lastwk
    price.save()
    self.assertEqual(product.unit_price, Decimal('19.50'))

dataset/ETHPy150Open dokterbob/satchmo/satchmo/apps/product/tests.py ProductTest.test_expiring_price/original