您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

test_checkout_forms.py 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from django.test import TestCase
  2. from apps.checkout import forms
  3. from oscar.apps.address import models
  4. from oscar.apps.order import models as order_models
  5. class TestBillingAddressForm(TestCase):
  6. def setUp(self):
  7. models.Country.objects.create(
  8. iso_3166_1_a2='GB', name="Great Britain")
  9. self.shipping_address = order_models.ShippingAddress()
  10. def test_selecting_same_as_shipping_is_valid_with_no_billing_address_data(self):
  11. data = {
  12. 'same_as_shipping': 'same',
  13. 'first_name': '',
  14. 'last_name': '',
  15. 'line1': '',
  16. 'line2': '',
  17. 'line3': '',
  18. 'line4': '',
  19. 'postcode': '',
  20. 'state': '',
  21. 'country': 'GB'
  22. }
  23. form = forms.BillingAddressForm(
  24. shipping_address=self.shipping_address, data=data)
  25. self.assertTrue(
  26. form.is_valid(), "Form invalid due to %r" % form.errors)
  27. def test_selecting_same_as_shipping_is_valid(self):
  28. data = {
  29. 'same_as_shipping': 'same',
  30. 'first_name': 'test',
  31. 'last_name': 'test',
  32. 'line1': 'test',
  33. 'line2': 'test',
  34. 'line3': 'test',
  35. 'line4': 'test',
  36. 'postcode': 'test',
  37. 'state': '',
  38. 'country': 'GB'
  39. }
  40. form = forms.BillingAddressForm(
  41. shipping_address=self.shipping_address, data=data)
  42. self.assertTrue(
  43. form.is_valid(), "Form invalid due to %r" % form.errors)
  44. def test_selecting_manual_validate_address(self):
  45. data = {
  46. 'same_as_shipping': 'new',
  47. 'first_name': 'test',
  48. 'last_name': 'test',
  49. 'line1': 'test',
  50. 'line2': 'test',
  51. 'line3': 'test',
  52. 'line4': 'test',
  53. 'postcode': 'test',
  54. 'state': '',
  55. 'country': 'GB'
  56. }
  57. form = forms.BillingAddressForm(
  58. shipping_address=self.shipping_address, data=data)
  59. self.assertFalse(form.is_valid())