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.

58 lines
2.4 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Authentification - Generate Password module for Odoo
  5. # Copyright (C) 2013-2014 GRAP (http://www.grap.coop)
  6. # @author Sylvain LE GAL (https://twitter.com/legalsylvain)
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. # import threading
  23. from openerp.tests.common import TransactionCase
  24. class TestAuthGeneratePassword(TransactionCase):
  25. def setUp(self):
  26. super(TestAuthGeneratePassword, self).setUp()
  27. cr, uid = self.cr, self.uid
  28. self.imd_obj = self.registry('ir.model.data')
  29. self.ru_obj = self.registry('res.users')
  30. self.mm_obj = self.registry('mail.mail')
  31. self.demo_ru_id = self.imd_obj.get_object_reference(
  32. cr, uid, 'base',
  33. 'user_demo')[1]
  34. self.extra_ru_id = self.imd_obj.get_object_reference(
  35. cr, uid, 'auth_generate_password',
  36. 'extra_user')[1]
  37. # Test Section
  38. def test_01_generate_password(self):
  39. """[Functional Test] Test if generate password generate mails"""
  40. cr, uid = self.cr, self.uid
  41. ru_ids = [self.demo_ru_id, self.extra_ru_id]
  42. mm_qty_before = len(self.mm_obj.search(cr, uid, []))
  43. # threading.currentThread().testing = True
  44. self.ims_obj = self.registry('ir.mail_server')
  45. ims_ids = self.ims_obj.search(cr, uid, [])
  46. self.ims_obj.unlink(cr, uid, ims_ids)
  47. self.ru_obj.generate_password(cr, uid, ru_ids)
  48. mm_qty_after = len(self.mm_obj.search(cr, uid, []))
  49. self.assertEquals(
  50. mm_qty_before + len(ru_ids), mm_qty_after,
  51. "Generate password for %d user(s) must send %d email(s) !" % (
  52. len(ru_ids), len(ru_ids)))