Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

test_forms.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import datetime
  2. from django.test import TestCase
  3. from django.utils.timezone import now
  4. from oscar.apps.dashboard.offers import forms
  5. from oscar.apps.offer.models import ConditionalOffer
  6. from oscar.test.factories import ConditionalOfferFactory, VoucherFactory
  7. class TestMetaDataForm(TestCase):
  8. def test_changing_offer_type_for_voucher_offer_without_vouchers(self):
  9. offer = ConditionalOfferFactory(offer_type=ConditionalOffer.VOUCHER)
  10. data = {
  11. 'name': offer.name,
  12. 'description': offer.description,
  13. 'offer_type': ConditionalOffer.SITE,
  14. }
  15. form = forms.MetaDataForm(data, instance=offer)
  16. self.assertTrue(form.is_valid())
  17. def test_changing_offer_type_for_voucher_offer_with_vouchers(self):
  18. offer = ConditionalOfferFactory(offer_type=ConditionalOffer.VOUCHER)
  19. VoucherFactory().offers.add(offer)
  20. data = {
  21. 'name': offer.name,
  22. 'description': offer.description,
  23. 'offer_type': ConditionalOffer.SITE,
  24. }
  25. form = forms.MetaDataForm(data, instance=offer)
  26. self.assertFalse(form.is_valid())
  27. self.assertEqual(form.errors['offer_type'][0],
  28. "This can only be changed if it has no vouchers attached to it")
  29. class TestRestrictionsFormEnforces(TestCase):
  30. def test_cronological_dates(self):
  31. start = now()
  32. end = start - datetime.timedelta(days=30)
  33. post = {'name': 'dummy',
  34. 'description': 'dummy',
  35. 'start_datetime': start,
  36. 'end_datetime': end}
  37. form = forms.RestrictionsForm(post)
  38. self.assertFalse(form.is_valid())