[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) <nle@odoo.com>
This commit is contained in:
Nicolas Lempereur
2022-06-08 12:26:59 +02:00
parent b24bc6dc06
commit 6dae35ab2e
+10 -3
View File
@@ -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)