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.

address_tests.py 3.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. from django.contrib.auth.models import User
  3. from django.test import TestCase
  4. from oscar.apps.address.models import Country, UserAddress
  5. from oscar.apps.order.models import ShippingAddress
  6. class UserAddressTest(TestCase):
  7. def setUp(self):
  8. self.user = User.objects.create(username='dummy_user')
  9. self.country = Country(iso_3166_1_a2='GB', name="UNITED KINGDOM")
  10. def tearDown(self):
  11. self.user.delete()
  12. def test_titleless_salutation_is_stripped(self):
  13. a = UserAddress(last_name='Barrington', line1="75 Smith Road", postcode="N4 8TY",
  14. country=self.country, user=self.user)
  15. self.assertEquals("Barrington", a.salutation())
  16. def test_postcodes_are_saved_in_uppercase(self):
  17. a = UserAddress.objects.create(last_name='Barrington', line1="75 Smith Road", postcode="n4 8ty",
  18. country=self.country, user=self.user)
  19. self.assertEquals("N4 8TY", a.postcode)
  20. def test_fields_are_stripped_when_saved(self):
  21. a = UserAddress.objects.create(last_name='Barrington', line1=" 75 Smith Road ", postcode=" n4 8ty",
  22. country=self.country, user=self.user)
  23. self.assertEquals("N4 8TY", a.postcode)
  24. def test_active_address_fields_skips_whitespace_only_fields(self):
  25. a = UserAddress(first_name=" ", last_name='Barrington', line1=" 75 Smith Road ", postcode=" n4 8ty",
  26. country=self.country, user=self.user)
  27. active_fields = a.active_address_fields()
  28. self.assertEquals("Barrington", active_fields[0])
  29. def test_summary_is_property(self):
  30. a = UserAddress(first_name=" Terry ", last_name='Barrington', line1=" 75 Smith Road ", postcode=" n4 8ty",
  31. country=self.country, user=self.user)
  32. self.assertEquals("Terry Barrington, 75 Smith Road, N4 8TY, UNITED KINGDOM", a.summary)
  33. def test_populate_shipping_address_doesnt_set_id(self):
  34. a = UserAddress(first_name=" Terry ", last_name='Barrington', line1=" 75 Smith Road ", postcode=" n4 8ty",
  35. country=self.country, user=self.user)
  36. sa = ShippingAddress()
  37. a.populate_alternative_model(sa)
  38. self.assertIsNone(sa.id)
  39. def test_populated_shipping_address_has_same_summary_user_address(self):
  40. a = UserAddress(first_name=" Terry ", last_name='Barrington', line1=" 75 Smith Road ", postcode=" n4 8ty",
  41. country=self.country, user=self.user)
  42. sa = ShippingAddress()
  43. a.populate_alternative_model(sa)
  44. self.assertEquals(sa.summary, a.summary)
  45. def test_addresses_with_same_fields_ignoring_whitespace_have_same_hash(self):
  46. a1 = UserAddress(first_name=" Terry ", last_name='Barrington', line1=" 75 Smith Road ", postcode=" n4 8ty",
  47. country=self.country, user=self.user)
  48. a2 = UserAddress(first_name=" Terry", last_name=' Barrington', line1=" 75 Smith Road ", postcode="N4 8ty",
  49. country=self.country, user=self.user)
  50. self.assertEquals(a1.generate_hash(), a2.generate_hash())
  51. def test_hashing_with_utf8(self):
  52. a = UserAddress(first_name=u"\u0141ukasz Smith", last_name=u'Smith', line1=u"75 Smith Road", postcode=u"n4 8ty",
  53. country=self.country, user=self.user)
  54. a.active_address_fields()
  55. def test_city_is_alias_of_line4(self):
  56. a = UserAddress(last_name='Barrington', line1="75 Smith Road", line4="London", postcode="n4 8ty",
  57. country=self.country, user=self.user)
  58. self.assertEqual('London', a.city)