diff --git a/docs/changes.rst b/docs/changes.rst index c97e9f745..ae664dc66 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,7 +4,9 @@ Changelog 16.2.5 (unreleased) ------------------- -- Nothing changed yet. +- Report: Fix lists of risks (“parked” / not present) + (`#2800 `_) + [reinhardt] 16.2.4 (2024-11-21) @@ -16,9 +18,6 @@ Changelog - Action Plan: Strip HTML from comments (`#2763 `_) [reinhardt] -- Report: Fix “parked” risks - (`#2800 `_) - [reinhardt] 16.2.3 (2024-10-25) diff --git a/src/euphorie/client/model.py b/src/euphorie/client/model.py index ebc2c4db0..0cb3fb4c3 100644 --- a/src/euphorie/client/model.py +++ b/src/euphorie/client/model.py @@ -1963,13 +1963,7 @@ def _MODULE_WITH_RISKS_NOT_PRESENT_FILTER_factory(): RISK_NOT_PRESENT_FILTER = sql.and_( SurveyTreeItem.type == "risk", - sql.exists( - sql.select([Risk.sql_risk_id]).where( - sql.and_( - Risk.sql_risk_id == SurveyTreeItem.id, Risk.identification == "yes" - ) - ) - ), + sql.and_(Risk.sql_risk_id == SurveyTreeItem.id, Risk.identification == "yes"), ) diff --git a/src/euphorie/client/tests/test_report.py b/src/euphorie/client/tests/test_report.py index dad298137..b08bc56a3 100644 --- a/src/euphorie/client/tests/test_report.py +++ b/src/euphorie/client/tests/test_report.py @@ -3,6 +3,7 @@ # from euphorie.client.report import IdentificationReport # from euphorie.content.risk import Risk from euphorie.client import model +from euphorie.client import utils from euphorie.client.adapters.session_traversal import TraversedSurveySession from euphorie.client.interfaces import IClientSkinLayer from euphorie.client.model import SurveySession @@ -12,7 +13,6 @@ from ExtensionClass import Base from plone import api from plone.app.testing.interfaces import SITE_OWNER_NAME -from sqlalchemy import sql from unittest import mock from urllib.parse import quote from z3c.saconfig import Session @@ -520,29 +520,11 @@ def test_render_value(self): ) -def get_unanswered_nodes(session): - query = ( - Session() - .query(model.SurveyTreeItem) - .filter( - sql.and_( - model.SurveyTreeItem.session == session, - sql.or_( - model.MODULE_WITH_UNANSWERED_RISKS_FILTER, - model.UNANSWERED_RISKS_FILTER, - ), - sql.not_(model.SKIPPED_PARENTS), - ) - ) - .order_by(model.SurveyTreeItem.path) - ) - return query.all() - - class UnansweredQueryTests(EuphorieIntegrationTestCase): """Test #2800. Only risks with `identification` == None are returned as unanswered. + They are not returned as not present. """ def createData(self): @@ -598,6 +580,24 @@ def createData(self): ) self.mod1.addChild(self.r1) + self.r3 = model.Risk( + **{ + "risk_id": 2, + "depth": 3, + "identification": "yes", + "action_plans": [], + "has_description": True, + "path": "001001002", + "postponed": False, + "profile_index": 0, + "skip_children": False, + "title": "Feet are washed", + "type": "risk", + "zodb_path": "173/euphorie.risk-1", + } + ) + self.mod1.addChild(self.r3) + self.mod2 = model.Module( **{ "depth": 2, @@ -636,7 +636,16 @@ def testUnansweredNodes(self): self.createData() risks = [ node - for node in get_unanswered_nodes(self.survey_session) + for node in utils.get_unanswered_nodes(self.survey_session) + if node.type == "risk" + ] + self.assertEqual(len(risks), 1) + + def testRiskNotPresentNodes(self): + self.createData() + risks = [ + node + for node in utils.get_risk_not_present_nodes(self.survey_session) if node.type == "risk" ] self.assertEqual(len(risks), 1)