Exemple #1
0
 def testRemoveModule(self):
     session = self.createSurveySession()
     session.addChild(
             model.Module(title=u"Root", module_id="1", zodb_path="1"))
     survey = self.createClientSurvey()
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([("1", "module", "remove")]))
Exemple #2
0
 def testRemoveModule(self):
     session = self.createSurveySession()
     session.addChild(
         model.Module(title="Root", module_id="1", zodb_path="1"))
     survey = self.createClientSurvey()
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([("1", "module", "remove")]))
Exemple #3
0
def set_session_profile(survey, survey_session, profile):
    """Set up the survey session using a given profile.

    :param survey: the survey to use
    :type survey: :py:class:`euphorie.content.survey.Survey`
    :param survey_session: survey session to update
    :type survey_session: :py:class:`euphorie.client.model.SurveySession`
    :param dict profile: desired profile
    :rtype: :py:class:`euphorie.client.model.SurveySession`
    :return: the update session (this might be a new session)

    This will rebuild the survey session tree if the profile has changed.
    """
    if not survey_session.hasTree():
        BuildSurveyTree(survey, profile, survey_session)
        return survey_session

    current_profile = extractProfile(survey, survey_session)
    if current_profile == profile and not treeChanges(survey_session, survey):
        survey_session.touch()
        return survey_session

    new_session = create_survey_session(survey_session.title, survey,
                                        survey_session.account)
    BuildSurveyTree(survey, profile, new_session, survey_session)
    new_session.copySessionData(survey_session)
    object_session(survey_session).delete(survey_session)
    return new_session
Exemple #4
0
 def testProfileActsAsModule(self):
     session = self.createSurveySession()
     session.addChild(model.Module(title=u"Root", module_id="1", zodb_path="1"))
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.profilequestion", "1")
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([]))
Exemple #5
0
def set_session_profile(survey, survey_session, profile):
    """Set up the survey session using a given profile.

    :param survey: the survey to use
    :type survey: :py:class:`euphorie.content.survey.Survey`
    :param survey_session: survey session to update
    :type survey_session: :py:class:`euphorie.client.model.SurveySession`
    :param dict profile: desired profile
    :rtype: :py:class:`euphorie.client.model.SurveySession`
    :return: the update session (this might be a new session)

    This will rebuild the survey session tree if the profile has changed.
    """
    if not survey_session.hasTree():
        BuildSurveyTree(survey, profile, survey_session)
        return survey_session

    current_profile = extractProfile(survey, survey_session)
    if current_profile == profile and not treeChanges(survey_session, survey):
        survey_session.touch()
        return survey_session

    new_session = create_survey_session(
            survey_session.title, survey, survey_session.account)
    BuildSurveyTree(survey, profile, new_session, survey_session)
    new_session.copySessionData(survey_session)
    object_session(survey_session).delete(survey_session)
    return new_session
Exemple #6
0
 def test_add_new_risk(self):
     session = self.createSurveySession()
     session.addChild(model.Module(title=u"Root", module_id="1", zodb_path="1", has_description=False))
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     survey["1"].invokeFactory("euphorie.risk", "2")
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([("1/2", "risk", "add")]))
Exemple #7
0
 def test_remove_risk(self):
     session = self.createSurveySession()
     session.addChild(model.Module(title=u"Root", module_id="1", zodb_path="1", has_description=False))
     session.addChild(model.Risk(title=u"Risk 1", risk_id="1", zodb_path="1/1", type="risk", identification="no"))
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([("1/1", "risk", "remove")]))
Exemple #8
0
 def testProfileActsAsModule(self):
     session = self.createSurveySession()
     session.addChild(
         model.Module(title="Root", module_id="1", zodb_path="1"))
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.profilequestion", "1")
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([]))
Exemple #9
0
    def setupSession(self):
        """Setup the session for the context survey. This will rebuild the
        session tree if the profile has changed.

        Set up the survey session using a given profile.

        :param survey: the survey to use
        :type survey: :py:class:`euphorie.content.survey.Survey`
        :param survey_session: survey session to update
        :type survey_session: :py:class:`euphorie.client.model.SurveySession`
        :param dict profile: desired profile
        :rtype: :py:class:`euphorie.client.model.SurveySession`
        :return: the update session (this might be a new session)

        This will rebuild the survey session tree if the profile has changed.
        """
        survey = self.context.aq_parent
        survey_session = self.session
        profile = self.getDesiredProfile()
        if not survey_session.hasTree():
            BuildSurveyTree(survey, profile, survey_session)
            return survey_session

        current_profile = extractProfile(survey, survey_session)
        if current_profile == profile and not treeChanges(
                survey_session, survey, profile):
            # At this stage, we actually do not need to touch the session.
            # It is enough that it gets touched when a Risk is edited, or if the
            # tree gets rebuilt due to changes.
            # Touch means: the modification timestamp is set.
            # But we need to make sure the refreshed marker is up to date!
            survey_session.refresh_survey(survey)
            return survey_session

        params = {}
        # Some values might not be present, depending on the type of survey session
        _marker = object()
        for column in survey_session.__table__.columns:
            if column.key not in (
                    "id",
                    "account_id",
                    "title",
                    "created",
                    "modified",
                    "zodb_path",
            ):
                value = getattr(survey_session, column.key, _marker)
                if value is not _marker:
                    params[column.key] = value

        survey_view = api.content.get_view("index_html", survey, self.request)
        new_session = survey_view.create_survey_session(
            survey_session.title, survey_session.account, **params)
        BuildSurveyTree(survey, profile, new_session, survey_session)
        new_session.copySessionData(survey_session)
        object_session(survey_session).delete(survey_session)
        new_session.refresh_survey()
        return new_session
Exemple #10
0
 def testModuleMadeRequired(self):
     session = self.createSurveySession()
     session_module = model.Module(title=u"Root", module_id="1", zodb_path="1", skip_children=True)
     session.addChild(session_module)
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     module = survey["1"]
     module.optional = False
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([("1", "module", "modified")]))
Exemple #11
0
 def test_module_gained_description(self):
     session = self.createSurveySession()
     session_module = model.Module(title=u"Root", module_id="1",
             zodb_path="1", skip_children=False, has_description=False)
     session.addChild(session_module)
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     module = survey['1']
     module.description = u'<p>Hello</p>'
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([('1', 'module', 'modified')]))
Exemple #12
0
 def test_module_made_optionsl(self):
     session = self.createSurveySession()
     session_module = model.Module(title=u"Root", module_id="1",
             zodb_path="1", has_description=False, skip_children=False)
     session.addChild(session_module)
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     module = survey['1']
     module.optional = True
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([]))
Exemple #13
0
 def test_nothing_changes(self):
     session = self.createSurveySession()
     session_module = model.Module(title=u'Root', module_id='1',
             zodb_path='1', skip_children=False, has_description=False)
     session.addChild(session_module)
     session_module.addChild(model.Risk(title=u'Risk 1', risk_id='2',
         zodb_path='1/2', type='risk', identification='no'))
     survey = self.createClientSurvey()
     survey.invokeFactory('euphorie.module', '1')
     survey['1'].invokeFactory('euphorie.risk', '2')
     self.assertEqual(update.treeChanges(session, survey), set())
Exemple #14
0
 def test_add_new_risk(self):
     session = self.createSurveySession()
     session.addChild(
         model.Module(title="Root",
                      module_id="1",
                      zodb_path="1",
                      has_description=False))
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     survey["1"].invokeFactory("euphorie.risk", "2")
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([("1/2", "risk", "add")]))
Exemple #15
0
 def testModuleMadeRequired(self):
     session = self.createSurveySession()
     session_module = model.Module(title="Root",
                                   module_id="1",
                                   zodb_path="1",
                                   skip_children=True)
     session.addChild(session_module)
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     module = survey["1"]
     module.optional = False
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([("1", "module", "modified")]))
Exemple #16
0
    def test_no_changes_with_repeated_profile(self):
        session = self.createSurveySession()
        for i in range(2):
            session_module = model.Module(title=u'Root', module_id='1',
                    zodb_path='1', skip_children=False, profile_index=i)
            session.addChild(session_module)
            session_module.addChild(model.Risk(title=u'Risk 1', risk_id='2',
                zodb_path='1/2', type='risk', identification='no'))

        survey = self.createClientSurvey()
        survey.invokeFactory('euphorie.profilequestion', '1')
        survey['1'].invokeFactory('euphorie.risk', '2')
        self.assertEqual(update.treeChanges(session, survey), set())
Exemple #17
0
 def test_nothing_changes(self):
     session = self.createSurveySession()
     session_module = model.Module(
         title=u"Root", module_id="1", zodb_path="1", skip_children=False, has_description=False
     )
     session.addChild(session_module)
     session_module.addChild(
         model.Risk(title=u"Risk 1", risk_id="2", zodb_path="1/2", type="risk", identification="no")
     )
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     survey["1"].invokeFactory("euphorie.risk", "2")
     self.assertEqual(update.treeChanges(session, survey), set())
Exemple #18
0
    def test_no_changes_with_repeated_profile(self):
        session = self.createSurveySession()
        for i in range(2):
            session_module = model.Module(
                title=u"Root", module_id="1", zodb_path="1", skip_children=False, profile_index=i
            )
            session.addChild(session_module)
            session_module.addChild(
                model.Risk(title=u"Risk 1", risk_id="2", zodb_path="1/2", type="risk", identification="no")
            )

        survey = self.createClientSurvey()
        survey.invokeFactory("euphorie.profilequestion", "1")
        survey["1"].invokeFactory("euphorie.risk", "2")
        self.assertEqual(update.treeChanges(session, survey), set())
Exemple #19
0
 def test_module_gained_description(self):
     session = self.createSurveySession()
     session_module = model.Module(
         title="Root",
         module_id="1",
         zodb_path="1",
         skip_children=False,
         has_description=False,
     )
     session.addChild(session_module)
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     module = survey["1"]
     module.description = "<p>Hello</p>"
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([("1", "module", "modified")]))
Exemple #20
0
 def test_remove_risk(self):
     session = self.createSurveySession()
     session.addChild(
         model.Module(title="Root",
                      module_id="1",
                      zodb_path="1",
                      has_description=False))
     session.addChild(
         model.Risk(
             title="Risk 1",
             risk_id="1",
             zodb_path="1/1",
             type="risk",
             identification="no",
         ))
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([("1/1", "risk", "remove")]))
Exemple #21
0
 def test_module_made_optional(self):
     """
     Note: an optional module is always considered to have a description, so
     that is never gets skipped.
     See https://github.com/euphorie/Euphorie/commit/c277d05
     """
     session = self.createSurveySession()
     session_module = model.Module(
         title="Root",
         module_id="1",
         zodb_path="1",
         has_description=True,
         skip_children=False,
     )
     session.addChild(session_module)
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     module = survey["1"]
     module.optional = True
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([]))
Exemple #22
0
 def test_nothing_changes(self):
     session = self.createSurveySession()
     session_module = model.Module(
         title="Root",
         module_id="1",
         zodb_path="1",
         skip_children=False,
         has_description=False,
     )
     session.addChild(session_module)
     session_module.addChild(
         model.Risk(
             title="Risk 1",
             risk_id="2",
             zodb_path="1/2",
             type="risk",
             identification="no",
         ))
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     survey["1"].invokeFactory("euphorie.risk", "2")
     self.assertEqual(update.treeChanges(session, survey), set())
Exemple #23
0
    def test_no_changes_with_repeated_profile(self):
        session = self.createSurveySession()
        for i in range(2):
            session_module = model.Module(
                title="Root",
                module_id="1",
                zodb_path="1",
                skip_children=False,
                profile_index=i,
            )
            session.addChild(session_module)
            session_module.addChild(
                model.Risk(
                    title="Risk 1",
                    risk_id="2",
                    zodb_path="1/2",
                    type="risk",
                    identification="no",
                ))

        survey = self.createClientSurvey()
        survey.invokeFactory("euphorie.profilequestion", "1")
        survey["1"].invokeFactory("euphorie.risk", "2")
        self.assertEqual(update.treeChanges(session, survey), set())
Exemple #24
0
 def testAddNewModule(self):
     session = self.createSurveySession()
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([("1", "module", "add")]))
Exemple #25
0
 def testAddNewModule(self):
     session = self.createSurveySession()
     survey = self.createClientSurvey()
     survey.invokeFactory("euphorie.module", "1")
     changes = update.treeChanges(session, survey)
     self.assertEqual(changes, set([("1", "module", "add")]))