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.

54 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 ACSONE SA/NV
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp.tests.common import TransactionCase
  5. from openerp.exceptions import UserError
  6. class TestMailAsLetter(TransactionCase):
  7. def setUp(self):
  8. super(TestMailAsLetter, self).setUp()
  9. # ENVIRONMENTS
  10. self.mail_compose_message = self.env['mail.compose.message']
  11. # INSTANCES
  12. # Partners
  13. self.base_partner = self.ref('base.main_partner')
  14. self.root_partner = self.ref('base.partner_root')
  15. # Mail compose message
  16. self.mail_composer = self.mail_compose_message.create({
  17. 'subject': "Test mail",
  18. 'body': "Blah blah blah"})
  19. def test_compute_partner_count(self):
  20. # No partner
  21. self.mail_composer.update({
  22. 'partner_ids': False})
  23. self.assertEqual(self.mail_composer.partner_count, 0)
  24. # One partner
  25. self.mail_composer.update({
  26. 'partner_ids': [self.base_partner]})
  27. self.assertEqual(self.mail_composer.partner_count, 1)
  28. # Two partners
  29. self.mail_composer.update({
  30. 'partner_ids': [self.base_partner, self.root_partner]})
  31. self.assertEqual(self.mail_composer.partner_count, 2)
  32. def test_download_pdf(self):
  33. # With no partner
  34. with self.assertRaises(UserError), self.cr.savepoint():
  35. self.mail_composer.update({
  36. 'partner_ids': False})
  37. self.mail_composer.download_pdf()
  38. # With more than one partner
  39. with self.assertRaises(UserError), self.cr.savepoint():
  40. self.mail_composer.update({
  41. 'partner_ids': [self.base_partner, self.root_partner]})
  42. self.mail_composer.download_pdf()
  43. # With exactly one partner
  44. self.mail_composer.update({
  45. 'partner_ids': [self.base_partner]})
  46. self.mail_composer.download_pdf()