diff --git a/web_favicon/controllers/web_favicon.py b/web_favicon/controllers/web_favicon.py index 1c9d753f..1a190d9c 100644 --- a/web_favicon/controllers/web_favicon.py +++ b/web_favicon/controllers/web_favicon.py @@ -20,14 +20,14 @@ import StringIO import base64 from openerp import http -from openerp.http import request from openerp.tools.misc import file_open -class WebShortcutIcon(http.Controller): +class WebFavicon(http.Controller): @http.route('/web_favicon/favicon', type='http', auth="none") def icon(self): + request = http.request company = request.env['res.company'].search([], limit=1) if 'uid' in request.env.context: user = request.env['res.users'].browse(request.env.context['uid']) diff --git a/web_favicon/tests/__init__.py b/web_favicon/tests/__init__.py new file mode 100644 index 00000000..15f22fca --- /dev/null +++ b/web_favicon/tests/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import test_web_favicon diff --git a/web_favicon/tests/test_web_favicon.py b/web_favicon/tests/test_web_favicon.py new file mode 100644 index 00000000..c5170f4b --- /dev/null +++ b/web_favicon/tests/test_web_favicon.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +import base64 +import werkzeug.local +from openerp.tests.common import TransactionCase +from openerp.tools.misc import file_open +from openerp import http + + +class FakeRequest(object): + def __init__(self, env): + self.env = env + def make_response(self, data, headers): + return FakeResponse(data, headers) + + +class FakeResponse(object): + def __init__(self, data, headers): + self.data = data + self.headers = dict(headers) + + + + +class TestWebFavicon(TransactionCase): + def test_web_favicon(self): + original_request = http.request + http.request = FakeRequest(self.env) + from openerp.addons.web_favicon.controllers.web_favicon import\ + WebFavicon + company = self.env['res.company'].search([], limit=1) + # default icon + company.write({ + 'favicon_backend': False, + 'favicon_backend_mimetype': False, + }) + data = WebFavicon().icon() + self.assertEqual(data.headers['Content-Type'], 'image/x-icon') + default_icon_data = data.data + # our own icon + company.write({ + 'favicon_backend': base64.b64encode(file_open( + 'web_favicon/static/description/icon.png').read()), + 'favicon_backend_mimetype': 'image/png', + }) + data = WebFavicon().icon() + self.assertEqual(data.headers['Content-Type'], + company.favicon_backend_mimetype) + http.request = original_request