Skip to content

Commit

Permalink
Merge PR #329 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by fcayre
  • Loading branch information
github-grap-bot committed Oct 20, 2024
2 parents 960f1f6 + fdb3a57 commit 605c7be
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
24 changes: 24 additions & 0 deletions product_rental/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import lxml.html
from mock import patch

from odoo import api
from odoo.tests.common import SavepointCase

from odoo.addons.queue_job.tests.common import trap_jobs
from odoo.addons.website.models.website import Website # see mock
from odoo.addons.website.tools import MockRequest

from ..models.contract import NO_DATE

Expand Down Expand Up @@ -250,3 +254,23 @@ def _contract_line(self, num, name, product_tax=None, **kwargs):

class RentalSaleOrderTC(MockedEmptySessionMixin, RentalSaleOrderMixin, SavepointCase):
pass


class WebsiteBaseTC(RentalSaleOrderTC):
def setUp(self):
super().setUp()
self.partner = self.env.ref("base.partner_demo_portal")
# Use a portal user to avoid language selector rendering
# (other page is editable and the selector is more complex)
env = api.Environment(self.env.cr, self.partner.user_ids[0].id, {})
self.website = self.env.ref("website.default_website").with_env(env)

def render_view(self, ref, **render_kwargs):
view = self.env.ref(ref)
with patch.object(Website, "get_alternate_languages", return_value=()):
with MockRequest(self.env, website=self.website) as request:
request.httprequest.args = []
request.httprequest.query_string = ""
request.endpoint_arguments = {}
html = view.render(render_kwargs)
return lxml.html.fromstring(html)
29 changes: 3 additions & 26 deletions product_rental/tests/test_website.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,21 @@
import lxml.html
from mock import patch

from odoo import api

from odoo.addons.website.models.website import Website # see mock
from odoo.addons.website.tools import MockRequest

from .common import RentalSaleOrderTC
from .common import WebsiteBaseTC


def _clean_text(node):
return " ".join(t.strip() for t in node.itertext() if t.strip())


class WebsiteTC(RentalSaleOrderTC):
class WebsiteTC(WebsiteBaseTC):
def setUp(self):
super().setUp()
partner = self.env.ref("base.partner_demo_portal")
self.so = self.create_sale_order(partner)
self.so = self.create_sale_order(self.partner)
self.so.action_confirm()
# Use a portal user to avoid language selector rendering
# (other page is editable and the selector is more complex)
env = api.Environment(self.env.cr, partner.user_ids[0].id, {})
self.website = self.env.ref("website.default_website").with_env(env)
self.contracts = self.env["contract.contract"].search(
[
("name", "ilike", "%" + self.so.name + "%"),
]
)

def render_view(self, ref, **render_kwargs):
view = self.env.ref(ref)
with patch.object(Website, "get_alternate_languages", return_value=()):
with MockRequest(self.env, website=self.website) as request:
request.httprequest.args = []
request.httprequest.query_string = ""
request.endpoint_arguments = {}
html = view.render(render_kwargs)
return lxml.html.fromstring(html)

def test_portal_sale_order_view(self):
doc = self.render_view(
"sale.sale_order_portal_template", sale_order=self.so, website=self.website
Expand Down
1 change: 1 addition & 0 deletions website_sale_b2b/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import test_payment_portal_templates
from . import test_portal_wizard
from . import test_pricelist
from . import test_sale_order
Expand Down
14 changes: 14 additions & 0 deletions website_sale_b2b/tests/test_payment_portal_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from odoo.addons.product_rental.tests.test_website import WebsiteBaseTC


class PaymentPortalTemplatesTC(WebsiteBaseTC):
def setUp(self):
super().setUp()

def test_render_payment_portal_templates(self):
view = self.render_view(
"website_sale_b2b.payment_tokens_list",
is_big_b2b=True,
is_authorized_to_order=True,
)
self.assertIn("Submit my request", view.text_content())
2 changes: 1 addition & 1 deletion website_sale_b2b/views/payment_portal_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
method="post"
class="clearfix">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
<input type="hidden" name="order_id" t-att-value="order.id"/>
<input type="hidden" name="order_id" t-att-value="order_id"/>
<div class="float-left mt-2">
<a role="button" href="/shop/cart" class="btn btn-secondary">
<i class="fa fa-chevron-left"/>
Expand Down

0 comments on commit 605c7be

Please sign in to comment.