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.

65 lines
2.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2014-2015 Grupo ESOC <www.grupoesoc.es>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from os import path
  5. from openerp.tests.common import TransactionCase
  6. class ForwardMailCase(TransactionCase):
  7. def setUp(self, *args, **kwargs):
  8. super(ForwardMailCase, self).setUp(*args, **kwargs)
  9. self.compose = self.env["mail.compose.message"].create({})
  10. self.fwd = self.env["mail_forward.compose_message"].create({
  11. "original_wizard_id": self.compose.id,
  12. })
  13. self.partner = self.env["res.partner"].create({"name": __file__})
  14. self.attachment = self.env["ir.attachment"].create({
  15. "name": "Testing source",
  16. "datas_fname": path.basename(__file__),
  17. "type": "url",
  18. "url": "file://%s" % __file__,
  19. })
  20. def test_subject(self):
  21. """Test correct subject is used."""
  22. self.compose.subject = "Bad subject"
  23. good = "Good subject"
  24. defaults = self.fwd.with_context(default_subject=good).default_get(
  25. ["subject"])
  26. self.assertEqual(defaults["subject"], good)
  27. def test_change_destination(self):
  28. """Test what happens when changing the destination."""
  29. model = self.env["ir.model"].search(
  30. [("model", "=", self.partner._name)])
  31. # Set a partner as destination object
  32. self.fwd.destination_object_id = self.partner
  33. self.fwd.change_destination_object()
  34. self.assertEqual(self.fwd.model, self.partner._name)
  35. self.assertEqual(self.fwd.res_id, self.partner.id)
  36. self.assertEqual(self.fwd.record_name,
  37. "%s %s" % (model.name, self.partner.name))
  38. # Remove the destination object
  39. self.fwd.destination_object_id = False
  40. self.fwd.change_destination_object()
  41. self.assertFalse(self.fwd.model)
  42. self.assertFalse(self.fwd.res_id)
  43. self.assertFalse(self.fwd.record_name)
  44. def test_move_attachments(self):
  45. """Attachments moved correctly."""
  46. self.fwd.attachment_ids |= self.attachment
  47. self.fwd.destination_object_id = self.partner
  48. self.fwd.change_destination_object()
  49. self.fwd.body = "body"
  50. self.fwd.subject = "subject"
  51. self.fwd.move_attachments = True
  52. self.fwd.send_mail()
  53. self.assertEqual(self.attachment.res_model, self.partner._name)
  54. self.assertEqual(self.attachment.res_id, self.partner.id)