Пример #1
0
    def test_get_measures_order_by_start_date(self):
        dbsession = Session()
        session = self._create_session(dbsession)
        module = session.addChild(
            model.Module(
                session=session,
                zodb_path='1',
                module_id='1',
            ))
        module.addChild(
            model.Risk(session=session,
                       zodb_path='1/2',
                       risk_id='1',
                       identification='no',
                       action_plans=[
                           model.ActionPlan(action_plan=u'Plan 2',
                                            planning_start=datetime.date(
                                                2011, 12, 15)),
                           model.ActionPlan(action_plan=u'Plan 1',
                                            planning_start=datetime.date(
                                                2011, 11, 15))
                       ]))

        request = testRequest()
        request.survey = mock.Mock()
        request.survey.restrictedTraverse = lambda x: object
        request.survey.ProfileQuestions = lambda: []
        setRequest(request)
        view = self.ActionPlanTimeline(None, request)
        view.session = session
        measures = view.get_measures()
        self.assertEqual(len(measures), 2)
        self.assertEqual([row[2].action_plan for row in measures],
                         [u'Plan 1', u'Plan 2'])
Пример #2
0
 def beforeTearDown(self):
     from euphorie.client import model
     from euphorie.client import utils
     from z3c.saconfig import Session
     Session.remove()
     model.metadata.drop_all(Session.bind)
     utils.setRequest(None)
Пример #3
0
    def test_get_measures_filter_on_session(self):
        dbsession = Session()
        sessions = []
        for login in ['jane', 'john']:
            session = self._create_session(dbsession, loginname=login)
            module = session.addChild(
                model.Module(
                    session=session,
                    zodb_path='1',
                    module_id='1',
                ))
            module.addChild(
                model.Risk(session=session,
                           zodb_path='1/2',
                           risk_id='1',
                           identification='no',
                           action_plans=[
                               model.ActionPlan(
                                   action_plan=u'Measure 1 for %s' % login)
                           ]))
            sessions.append(session)

        request = testRequest()
        request.survey = mock.Mock()
        request.survey.restrictedTraverse = lambda x: object
        request.survey.ProfileQuestions = lambda: []
        setRequest(request)
        view = self.ActionPlanTimeline(None, request)
        view.session = sessions[0]
        measures = view.get_measures()
        self.assertEqual(len(measures), 1)
        self.assertEqual(measures[0][2].action_plan, 'Measure 1 for jane')
    def testUnpublishWithActiveSession(self):
        """When a survey gets unpublished, while it's still in an active
        session, then WebHelpers.survey_url must return None, not fail.
        """
        survey = self.createSurvey()
        client_survey = getSite().client.nl.ict['software-development']
        request = testRequest()
        request.client = client_survey
        utils.setRequest(request)
        account = model.Account(loginname="jane", password=u"john")
        mgr = session.SessionManagerFactory()
        mgr.start(u"Test session", client_survey, account)
        mgr.session.zodb_path = '/'.join(client_survey.getPhysicalPath())

        helpers = utils.WebHelpers(survey, request)
        self.assertEqual(
                helpers.survey_url(),
                client_survey.absolute_url())

        self.handleSurveyUnpublish(survey, None)

        helpers = utils.WebHelpers(survey, request)
        self.assertEqual(
                helpers.survey_url(),
                None)
Пример #5
0
 def test_create_workbook_no_problem_description(self):
     dbsession = Session()
     session = self._create_session(dbsession)
     module = model.Module(
         zodb_path='1',
         path='001',
         title=u'Top-level Module title',
     )
     risk = model.Risk(zodb_path='1/2/3',
                       risk_id='1',
                       title=u'Risk title',
                       priority='high',
                       identification='no',
                       path='001002003',
                       comment=u'Risk comment')
     request = testRequest()
     request.survey = mock.Mock()
     request.survey.ProfileQuestions = lambda: []
     zodb_node = mock.Mock()
     zodb_node.title = u'Risk title.'
     zodb_node.problem_description = u'  '
     request.survey.restrictedTraverse.return_value = zodb_node
     setRequest(request)
     view = self.ActionPlanTimeline(None, request)
     view.session = session
     view.getRisks = lambda x: [(module, risk)]
     sheet = view.create_workbook().worksheets[0]
     self.assertEqual(sheet.cell('J2').value, u'Risk title')
Пример #6
0
    def testUnpublishWithActiveSession(self):
        """When a survey gets unpublished, while it's still in an active
        session, then WebHelpers.survey_url must return None, not fail.
        """
        survey = self.createSurvey()
        client_survey = getSite().client.nl.ict['software-development']
        request = testRequest()
        request.client = client_survey
        utils.setRequest(request)
        account = model.Account(loginname="jane", password=u"john")
        mgr = session.SessionManagerFactory()
        mgr.start(u"Test session", client_survey, account)
        mgr.session.zodb_path = '/'.join(client_survey.getPhysicalPath())

        helpers = utils.WebHelpers(survey, request)
        self.assertEqual(
                helpers.survey_url(),
                client_survey.absolute_url())

        self.handleSurveyUnpublish(survey, None)

        helpers = utils.WebHelpers(survey, request)
        self.assertEqual(
                helpers.survey_url(),
                None)
Пример #7
0
 def test_create_workbook_empty_session(self):
     # If there are no risks only the header row should be generated.
     request = testRequest()
     request.survey = None
     setRequest(request)
     view = self.ActionPlanTimeline(None, request)
     view.getModulePaths = lambda: []
     book = view.create_workbook()
     self.assertEqual(len(book.worksheets), 1)
     sheet = book.worksheets[0]
     self.assertEqual(len(sheet.rows), 1)
Пример #8
0
    def publishTraverse(self, request, name):
        from euphorie.client.utils import setRequest
        setRequest(request)
        request.client = self.context
        if name == 'api':
            return access_api(request).__of__(self.context)

        ifaces = [iface for iface in directlyProvidedBy(request)
                  if not IBrowserSkinType.providedBy(iface)]
        directlyProvides(request, IOSHAClientSkinLayer, ifaces)
        return super(ClientPublishTraverser, self).publishTraverse(request, name)
Пример #9
0
    def publishTraverse(self, request, name):
        from euphorie.client.utils import setRequest

        setRequest(request)
        request.client = self.context

        ifaces = [
            iface
            for iface in directlyProvidedBy(request)
            if not IBrowserSkinType.providedBy(iface)
        ]
        directlyProvides(request, IOSHAClientSkinLayer, ifaces)
        return super(ClientPublishTraverser, self).publishTraverse(request, name)
Пример #10
0
 def _get_view(self, name, obj, survey_session=None, client=None):
     """Get's a view with a proper fresh request.
     If survey_session is set the SessionManager will be configured
     """
     old_request = getRequest()
     request = self.get_client_request(client=client)
     if survey_session is not None:
         request.other["euphorie.session"] = survey_session
     try:
         setRequest(request)
         yield api.content.get_view(name, obj, request)
     finally:
         setRequest(old_request)
Пример #11
0
 def testCachedSessionId(self):
     from euphorie.client.tests.utils import testRequest
     from euphorie.client.utils import setRequest
     from euphorie.client import session
     request = testRequest()
     marker = []
     ses = Mock(id=marker)
     request.other["euphorie.session"] = ses
     mgr = session.SessionManagerFactory()
     setRequest(request)
     try:
         self.failUnless(mgr.id is marker)
     finally:
         setRequest(None)
Пример #12
0
    def setUp(self):
        super(SurveySessionTests, self).setUp()
        self.loginAsPortalOwner()
        addSurvey(self.portal, SURVEY)
        self.survey = self.portal.client.nl["ict"]["software-development"]

        class DummyObj(object):
            problem_description = u'A Tricky Problem'

        self.survey.restrictedTraverse = lambda path: DummyObj()
        self.request = self.portal.REQUEST
        self.request.survey = self.survey
        self.request.other["euphorie.session"] = createSurveySession()
        utils.setRequest(self.request)
        interface.alsoProvides(self.request, interfaces.IOSHAClientSkinLayer)
Пример #13
0
 def setupSession(self, view):
     from euphorie.client.utils import setRequest
     from euphorie.client.model import SurveySession
     from AccessControl.SecurityManagement import getSecurityManager
     from AccessControl.SecurityManagement import setSecurityManager
     from AccessControl.SecurityManagement import newSecurityManager
     setRequest(self.portal.REQUEST)
     sm = getSecurityManager()
     # Add stub for copySessionData since it tries to run SQL code which
     # SQLite does not handle (UPDATE FROM)
     _copySessionData = SurveySession.copySessionData
     SurveySession.copySessionData = lambda *a: None
     try:
         newSecurityManager(None, self.session.account)
         return view.setupSession()
     finally:
         SurveySession.copySessionData = _copySessionData
         setSecurityManager(sm)
         setRequest(None)
Пример #14
0
    def setupSession(self, view):
        from euphorie.client.utils import setRequest
        from euphorie.client.model import SurveySession
        from AccessControl.SecurityManagement import getSecurityManager
        from AccessControl.SecurityManagement import setSecurityManager
        from AccessControl.SecurityManagement import newSecurityManager

        setRequest(self.portal.REQUEST)
        sm = getSecurityManager()
        # Add stub for copySessionData since it tries to run SQL code which
        # SQLite does not handle (UPDATE FROM)
        _copySessionData = SurveySession.copySessionData
        SurveySession.copySessionData = lambda *a: None
        try:
            newSecurityManager(None, self.session.account)
            return view.setupSession()
        finally:
            SurveySession.copySessionData = _copySessionData
            setSecurityManager(sm)
            setRequest(None)
Пример #15
0
    def testNewSession(self):
        import mock
        from euphorie.client.tests.utils import testRequest
        from euphorie.client.utils import setRequest
        from euphorie.client import model
        from euphorie.client import session

        request = testRequest()
        mgr = session.SessionManagerFactory()
        request.client = survey = object()
        setRequest(request)
        try:
            account = model.Account(loginname="jane", password=u"john")
            with mock.patch('euphorie.client.session.create_survey_session') \
                    as mock_create:
                survey_session = mock.Mock()
                survey_session.id = 43
                mock_create.return_value = survey_session
                ses = mgr.start(u"Test session", survey, account)
                self.assertTrue(ses is survey_session)
                self.failUnless(request.other["euphorie.session"] is ses)
        finally:
            setRequest(None)
Пример #16
0
 def test_get_measures_return_risks_without_measures(self):
     dbsession = Session()
     session = self._create_session(dbsession)
     module = session.addChild(
         model.Module(
             session=session,
             zodb_path='1',
             module_id='1',
         ))
     module.addChild(
         model.Risk(session=session,
                    zodb_path='1/2',
                    risk_id='1',
                    identification='no'))
     request = testRequest()
     request.survey = mock.Mock()
     request.survey.restrictedTraverse = lambda x: object
     request.survey.ProfileQuestions = lambda: []
     setRequest(request)
     view = self.ActionPlanTimeline(None, request)
     view.session = session
     measures = view.get_measures()
     self.assertEqual(len(measures), 1)
     self.assertEqual(measures[0][2], None)
Пример #17
0
 def publishTraverse(self, request, name):
     setRequest(request)
     request.client = self.context
     directlyProvides(request, IOSHAClientSkinLayer)
     return super(HomePagePublishTraverser,
                  self).publishTraverse(request, name)
Пример #18
0
 def setUp(self):
     from ..utils import setRequest
     from .utils import testRequest
     setRequest(testRequest())
     super(SessionManagerFactoryTests, self).setUp()
Пример #19
0
 def tearDown(self):
     from ..utils import setRequest
     setRequest(None)
     super(SessionManagerFactoryTests, self).tearDown()
Пример #20
0
    def setUp(self):
        super(SurveySessionTests, self).setUp()
        self.loginAsPortalOwner()
        addSurvey(self.portal, SURVEY)
        self.survey = self.portal.client.nl["ict"]["software-development"]

        class DummyObj(object):
            problem_description = u'A Tricky Problem'

        self.survey.restrictedTraverse = lambda path: DummyObj()
        self.request = self.portal.REQUEST
        self.request.survey = self.survey
        self.request.other["euphorie.session"] = createSurveySession()
        utils.setRequest(self.request)
        interface.alsoProvides(self.request, interfaces.IOSHAClientSkinLayer)

        self.module = model.Module(
            zodb_path='1',
            path='001001',
            title=u'Shops are clean - Somerset West',
        )
        self.risk1 = model.Risk(
            zodb_path='504/277/444', risk_id='1',
            title=u"Le conducteur est-il prot\xe9g\xe9 des autres v\xe9hicules lorsqu'il circule au sol ?",
            priority='medium',
            identification='no',
            path='001001001',
        )
        self.risk2 = model.Risk(
            zodb_path='504/277/444', risk_id='1',
            title=u"Le conducteur effectue-t-il toutes ses man\u0153uvres d'accroche/d\xe9croche depuis le sol ?",
            priority='high',
            identification='no',
            path='001001002',
        )
        self.risk3_no = model.Risk(
            zodb_path='504/277/385', risk_id='1',
            title=u'Le conducteur descend-il de sa cabine en utilisant les marches ?',
            priority='low',
            identification='no',
            path='001001003',
        )
        self.risk3_yes = model.Risk(
            zodb_path='504/277/385', risk_id='1',
            title=u'Le conducteur descend-il de sa cabine en utilisant les marches ?',
            priority='low',
            identification='yes',
            path='001001003',
        )
        self.risk4 = model.Risk(
            zodb_path='504/277/383', risk_id='1',
            title=u'Un autre risque ?',
            priority='medium',
            identification=None,
            path='001001004',
        )
        self.risk5 = model.Risk(
            zodb_path='504/277/444', risk_id='1',
            title=u'Encore un autre risque ?',
            priority='low',
            identification=None,
            path='001001005',
            postponed=True,
        )
Пример #21
0
 def publishTraverse(self, request, name):
     setRequest(request)
     request.client = self.context
     directlyProvides(request, IOSHAClientSkinLayer)
     return super(HomePagePublishTraverser,
                  self).publishTraverse(request, name)
Пример #22
0
    def setUp(self):
        super(SurveySessionTests, self).setUp()
        self.loginAsPortalOwner()
        addSurvey(self.portal, SURVEY)
        self.survey = self.portal.client.nl["ict"]["software-development"]

        class DummyObj(object):
            problem_description = "A Tricky Problem"

        self.survey.restrictedTraverse = lambda path: DummyObj()
        self.request = self.portal.REQUEST
        self.request.survey = self.survey
        self.request.other["euphorie.session"] = createSurveySession()
        utils.setRequest(self.request)
        interface.alsoProvides(self.request, interfaces.IOSHAClientSkinLayer)

        self.module = model.Module(
            zodb_path="1",
            path="001001",
            title="Shops are clean - Somerset West",
        )
        self.risk1 = model.Risk(
            zodb_path="504/277/444",
            risk_id="1",
            title=
            "Le conducteur est-il prot\xe9g\xe9 des autres v\xe9hicules lorsqu'il circule au sol ?",  # noqa: E501
            priority="medium",
            identification="no",
            path="001001001",
        )
        self.risk2 = model.Risk(
            zodb_path="504/277/444",
            risk_id="1",
            title=
            "Le conducteur effectue-t-il toutes ses man\u0153uvres d'accroche/d\xe9croche depuis le sol ?",  # noqa: E501
            priority="high",
            identification="no",
            path="001001002",
        )
        self.risk3_no = model.Risk(
            zodb_path="504/277/385",
            risk_id="1",
            title=
            "Le conducteur descend-il de sa cabine en utilisant les marches ?",
            priority="low",
            identification="no",
            path="001001003",
        )
        self.risk3_yes = model.Risk(
            zodb_path="504/277/385",
            risk_id="1",
            title=
            "Le conducteur descend-il de sa cabine en utilisant les marches ?",
            priority="low",
            identification="yes",
            path="001001003",
        )
        self.risk4 = model.Risk(
            zodb_path="504/277/383",
            risk_id="1",
            title="Un autre risque ?",
            priority="medium",
            identification=None,
            path="001001004",
        )
        self.risk5 = model.Risk(
            zodb_path="504/277/444",
            risk_id="1",
            title="Encore un autre risque ?",
            priority="low",
            identification=None,
            path="001001005",
            postponed=True,
        )