mirror of
https://gitlab.com/itsulu-odoo/itsulu-blog-publisher.git
synced 2026-05-30 23:41:23 +00:00
fix: create Odoo env directly in BDD fixture; fix _generate_template call
- pytest-odoo 2.x provides no 'env' pytest fixture; env only exists as self.env in TransactionCase subclasses. Build the env from odoo.registry() directly in the odoo_env fixture and rollback after each BDD scenario. - _generate_template() takes positional args (res_ids, render_fields), not keyword args; remove 'fields=' keyword from all call sites. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9948c7aad6
commit
3281298f5e
2 changed files with 17 additions and 5 deletions
|
|
@ -8,6 +8,8 @@ Links: blog_generation.feature, blog_scheduling.feature,
|
|||
RED PHASE — all scenarios FAIL until implementation exists.
|
||||
"""
|
||||
import pytest
|
||||
import odoo
|
||||
from odoo.api import Environment
|
||||
from unittest.mock import patch, MagicMock
|
||||
from pytest_bdd import scenarios, given, when, then, parsers
|
||||
|
||||
|
|
@ -25,8 +27,18 @@ scenarios('../features/notification_email.feature')
|
|||
|
||||
@pytest.fixture
|
||||
def odoo_env(request):
|
||||
"""pytest-odoo's env fixture, re-exported for BDD step access."""
|
||||
return request.getfixturevalue('env')
|
||||
"""Odoo environment for BDD step definitions.
|
||||
|
||||
pytest-odoo 2.x does not expose an 'env' pytest fixture — env only
|
||||
exists as self.env inside TransactionCase subclasses. We build one
|
||||
directly from the registry and roll back after each scenario.
|
||||
"""
|
||||
db = request.config.getoption('--odoo-database')
|
||||
registry = odoo.registry(db)
|
||||
with registry.cursor() as cr:
|
||||
env = Environment(cr, odoo.SUPERUSER_ID, {})
|
||||
yield env
|
||||
cr.rollback()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@ class TestNotificationEmail(TransactionCase):
|
|||
|
||||
# ACT — render the template synchronously to check the subject
|
||||
template = self.env.ref('itsulu_blog_publisher.email_template_blog_published')
|
||||
rendered = template._generate_template([log.id], fields=['subject'])
|
||||
rendered = template._generate_template([log.id], ['subject'])
|
||||
|
||||
# ASSERT
|
||||
subject = rendered[log.id].get('subject', '')
|
||||
|
|
@ -300,7 +300,7 @@ class TestNotificationEmail(TransactionCase):
|
|||
|
||||
# Verify template renders all platform copy in the body
|
||||
template = self.env.ref('itsulu_blog_publisher.email_template_blog_published')
|
||||
rendered = template._generate_template([log.id], fields=['body_html'])
|
||||
rendered = template._generate_template([log.id], ['body_html'])
|
||||
body = rendered[log.id].get('body_html', '')
|
||||
self.assertIn('Twitter A copy', body, "Body must contain Twitter copy")
|
||||
self.assertIn('LinkedIn copy', body, "Body must contain LinkedIn copy")
|
||||
|
|
@ -319,7 +319,7 @@ class TestNotificationEmail(TransactionCase):
|
|||
|
||||
# ASSERT — render the template synchronously to check the URL appears in the body
|
||||
template = self.env.ref('itsulu_blog_publisher.email_template_blog_published')
|
||||
rendered = template._generate_template([log.id], fields=['body_html'])
|
||||
rendered = template._generate_template([log.id], ['body_html'])
|
||||
body = rendered[log.id].get('body_html', '')
|
||||
self.assertIn('itsulu.com', body, "Body must contain itsulu.com URL")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue