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.

43 lines
1.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 Onestein (<http://www.onestein.eu>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from mock import patch
  5. from odoo import http
  6. from odoo.tests.common import HttpCase
  7. from odoo.addons.web_chatter_paste.controllers.main \
  8. import ChatterPasteController
  9. class TestWebChatterPaste(HttpCase):
  10. def test_controller(self):
  11. partner_id = self.ref('base.main_partner')
  12. attachment_obj = self.env['ir.attachment']
  13. attachment_count = attachment_obj.search_count([
  14. ('res_model', '=', 'res.partner'),
  15. ('res_id', '=', partner_id)
  16. ])
  17. f = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6' \
  18. 'QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFN' \
  19. 'vZnR3YXJlAHBhaW50Lm5ldCA0LjAuOWwzfk4AAAAMSURBVBhXY/j//z8ABf4C/q' \
  20. 'c1gYQAAAAASUVORK5CYII='
  21. with patch.object(http, 'request') as request:
  22. request.env = self.env
  23. controller = ChatterPasteController()
  24. controller.upload_attachment(
  25. '_',
  26. 'res.partner',
  27. partner_id,
  28. 'test.png',
  29. 'image/png',
  30. f
  31. )
  32. new_attachment_count = attachment_obj.search_count([
  33. ('res_model', '=', 'res.partner'),
  34. ('res_id', '=', partner_id)
  35. ])
  36. self.assertEqual(attachment_count + 1, new_attachment_count)