Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

test_forms.py 1.2KB

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