Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

form_tests.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from django.test import TestCase
  2. from django_dynamic_fixture import G
  3. from oscar.apps.address import models, forms
  4. from oscar.core.compat import get_user_model
  5. User = get_user_model()
  6. class TestUserAddressForm(TestCase):
  7. def setUp(self):
  8. self.user = G(User)
  9. self.country = models.Country.objects.create(
  10. iso_3166_1_a2='GB', name="UNITED KINGDOM")
  11. def test_merges_addresses_with_same_hash(self):
  12. data = {
  13. 'user': self.user,
  14. 'first_name': "Matus",
  15. 'last_name': "Moravcik",
  16. 'line1': "1 Egg Street",
  17. 'line4': "London",
  18. 'postcode': "N12 9RE",
  19. 'country': self.country}
  20. # Create two addresses, which are slightly different
  21. models.UserAddress.objects.create(**data)
  22. other = data.copy()
  23. other['first_name'] = 'Izidor'
  24. duplicate = models.UserAddress.objects.create(**other)
  25. # Edit duplicate to be same as original and check that the two
  26. # addresses are merged when the form saves.
  27. post_data = data.copy()
  28. post_data['country'] = self.country.iso_3166_1_a2
  29. form = forms.UserAddressForm(self.user, post_data, instance=duplicate)
  30. self.assertFalse(form.is_valid())
  31. self.assertTrue(len(form.errors['__all__']) > 0)