Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if we can run the tests without fiddling with the request layers #247

Merged
merged 4 commits into from
May 24, 2024
Merged
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
28 changes: 21 additions & 7 deletions src/osha/oira/content/tests/test_risk.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from osha.oira import interfaces
from osha.oira.testing import OiRAIntegrationTestCase
from plonetheme.nuplone.z3cform.widget import SingleRadioWidget
from z3c.form.browser.select import SelectWidget
from z3c.form.interfaces import IFieldWidget
from zope.interface import alsoProvides
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary

Expand All @@ -24,17 +22,34 @@ def createModule(self, algorithm="kinney", sector_name="sector"):
survey = self._create(surveygroup, "euphorie.survey", "survey")
return self._create(survey, "euphorie.module", "module")

def test_request_layers(self):
"""Test that request layers are set up correctly."""
from osha.oira.interfaces import IOSHAContentSkinLayer
from zope.interface import noLongerProvides

# Given we have the IOSHAContentSkinLayer we get the AddView defined in
# out custom package
self.assertTrue(IOSHAContentSkinLayer.providedBy(self.request))
self.assertEqual(
repr(self.portal.restrictedTraverse("++add++euphorie.risk").__class__),
"<class 'osha.oira.content.browser.risk.AddView'>",
)

# If we remove the IOSHAContentSkinLayer we get the AddView
# that comes from euphorie
noLongerProvides(self.request, IOSHAContentSkinLayer)
self.assertEqual(
repr(self.portal.restrictedTraverse("++add++euphorie.risk").__class__),
"<class 'euphorie.content.browser.risk.AddView'>",
)

def testDynamicDescription(self):
"""#3343: Customize infoBubble description according to calculation
method.
"""
self.loginAsPortalOwner()
for risk_type in ["kinney", "french"]:
module = self.createModule(risk_type, "sector-" + risk_type)
# Merely installing the OiRA skin doesn't set it's layer on the
# request. This happens during IBeforeTraverseEvent, so we have to do
# here manually
alsoProvides(self.portal.REQUEST, interfaces.IOSHAContentSkinLayer)

# Test AddForm
form = module.unrestrictedTraverse("++add++euphorie.risk").form_instance
Expand All @@ -58,7 +73,6 @@ def testChoiceWidget(self):
"""#1537 The Choice fields must be uniform and all radio buttons."""
self.loginAsPortalOwner()
module = self.createModule()
alsoProvides(self.portal.REQUEST, interfaces.IOSHAContentSkinLayer)
form = module.unrestrictedTraverse("++add++euphorie.risk").form_instance
form.updateFields()

Expand Down
4 changes: 2 additions & 2 deletions src/osha/oira/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from euphorie.content.interfaces import IEuphorieContentLayer
from osha.oira.nuplone.interfaces import IOiRAFormLayer
from plonetheme.nuplone.skin.interfaces import NuPloneSkin
from zope.interface import Interface


Expand All @@ -8,5 +8,5 @@ class IProductLayer(Interface):
installed."""


class IOSHAContentSkinLayer(IOiRAFormLayer, NuPloneSkin):
class IOSHAContentSkinLayer(IOiRAFormLayer, IEuphorieContentLayer):
"""Marker interface for the CMS/Content editing skin."""
1 change: 1 addition & 0 deletions src/osha/oira/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ftw.upgrade in the package osha.oira.upgrade
-->
<dependencies>
<dependency>profile-euphorie.deployment:default</dependency>
<dependency>profile-pas.plugins.ldap:default</dependency>
<dependency>profile-plone.restapi:default</dependency>
<dependency>profile-ftw.upgrade:default</dependency>
Expand Down