From d89d49edd6582b6aa000eb0aa5163fb16f66fd27 Mon Sep 17 00:00:00 2001 From: Daryl Chen Date: Thu, 28 Mar 2024 11:30:51 -0400 Subject: [PATCH] 3fix --- web_favicon/models/res_company.py | 14 +++++++++----- web_favicon/tests/test_web_favicon.py | 13 +++---------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/web_favicon/models/res_company.py b/web_favicon/models/res_company.py index 6426293cbc41..84d2a887b85d 100644 --- a/web_favicon/models/res_company.py +++ b/web_favicon/models/res_company.py @@ -73,11 +73,15 @@ def _get_favicon(self): if request.httprequest.cookies.get("cids") else False ) - if company_id and self.browse(int(company_id)).sudo().favicon: - sudo_record = self.env.company.sudo() - sha = hashlib.sha512( - str(sudo_record.write_date).encode("utf-8") - ).hexdigest()[:7] + company = ( + self.browse(int(company_id.split(",")[0])).sudo() + if company_id and self.browse(int(company_id.split(",")[0])).sudo().favicon + else False + ) + if company: + sha = hashlib.sha512(str(company.write_date).encode("utf-8")).hexdigest()[ + :7 + ] return f"/web/image/{self._name}/{company_id}/favicon?unique={sha}" else: return False diff --git a/web_favicon/tests/test_web_favicon.py b/web_favicon/tests/test_web_favicon.py index d399d03c0cc2..0ce1b73b41f0 100644 --- a/web_favicon/tests/test_web_favicon.py +++ b/web_favicon/tests/test_web_favicon.py @@ -37,19 +37,12 @@ def test_01_web_favicon(self): self.assertEqual(image.format, "JPEG") self.assertEqual(image.size, (1920, 1080)) self.assertEqual(image.getpixel((0, 0)), bg_color) + with MockRequest(self.env) as mock_request: + mock_request.httprequest.cookies = {"cids": str(company.id)} + self.assertTrue(Company._get_favicon()) def test_02_default_favicon_creation(self): """Test if default favicon is set when creating a company without specifying a favicon.""" Company = self.env["res.company"] company = Company.create({"name": "Test Company"}) self.assertTrue(company.favicon, "Default favicon not set on company creation.") - - def test_03_get_favicon_returns_false(self): - """Test if _get_favicon() returns False when certain conditions are not met.""" - Company = self.env["res.company"].create({"name": "Company for Testing"}) - with MockRequest(self.env): - # Call _get_favicon() without company id to trigger the condition - self.assertFalse( - Company._get_favicon(), - "_get_favicon() should return False when company id is not present.", - )