You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

form_tests.py 1.3KB

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