Skip to content

Commit be5d3f3

Browse files
committed
squashing syntax fixes and using assertLog in unittest
1 parent bf0b5fa commit be5d3f3

File tree

9 files changed

+83
-43
lines changed

9 files changed

+83
-43
lines changed

web_favicon/__manifest__.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
{
77
"name": "Custom shortcut icon",
88
"version": "18.0.1.0.0",
9-
"author": "Therp BV, "
10-
"Tecnativa, "
11-
"OERP Canada,"
12-
"Odoo Community Association (OCA)",
9+
"author": "Therp BV, Tecnativa, OERP Canada,Odoo Community Association (OCA)",
1310
"license": "AGPL-3",
1411
"category": "Website",
1512
"summary": "Allows to set a custom shortcut icon (aka favicon)",

web_iconify_proxy/README.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Web Iconify Proxy
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1414
:target: https://odoo-community.org/page/development-status
1515
:alt: Beta
16-
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17-
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18-
:alt: License: AGPL-3
16+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
18+
:alt: License: LGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
2020
:target: https://github.com/OCA/web/tree/18.0/web_iconify_proxy
2121
:alt: OCA/web

web_iconify_proxy/__manifest__.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
{
55
"name": "Web Iconify Proxy",
66
"summary": "Proxies requests to the Iconify API, providing SVG icons, CSS,"
7-
" and JSON data. It also implements caching using Odoo's ir.attachment "
8-
"model.",
7+
" and JSON data. It also implements caching using Odoo's "
8+
"ir.attachment model.",
99
"version": "18.0.1.0.0",
1010
"category": "Website",
1111
"website": "https://github.com/OCA/web",
1212
"author": "jaco.tech, Odoo Community Association (OCA)",
13-
"license": "AGPL-3",
13+
"license": "LGPL-3",
1414
"depends": ["web"],
1515
"data": [],
1616
"assets": {
@@ -20,4 +20,5 @@
2020
},
2121
"installable": True,
2222
"auto_install": False,
23+
"tests": ["tests/test_main.py"],
2324
}

web_iconify_proxy/controllers/main.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ def _fetch_iconify_data(
3232

3333
# Validate prefix
3434
if not re.match(r"^[a-z0-9-]+$", prefix):
35-
return request.not_found()
35+
raise request.not_found()
3636

3737
# Validate icon (if provided)
3838
if icon and not re.match(r"^[a-z0-9:-]+$", icon):
39-
return request.not_found()
39+
raise request.not_found()
4040

4141
# Validate icons (if provided)
4242
if icons:
4343
icon_list = icons.split(",")
4444
for single_icon in icon_list:
4545
if not re.match(r"^[a-z0-9:-]+$", single_icon):
46-
return request.not_found()
46+
raise request.not_found()
4747
icons = ",".join(icon_list) # Reconstruct to prevent injection
4848

4949
Attachment = request.env["ir.attachment"].sudo()
@@ -57,7 +57,7 @@ def _fetch_iconify_data(
5757
name = f"{prefix}-{icons}"
5858
res_model = "iconify.json"
5959
else:
60-
return request.not_found()
60+
raise request.not_found()
6161

6262
attachment = Attachment.search(
6363
[("res_model", "=", res_model), ("name", "=", name)], limit=1
@@ -79,7 +79,7 @@ def _fetch_iconify_data(
7979
response.raise_for_status() # Raise HTTPError for bad responses
8080
except requests.exceptions.RequestException as e:
8181
_logger.error(f"Request to Iconify API failed: {e}")
82-
return request.not_found()
82+
raise request.not_found() from e
8383

8484
data = response.content
8585
attachment = Attachment.create(
@@ -139,7 +139,7 @@ def get_css(self, prefix, **params):
139139
"""
140140
icons = params.get("icons")
141141
if not icons:
142-
return request.not_found()
142+
raise request.not_found()
143143
upstream_url = f"https://api.iconify.design/{prefix}.css?icons={icons}"
144144
return self._fetch_iconify_data(upstream_url, "text/css", prefix, icons=icons)
145145

@@ -162,7 +162,7 @@ def get_json(self, prefix, **params):
162162
"""
163163
icons = params.get("icons")
164164
if not icons:
165-
return request.not_found()
165+
raise request.not_found()
166166
upstream_url = f"https://api.iconify.design/{prefix}.json?icons={icons}"
167167
return self._fetch_iconify_data(
168168
upstream_url, "application/json", prefix, icons=icons
@@ -186,7 +186,7 @@ def get_last_modified(self, **params):
186186
"""
187187
prefixes = params.get("prefixes")
188188
if not prefixes:
189-
return request.not_found()
189+
raise request.not_found()
190190

191191
prefixes_list = prefixes.split(",")
192192

@@ -202,7 +202,7 @@ def get_last_modified(self, **params):
202202
)
203203

204204
if not attachments:
205-
return request.not_found()
205+
raise request.not_found()
206206

207207
# Find the latest create_date
208208
latest_timestamp = max(

web_iconify_proxy/static/description/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ <h1 class="title">Web Iconify Proxy</h1>
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370370
!! source digest: sha256:540c039653c052dd03103f8763a28c639f23b6e3a74191b78a2dd984352b5127
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/18.0/web_iconify_proxy"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_iconify_proxy"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/18.0/web_iconify_proxy"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_iconify_proxy"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>This module acts as a proxy for the Iconify API, allowing Odoo to fetch
374374
icons through the Odoo server rather than directly from the Iconify API.
375375
This improves performance by caching the icons locally using Odoo’s

web_iconify_proxy/tests/test_main.py

+47-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
from unittest.mock import patch
23

34
import requests
@@ -8,21 +9,42 @@
89

910
@tagged("post_install", "-at_install")
1011
class TestIconifyProxyController(HttpCase):
11-
def test_get_svg_success(self):
12+
@patch("odoo.addons.web_iconify_proxy.controllers.main.requests.get")
13+
def test_get_svg_success(self, mock_get):
14+
mock_response = requests.Response()
15+
mock_response.status_code = 200
16+
mock_response._content = b"<svg>dummy content</svg>"
17+
mock_response.headers["Content-Type"] = "image/svg+xml"
18+
mock_get.return_value = mock_response
19+
1220
response = self.url_open("/web_iconify_proxy/mdi/home.svg")
1321
self.assertEqual(response.status_code, 200)
1422
self.assertEqual(response.headers["Content-Type"], "image/svg+xml")
1523
# Add basic check for SVG content (can be improved)
1624
self.assertTrue(b"<svg" in response.content)
1725

18-
def test_get_css_success(self):
26+
@patch("odoo.addons.web_iconify_proxy.controllers.main.requests.get")
27+
def test_get_css_success(self, mock_get):
28+
mock_response = requests.Response()
29+
mock_response.status_code = 200
30+
mock_response._content = b".iconify { color: red; }"
31+
mock_response.headers["Content-Type"] = "text/css"
32+
mock_get.return_value = mock_response
33+
1934
response = self.url_open("/web_iconify_proxy/mdi.css?icons=home,account")
2035
self.assertEqual(response.status_code, 200)
2136
self.assertEqual(response.headers["Content-Type"], "text/css")
2237
# Add basic check for CSS content
2338
self.assertTrue(b".iconify" in response.content)
2439

25-
def test_get_json_success(self):
40+
@patch("odoo.addons.web_iconify_proxy.controllers.main.requests.get")
41+
def test_get_json_success(self, mock_get):
42+
mock_response = requests.Response()
43+
mock_response.status_code = 200
44+
mock_response._content = b'{"prefix": "mdi", "icons": {"home": {}}}'
45+
mock_response.headers["Content-Type"] = "application/json"
46+
mock_get.return_value = mock_response
47+
2648
response = self.url_open("/web_iconify_proxy/mdi.json?icons=home,account")
2749
self.assertEqual(response.status_code, 200)
2850
self.assertEqual(response.headers["Content-Type"], "application/json")
@@ -46,6 +68,21 @@ def test_get_json_invalid_icons(self):
4668
self.assertEqual(response.status_code, 404)
4769

4870
def test_get_last_modified(self):
71+
# Create a dummy attachment
72+
attachment = (
73+
self.env["ir.attachment"]
74+
.sudo()
75+
.create(
76+
{
77+
"name": "mdi-test",
78+
"datas": base64.b64encode(b"dummy data").decode("utf-8"),
79+
"res_model": "iconify.svg",
80+
"res_id": 0,
81+
"type": "binary",
82+
}
83+
)
84+
)
85+
4986
response = self.url_open("/web_iconify_proxy/last-modified?prefixes=mdi")
5087
self.assertEqual(response.status_code, 200)
5188
self.assertEqual(response.headers["Content-Type"], "application/json")
@@ -55,6 +92,9 @@ def test_get_last_modified(self):
5592
except ValueError:
5693
self.fail("last-modified did not return a valid timestamp")
5794

95+
# Clean up the attachment
96+
attachment.unlink()
97+
5898
def test_get_last_modified_no_prefix(self):
5999
response = self.url_open("/web_iconify_proxy/last-modified")
60100
self.assertEqual(response.status_code, 404)
@@ -93,5 +133,7 @@ def test_caching(self, mock_get):
93133
def test_api_error(self, mock_get):
94134
# Mock requests.get to simulate an API error
95135
mock_get.side_effect = requests.exceptions.RequestException("Simulated Error")
96-
response = self.url_open("/web_iconify_proxy/mdi/home.svg")
97-
self.assertEqual(response.status_code, 404)
136+
with self.assertLogs(level="ERROR") as log:
137+
response = self.url_open("/web_iconify_proxy/mdi/home.svg")
138+
self.assertEqual(response.status_code, 404) # Expect 404 Not Found
139+
self.assertIn("Simulated Error", log.output[0])

web_no_bubble/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Web No Bubble",
66
"version": "18.0.1.0.0",
7-
"author": "Savoir-faire Linux, " "Odoo Community Association (OCA)",
7+
"author": "Savoir-faire Linux, Odoo Community Association (OCA)",
88
"website": "https://github.com/OCA/web",
99
"license": "AGPL-3",
1010
"category": "Web",

web_notify/README.rst

+16-16
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ This technical module allows you to send instant notification messages
3434
from the server to the user in live. Two kinds of notification are
3535
supported.
3636

37-
- Success: Displayed in a success theme color flying popup div
38-
- Danger: Displayed in a danger theme color flying popup div
39-
- Warning: Displayed in a warning theme color flying popup div
40-
- Information: Displayed in a info theme color flying popup div
41-
- Default: Displayed in a default theme color flying popup div
37+
- Success: Displayed in a success theme color flying popup div
38+
- Danger: Displayed in a danger theme color flying popup div
39+
- Warning: Displayed in a warning theme color flying popup div
40+
- Information: Displayed in a info theme color flying popup div
41+
- Default: Displayed in a default theme color flying popup div
4242

4343
**Table of contents**
4444

@@ -87,8 +87,8 @@ or
8787
8888
The notifications can bring interactivity with some buttons.
8989

90-
- One allowing to refresh the active view
91-
- Another allowing to send a window / client action
90+
- One allowing to refresh the active view
91+
- Another allowing to send a window / client action
9292

9393
The reload button is activated when sending the notification with:
9494

@@ -142,17 +142,17 @@ Authors
142142
Contributors
143143
------------
144144

145-
- Laurent Mignon <laurent.mignon@acsone.eu>
146-
- Serpent Consulting Services Pvt. Ltd.<jay.vora@serpentcs.com>
147-
- Aitor Bouzas <aitor.bouzas@adaptivecity.com>
148-
- Shepilov Vladislav <shepilov.v@protonmail.com>
149-
- Kevin Khao <kevin.khao@akretion.com>
150-
- `Tecnativa <https://www.tecnativa.com>`__:
145+
- Laurent Mignon <laurent.mignon@acsone.eu>
146+
- Serpent Consulting Services Pvt. Ltd.<jay.vora@serpentcs.com>
147+
- Aitor Bouzas <aitor.bouzas@adaptivecity.com>
148+
- Shepilov Vladislav <shepilov.v@protonmail.com>
149+
- Kevin Khao <kevin.khao@akretion.com>
150+
- `Tecnativa <https://www.tecnativa.com>`__:
151151

152-
- David Vidal
152+
- David Vidal
153153

154-
- Nikul Chaudhary <nchaudhary@opensourceintegrators.com>
155-
- Tris Doan <tridm@trobz.com>
154+
- Nikul Chaudhary <nchaudhary@opensourceintegrators.com>
155+
- Tris Doan <tridm@trobz.com>
156156

157157
Other credits
158158
-------------

web_notify/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Send notification messages to user""",
99
"version": "18.0.1.0.1",
1010
"license": "AGPL-3",
11-
"author": "ACSONE SA/NV," "AdaptiveCity," "Odoo Community Association (OCA)",
11+
"author": "ACSONE SA/NV,AdaptiveCity,Odoo Community Association (OCA)",
1212
"development_status": "Production/Stable",
1313
"website": "https://github.com/OCA/web",
1414
"depends": ["web", "bus", "base", "mail"],

0 commit comments

Comments
 (0)