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.

52 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015-TODAY LasLabs Inc.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.tests.common import TransactionCase
  5. class TestResUsers(TransactionCase):
  6. def setUp(self, *args, **kwargs):
  7. super(TestResUsers, self).setUp(*args, **kwargs)
  8. self.login = 'LasLabs@ExAmPlE.CoM'
  9. self.partner_vals = {
  10. 'name': 'Partner',
  11. 'is_company': False,
  12. 'email': self.login,
  13. }
  14. self.vals = {
  15. 'name': 'User',
  16. 'login': self.login,
  17. 'password': 'password',
  18. }
  19. self.model_obj = self.env['res.users']
  20. def _new_record(self, ):
  21. partner_id = self.env['res.partner'].create(self.partner_vals)
  22. self.vals['partner_id'] = partner_id.id
  23. return self.model_obj.create(self.vals)
  24. def test_login_is_lowercased_on_create(self, ):
  25. rec_id = self._new_record()
  26. self.assertEqual(
  27. self.login.lower(), rec_id.login,
  28. 'Login was not lowercased when saved to db.',
  29. )
  30. def test_login_is_lowercased_on_write(self, ):
  31. rec_id = self._new_record()
  32. rec_id.write({'login': self.login})
  33. self.assertEqual(
  34. self.login.lower(), rec_id.login,
  35. 'Login was not lowercased when saved to db.',
  36. )
  37. def test_login_search_is_lowercased(self, ):
  38. rec_id = self._new_record()
  39. res_id = self.model_obj.search([('login', '=', self.login.upper())])
  40. res = res_id.id if res_id else False
  41. self.assertEqual(
  42. rec_id.id, res,
  43. 'Search for login with uppercase chars did not yield results.',
  44. )