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.

47 lines
1.5 KiB

  1. # Copyright 2015 Therp BV <http://therp.nl>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. import base64
  4. from odoo.tests.common import TransactionCase
  5. from odoo.tools.misc import file_open
  6. from odoo import http
  7. class FakeRequest(object):
  8. def __init__(self, env):
  9. self.env = env
  10. def make_response(self, data, headers):
  11. return FakeResponse(data, headers)
  12. class FakeResponse(object):
  13. def __init__(self, data, headers):
  14. self.data = data
  15. self.headers = dict(headers)
  16. class TestWebFavicon(TransactionCase):
  17. def test_web_favicon(self):
  18. original_request = http.request
  19. http.request = FakeRequest(self.env)
  20. from odoo.addons.web_favicon.controllers.web_favicon import\
  21. WebFavicon
  22. company = self.env['res.company'].search([], limit=1)
  23. # default icon
  24. company.write({
  25. 'favicon_backend': False,
  26. 'favicon_backend_mimetype': False,
  27. })
  28. data = WebFavicon().icon()
  29. self.assertEqual(data.headers['Content-Type'], 'image/x-icon')
  30. # our own icon
  31. company.write({
  32. 'favicon_backend': base64.b64encode(file_open(
  33. 'web_favicon/static/description/icon.png', 'rb').read()),
  34. 'favicon_backend_mimetype': 'image/png',
  35. })
  36. data = WebFavicon().icon()
  37. self.assertEqual(data.headers['Content-Type'],
  38. company.favicon_backend_mimetype)
  39. http.request = original_request