test_user.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # -*- coding: utf-8 -*-
  2. import transaction
  3. from tracim.tests import BaseTest
  4. from tracim.models.auth import User
  5. class TestUserModel(BaseTest):
  6. """
  7. Test for User model
  8. """
  9. def test_unit__create__ok__nominal_case(self):
  10. self.session.flush()
  11. transaction.commit()
  12. name = 'Damien'
  13. email = 'damien@accorsi.info'
  14. user = User()
  15. user.display_name = name
  16. user.email = email
  17. self.session.add(user)
  18. self.session.flush()
  19. transaction.commit()
  20. new_user = self.session.query(User).filter(User.display_name == name).one() # nopep8
  21. assert new_user.display_name == name
  22. assert new_user.email == email
  23. assert new_user.email_address == email
  24. def test_unit__password__ok__nominal_case(self):
  25. """
  26. Check if password can be set and hashed password
  27. can be retrieve. Verify if hashed password is not
  28. same as password.
  29. """
  30. name = 'Damien'
  31. email = 'tracim@trac.im'
  32. password = 'my_secure_password'
  33. user = User()
  34. user.display_name = name
  35. user.email = email
  36. assert user._password is None
  37. user.password = password
  38. assert user._password is not None
  39. assert user._password != password
  40. assert user.password == user._password
  41. def test__unit__validate_password__ok__nominal_case(self):
  42. """
  43. Check if validate_password can correctly check if password i the correct
  44. one
  45. """
  46. name = 'Damien'
  47. email = 'tracim@trac.im'
  48. password = 'my_secure_password'
  49. user = User()
  50. user.display_name = name
  51. user.email = email
  52. user.password = password
  53. assert user.validate_password(password) is True
  54. def test_unit__validate_password__false__null_password(self):
  55. # Check bug #70 fixed
  56. # http://tracim.org/workspaces/4/folders/5/threads/70
  57. name = 'Damien'
  58. email = 'tracim@trac.im'
  59. user = User()
  60. user.display_name = name
  61. user.email = email
  62. assert user.validate_password('') is False
  63. def test_unit__validate_password__false__bad_password(self):
  64. """
  65. Check if validate_password can correctly check if password is
  66. an uncorrect correct one
  67. """
  68. name = 'Damien'
  69. email = 'tracim@trac.im'
  70. password = 'my_secure_password'
  71. user = User()
  72. user.display_name = name
  73. user.email = email
  74. user.password = password
  75. assert user.validate_password('uncorrect_password') is False
  76. def test_unit__repr__ok__nominal_case(self):
  77. name = 'Damien'
  78. email = 'tracim@trac.im'
  79. user = User()
  80. user.display_name = name
  81. user.email = email
  82. assert user.__repr__() == "<User: email='tracim@trac.im', display='Damien'>" # nopep8
  83. def test_unit__unicode__ok__nominal_case(self):
  84. name = 'Damien'
  85. email = 'tracim@trac.im'
  86. user = User()
  87. user.display_name = name
  88. user.email = email
  89. assert user.__unicode__() == name
  90. def test__unit__unicode__ok__no_display_name(self):
  91. email = 'tracim@trac.im'
  92. user = User()
  93. user.email = email
  94. assert user.__unicode__() == email