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.

model_tests.py 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. from django.test import TestCase
  2. from oscar.core.compat import get_user_model
  3. from oscar.apps.address import models
  4. from oscar.apps.order.models import ShippingAddress
  5. User = get_user_model()
  6. class TestUserAddress(TestCase):
  7. def setUp(self):
  8. self.user = User.objects.create(username="dummy")
  9. self.country = models.Country(
  10. iso_3166_1_a2='GB', name="UNITED KINGDOM")
  11. def test_converts_postcode_to_uppercase_when_saving(self):
  12. address = models.UserAddress.objects.create(
  13. last_name='Barrington',
  14. line1="75 Smith Road",
  15. postcode="n4 8ty",
  16. country=self.country, user=self.user)
  17. self.assertEquals("N4 8TY", address.postcode)
  18. def test_strips_whitespace_when_saving(self):
  19. a = models.UserAddress.objects.create(
  20. last_name='Barrington',
  21. line1=" 75 Smith Road ",
  22. postcode=" n4 8ty",
  23. country=self.country, user=self.user)
  24. self.assertEquals("N4 8TY", a.postcode)
  25. self.assertEquals("75 Smith Road", a.line1)
  26. def test_active_address_fields_skips_whitespace_only_fields(self):
  27. a = models.UserAddress(
  28. first_name=" ",
  29. last_name='Barrington',
  30. line1=" 75 Smith Road ",
  31. postcode=" n4 8ty",
  32. country=self.country)
  33. active_fields = a.active_address_fields()
  34. self.assertEquals("Barrington", active_fields[0])
  35. def test_ignores_whitespace_when_hashing(self):
  36. a1 = models.UserAddress(
  37. first_name=" Terry ",
  38. last_name='Barrington',
  39. line1=" 75 Smith Road ",
  40. postcode=" n4 8ty",
  41. country=self.country)
  42. a2 = models.UserAddress(
  43. first_name=" Terry",
  44. last_name=' Barrington',
  45. line1=" 75 Smith Road ",
  46. postcode="N4 8ty",
  47. country=self.country)
  48. self.assertEquals(a1.generate_hash(), a2.generate_hash())
  49. def test_populate_shipping_address_doesnt_set_id(self):
  50. a = models.UserAddress(
  51. first_name=" Terry ",
  52. last_name='Barrington',
  53. line1=" 75 Smith Road ",
  54. postcode=" n4 8ty",
  55. country=self.country)
  56. sa = ShippingAddress()
  57. a.populate_alternative_model(sa)
  58. self.assertIsNone(sa.id)
  59. def test_populated_shipping_address_has_same_summary_user_address(self):
  60. a = models.UserAddress(
  61. first_name=" Terry ",
  62. last_name='Barrington',
  63. line1=" 75 Smith Road ",
  64. postcode=" n4 8ty",
  65. country=self.country)
  66. sa = ShippingAddress()
  67. a.populate_alternative_model(sa)
  68. self.assertEquals(sa.summary, a.summary)
  69. def test_summary_is_property(self):
  70. a = models.UserAddress(
  71. first_name=" Terry ",
  72. last_name='Barrington',
  73. line1=" 75 Smith Road ",
  74. postcode=" n4 8ty",
  75. country=self.country)
  76. self.assertEquals(
  77. u"Terry Barrington, 75 Smith Road, N4 8TY, UNITED KINGDOM",
  78. a.summary)