Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

model_tests.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_hashing_with_utf8(self):
  36. a = models.UserAddress(
  37. first_name=u"\u0141ukasz Smith",
  38. last_name=u'Smith',
  39. line1=u"75 Smith Road",
  40. postcode=u"n4 8ty",
  41. country=self.country)
  42. a.active_address_fields()
  43. def test_ignores_whitespace_when_hashing(self):
  44. a1 = models.UserAddress(
  45. first_name=" Terry ",
  46. last_name='Barrington',
  47. line1=" 75 Smith Road ",
  48. postcode=" n4 8ty",
  49. country=self.country)
  50. a2 = models.UserAddress(
  51. first_name=" Terry",
  52. last_name=' Barrington',
  53. line1=" 75 Smith Road ",
  54. postcode="N4 8ty",
  55. country=self.country)
  56. self.assertEquals(a1.generate_hash(), a2.generate_hash())
  57. def test_populate_shipping_address_doesnt_set_id(self):
  58. a = models.UserAddress(
  59. first_name=" Terry ",
  60. last_name='Barrington',
  61. line1=" 75 Smith Road ",
  62. postcode=" n4 8ty",
  63. country=self.country)
  64. sa = ShippingAddress()
  65. a.populate_alternative_model(sa)
  66. self.assertIsNone(sa.id)
  67. def test_populated_shipping_address_has_same_summary_user_address(self):
  68. a = models.UserAddress(
  69. first_name=" Terry ",
  70. last_name='Barrington',
  71. line1=" 75 Smith Road ",
  72. postcode=" n4 8ty",
  73. country=self.country)
  74. sa = ShippingAddress()
  75. a.populate_alternative_model(sa)
  76. self.assertEquals(sa.summary, a.summary)
  77. def test_summary_is_property(self):
  78. a = models.UserAddress(
  79. first_name=" Terry ",
  80. last_name='Barrington',
  81. line1=" 75 Smith Road ",
  82. postcode=" n4 8ty",
  83. country=self.country)
  84. self.assertEquals(
  85. u"Terry Barrington, 75 Smith Road, N4 8TY, UNITED KINGDOM",
  86. a.summary)