Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions endpoint_route_handler/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
class IrHttp(models.AbstractModel):
_inherit = "ir.http"

@classmethod
def _endpoint_route_registry(cls, env):
return EndpointRegistry.registry_for(env.cr)
def _endpoint_route_registry(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO there's no reason to change this because this is never bound to a specific env or a request.
That's why I originally thought to pass whatever env you want.
Not a blocker tho.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well become a @staticmethod which receives the cursor as only parameter:

    @staticmethod
    def _endpoint_route_registry(cr):
        return EndpointRegistry.registry_for(cr)

Alternative to ease customization and inheritance:

    def _endpoint_route_registry(self, cr=None):
        return EndpointRegistry.registry_for(cr or self.env.cr)

return EndpointRegistry.registry_for(self.env.cr)

def _generate_routing_rules(self, modules, converters):
# Override to inject custom endpoint rules.
Expand All @@ -28,10 +27,9 @@ def _generate_routing_rules(self, modules, converters):
self._endpoint_routing_rules(),
)

@classmethod
def _endpoint_routing_rules(cls):
def _endpoint_routing_rules(self):
"""Yield custom endpoint rules"""
e_registry = cls._endpoint_route_registry(http.request.env)
e_registry = self._endpoint_route_registry()
for endpoint_rule in e_registry.get_rules():
_logger.debug("LOADING %s", endpoint_rule)
endpoint = endpoint_rule.endpoint
Expand All @@ -43,14 +41,11 @@ def routing_map(self, key=None):
res = super().routing_map(key=key)
return res

@classmethod
def _endpoint_route_last_version(cls):
res = cls._get_routing_map_last_version(http.request.env)
return res
def _endpoint_route_last_version(self):
return self._get_routing_map_last_version()

@classmethod
def _get_routing_map_last_version(cls, env):
return cls._endpoint_route_registry(env).last_version()
def _get_routing_map_last_version(self):
return self._endpoint_route_registry().last_version()

@classmethod
def _auth_method_user_endpoint(cls):
Expand Down
1 change: 1 addition & 0 deletions endpoint_route_handler/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Simone Orsi \<<simone.orsi@camptocamp.com>\>
- Nguyen Minh Chien \<<chien@trobz.com>\>
- Omar Assouma \<<omar.assouma@dataone.eu>\>
8 changes: 8 additions & 0 deletions endpoint_route_handler/tests/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def tearDown(self):
EndpointRegistry.wipe_registry_for(self.env.cr)
super().tearDown()

def test_routing_map_no_request(self):
# Crons, `odoo shell` and core tests build the routing map with no
# request bound. website's TestWebsiteTechnicalPage does, through
# website.technical.page.get_static_routes(). No mocked request here
# on purpose.
self.env.registry.clear_cache("routing")
self.assertTrue(self.env["ir.http"].routing_map())

def test_as_tool_base_data(self):
new_route = make_new_route(self.env)
self.assertEqual(new_route.route, "/my/test/route")
Expand Down
Loading