-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add behavior to hide modules from trainings.
Ref: scrum-1573
- Loading branch information
Showing
8 changed files
with
239 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
src/euphorie/client/tests/test_training__hide_from_training.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
from euphorie.client import model | ||
from euphorie.client.interfaces import IClientSkinLayer | ||
from euphorie.client.tests.utils import addAccount | ||
from euphorie.client.tests.utils import addSurvey | ||
from euphorie.testing import EuphorieIntegrationTestCase | ||
from plone import api | ||
from zope.interface import alsoProvides | ||
|
||
|
||
SURVEY_1 = """ | ||
<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0"> | ||
<title>sector</title> | ||
<survey> | ||
<title>survey</title> | ||
<language>nl</language> | ||
<module> | ||
<title>module1</title> | ||
<risk> | ||
<title>risk11</title> | ||
<problem_description>problem-desc-11</problem_description> | ||
<description>desc-11</description> | ||
</risk> | ||
</module> | ||
<module> | ||
<title>module2</title> | ||
<risk> | ||
<title>risk21</title> | ||
<problem_description>problem-desc-21</problem_description> | ||
<description>desc-21</description> | ||
</risk> | ||
</module> | ||
</survey> | ||
</sector> | ||
""" | ||
|
||
SURVEY_2 = """ | ||
<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0"> | ||
<title>sector</title> | ||
<survey> | ||
<title>survey</title> | ||
<language>nl</language> | ||
<module hide_from_training="True"> | ||
<title>module1</title> | ||
<risk> | ||
<title>risk11</title> | ||
<problem_description>problem-desc-11</problem_description> | ||
<description>desc-11</description> | ||
</risk> | ||
</module> | ||
<module> | ||
<title>module2</title> | ||
<risk> | ||
<title>risk21</title> | ||
<problem_description>problem-desc-21</problem_description> | ||
<description>desc-21</description> | ||
</risk> | ||
</module> | ||
</survey> | ||
</sector> | ||
""" | ||
|
||
|
||
class TestTrainingHideFromTraining(EuphorieIntegrationTestCase): | ||
"""Tests the IHideFromTraining behavior. | ||
Also tests importing an xml structure with the hide_from_training | ||
attribute set. | ||
""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.account = addAccount(password="secret") | ||
api.portal.set_registry_record("euphorie.use_training_module", True) | ||
|
||
# Add the hide_from_training behavior to the module type | ||
types = api.portal.get_tool("portal_types") | ||
fti_module = types.get("euphorie.module") | ||
fti_module.behaviors = tuple( | ||
list(fti_module.behaviors) + ["euphorie.hide_from_training"] | ||
) | ||
|
||
def create_content(self, survey_xml): | ||
with api.env.adopt_user("admin"): | ||
addSurvey(self.portal, survey_xml) | ||
self.survey = self.portal.client.nl.sector.survey | ||
alsoProvides(self.survey.REQUEST, IClientSkinLayer) | ||
|
||
self.survey_session = model.SurveySession( | ||
title="Dummy session", | ||
zodb_path="nl/sector/survey", | ||
account=self.account, | ||
) | ||
model.Session.add(self.survey_session) | ||
|
||
self.module1 = self.survey_session.addChild( | ||
model.Module(title="module1", module_id="module1", zodb_path="1") | ||
) | ||
self.risk11 = self.module1.addChild( | ||
model.Risk(title="risk11", risk_id="risk11", zodb_path="1/2") | ||
) | ||
self.module2 = self.survey_session.addChild( | ||
model.Module(title="module2", module_id="module2", zodb_path="3") | ||
) | ||
self.risk21 = self.module2.addChild( | ||
model.Risk(title="risk21", risk_id="risk21", zodb_path="3/4") | ||
) | ||
|
||
def test_training_module_visible(self): | ||
"""Test the standard case - all modules and ristsk are visible in the | ||
training. | ||
""" | ||
self.create_content(SURVEY_1) | ||
|
||
traversed_session = self.survey.restrictedTraverse("++session++1") | ||
with api.env.adopt_user(user=self.account): | ||
with self._get_view( | ||
"training", traversed_session, self.request.clone() | ||
) as view: | ||
self.survey.enable_web_training = True | ||
data = list(view.slide_data.values()) | ||
|
||
self.assertEqual(len(data), 4) | ||
self.assertEqual(data[0]["item"].title, "module1") | ||
self.assertEqual(data[1]["item"].title, "risk11") | ||
self.assertEqual(data[2]["item"].title, "module2") | ||
self.assertEqual(data[3]["item"].title, "risk21") | ||
|
||
def test_training_module_hidden(self): | ||
"""Test module1 hidden from training.""" | ||
self.create_content(SURVEY_2) | ||
|
||
traversed_session = self.survey.restrictedTraverse("++session++1") | ||
with api.env.adopt_user(user=self.account): | ||
with self._get_view( | ||
"training", traversed_session, self.request.clone() | ||
) as view: | ||
self.survey.enable_web_training = True | ||
data = list(view.slide_data.values()) | ||
|
||
self.assertEqual(len(data), 2) | ||
self.assertEqual(data[0]["item"].title, "module2") | ||
self.assertEqual(data[1]["item"].title, "risk21") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from .. import MessageFactory as _ | ||
from plone.autoform.directives import order_after | ||
from plone.autoform.interfaces import IFormFieldProvider | ||
from plone.supermodel import model | ||
from zope import schema | ||
from zope.interface import provider | ||
|
||
|
||
@provider(IFormFieldProvider) | ||
class IHideFromTraining(model.Schema): | ||
hide_from_training = schema.Bool( | ||
title=_("label_hide_from_training", default="Hide from training"), | ||
description=_( | ||
"help_hide_from_training", | ||
default="Do not include this module in the training, for example " | ||
"if the module does not have any relevance for workers.", | ||
), | ||
required=False, | ||
default=False, | ||
) | ||
order_after(hide_from_training="question") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters