File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 88from odoo import models
99from odoo .http import request
1010
11+ from odoo .addons .website .models import ir_http
12+
1113
1214class IrHttp (models .AbstractModel ):
1315 _inherit = "ir.http"
@@ -16,6 +18,9 @@ class IrHttp(models.AbstractModel):
1618 def _dispatch (cls ):
1719 res = super (IrHttp , cls )._dispatch ()
1820 # if not website request - skip
21+ if not ir_http .get_request_website ():
22+ return res
23+
1924 website = request .env ["website" ].sudo ().get_current_website ()
2025 if not website :
2126 return res
Original file line number Diff line number Diff line change 66from odoo .tests import HttpCase
77from odoo .tools import mute_logger
88
9+ from odoo .addons .bus .controllers .main import BusController
10+
911
1012class TestIrHttp (HttpCase ):
1113 def setUp (self ):
@@ -70,3 +72,37 @@ def test_dispatch_failed_transaction(self):
7072 ),
7173 )
7274 self .assertEqual (response .status_code , 200 )
75+
76+ def test_dispatch_no_website (self ):
77+ """If the request is not `website`, do not interfere."""
78+ # Arrange
79+ path = "/longpolling/poll"
80+ routing = BusController ().poll .routing
81+ self .auth_url = self .env ["website.auth.url" ].create (
82+ {
83+ "website_id" : self .website .id ,
84+ "path" : path ,
85+ }
86+ )
87+ # pre-condition
88+ self .assertFalse (routing .get ("website" ))
89+ self .assertIn (path , routing .get ("routes" , dict ()))
90+
91+ # Act
92+ response = self .url_open (
93+ path ,
94+ headers = {
95+ "Content-Type" : "application/json" ,
96+ },
97+ data = json .dumps (
98+ {
99+ "params" : {
100+ "channels" : ["Test channel" ],
101+ "last" : 0 ,
102+ },
103+ }
104+ ),
105+ )
106+
107+ # Assert
108+ self .assertEqual (response .status_code , 200 )
You can’t perform that action at this time.
0 commit comments