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.

48 lines
1.5 KiB

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