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 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # -*- coding: utf-8 -*-
  2. from django.test import TestCase
  3. from oscar.core.compat import get_user_model
  4. from oscar.apps.address import models
  5. User = get_user_model()
  6. class TestUserAddress(TestCase):
  7. def test_uses_title_firstname_and_lastname_in_salutation(self):
  8. a = models.UserAddress(
  9. title="Dr",
  10. first_name="Barry",
  11. last_name='Barrington')
  12. self.assertEquals("Dr Barry Barrington", a.salutation)
  13. def test_strips_whitespace_from_salutation(self):
  14. a = models.UserAddress(last_name='Barrington')
  15. self.assertEquals("Barrington", a.salutation)
  16. def test_has_name_property(self):
  17. a = models.UserAddress(
  18. title="Dr",
  19. first_name="Barry",
  20. last_name='Barrington')
  21. self.assertEquals("Barry Barrington", a.name)
  22. def test_has_summary_property(self):
  23. a = models.UserAddress(
  24. title="Dr",
  25. first_name="Barry",
  26. last_name='Barrington',
  27. line1="1 King Road",
  28. line4="London",
  29. postcode="SW1 9RE")
  30. self.assertEquals("Dr Barry Barrington, 1 King Road, London, SW1 9RE",
  31. a.summary)
  32. def test_summary_includes_country(self):
  33. c = models.Country(
  34. pk=1, iso_3166_1_a2="GB", name="UNITED KINGDOM")
  35. a = models.UserAddress(
  36. title="Dr",
  37. first_name="Barry",
  38. last_name='Barrington',
  39. line1="1 King Road",
  40. line4="London",
  41. postcode="SW1 9RE",
  42. country=c)
  43. self.assertEquals(
  44. "Dr Barry Barrington, 1 King Road, London, SW1 9RE, UNITED KINGDOM",
  45. a.summary)
  46. def test_can_be_hashed(self):
  47. a = models.UserAddress(
  48. title="Dr",
  49. first_name="Barry",
  50. last_name='Barrington',
  51. line1="1 King Road",
  52. line4="London",
  53. postcode="SW1 9RE")
  54. hash = a.generate_hash()
  55. self.assertTrue(hash is not None)
  56. def test_can_be_hashed_including_non_ascii(self):
  57. a = models.UserAddress(
  58. first_name=u"\u0141ukasz Smith",
  59. last_name=u'Smith',
  60. line1=u"75 Smith Road",
  61. postcode=u"n4 8ty")
  62. hash = a.generate_hash()
  63. self.assertTrue(hash is not None)
  64. def test_strips_whitespace_in_name_property(self):
  65. a = models.UserAddress(
  66. last_name='Barrington')
  67. self.assertEquals("Barrington", a.name)
  68. def test_uses_city_as_an_alias_of_line4(self):
  69. a = models.UserAddress(
  70. last_name='Barrington',
  71. line1="75 Smith Road",
  72. line4="London",
  73. postcode="n4 8ty")
  74. self.assertEqual('London', a.city)