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.

57 lines
2.2 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 odoo.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. def test_move_attachments(self):
  39. """Attachments moved correctly."""
  40. self.fwd.attachment_ids |= self.attachment
  41. self.fwd.destination_object_id = self.partner
  42. self.fwd.change_destination_object()
  43. self.fwd.body = "body"
  44. self.fwd.subject = "subject"
  45. self.fwd.move_attachments = True
  46. self.fwd.send_mail()
  47. self.assertEqual(self.attachment.res_model, self.partner._name)
  48. self.assertEqual(self.attachment.res_id, self.partner.id)