From 6dae35ab2ee3f3ad3650063e72e151e4ccc65d55 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Tue, 3 May 2022 14:21:04 +0000 Subject: [PATCH] [FIX] base: test_mimetype_svg working with magic In libmagic implementation, space before an SVG make it detected as SVG. In odoo implementation, for the same case we don't detect it as SVG. But in the test `test_guess_mimetype.test_mimetype_svg` we only check odoo implementation behavior, so the test fail if module python-magic is installed. With this fix, the test is only run when python-magic is not installed. opw-2746934 closes odoo/odoo#93056 X-original-commit: 8e38bfb38a3c1c3888d4f4efa1a13fa4cf6246bb Signed-off-by: Nicolas Lempereur (nle) --- odoo/addons/base/tests/test_mimetypes.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/odoo/addons/base/tests/test_mimetypes.py b/odoo/addons/base/tests/test_mimetypes.py index 43d52b30f10..2867174a82f 100644 --- a/odoo/addons/base/tests/test_mimetypes.py +++ b/odoo/addons/base/tests/test_mimetypes.py @@ -1,6 +1,11 @@ import base64 import unittest +try: + import magic +except ImportError: + magic = None + from odoo.tests.common import BaseCase from odoo.tools.mimetypes import get_extension, guess_mimetype @@ -65,9 +70,11 @@ class test_guess_mimetype(BaseCase): content = base64.b64decode(SVG) mimetype = guess_mimetype(content, default='test') self.assertTrue(mimetype.startswith('image/svg')) - # Tests that whitespace padded SVG are not detected as SVG - mimetype = guess_mimetype(b" " + content, default='test') - self.assertNotIn("svg", mimetype) + # Tests that whitespace padded SVG are not detected as SVG in odoo implementation + if not magic: + mimetype = guess_mimetype(b" " + content, default='test') + self.assertNotIn("svg", mimetype) + def test_mimetype_zip(self): content = base64.b64decode(ZIP)