-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add behavior to hide modules from trainings. #669
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
148 changes: 148 additions & 0 deletions
148
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,148 @@ | ||
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 z3c.saconfig import Session | ||
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() | ||
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"] | ||
) | ||
from plone.dexterity.schema import SCHEMA_CACHE | ||
|
||
SCHEMA_CACHE.invalidate("euphorie.module") | ||
|
||
def create_content(self, survey_xml): | ||
session = Session() | ||
self.account = addAccount(password="secret") | ||
with api.env.adopt_user("admin"): | ||
addSurvey(self.portal, survey_xml) | ||
self.survey = self.portal.client.nl.sector.survey | ||
alsoProvides(self.survey.REQUEST, IClientSkinLayer) | ||
|
||
survey_session = model.SurveySession( | ||
title="Dummy session", | ||
zodb_path="nl/sector/survey", | ||
account=self.account, | ||
) | ||
session.add(survey_session) | ||
|
||
module1 = survey_session.addChild( | ||
model.Module(title="module1", module_id="module1", zodb_path="1"), | ||
) | ||
module1.addChild( | ||
model.Risk(title="risk11", risk_id="risk11", zodb_path="1/2"), | ||
) | ||
module2 = survey_session.addChild( | ||
model.Module(title="module2", module_id="module2", zodb_path="3"), | ||
) | ||
module2.addChild( | ||
model.Risk(title="risk21", risk_id="risk21", zodb_path="3/4"), | ||
) | ||
session.flush() | ||
|
||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, thanks. didn't think of the schema cache!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't even aware it existed - I did a quick step through and got lucky because I noticed it. 😄