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)
Beispiel #2
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'])
Beispiel #3
0
 def test_get_measures_with_correct_module(self):
     dbsession = Session()
     session = self._create_session(dbsession)
     # This first module should be ignored, it doesn't contain any risks
     session.addChild(model.Module(
         zodb_path='1',
         module_id='1',
     ))
     # Between the next two modules, the first one (root-level) must be
     # returned.
     module = session.addChild(model.Module(
         zodb_path='2',
         module_id='2',
     ))
     module = module.addChild(model.Module(
         zodb_path='2/3',
         module_id='3',
     ))
     module.addChild(
         model.Risk(zodb_path='2/3/4', risk_id='1', identification='no'))
     request = testRequest()
     request.survey = mock.Mock()
     request.survey.restrictedTraverse = lambda x: object
     request.survey.ProfileQuestions = lambda: []
     view = self.ActionPlanTimeline(None, request)
     view.session = session
     measures = view.get_measures()
     self.assertEqual(len(measures), 1)
     self.assertEqual(measures[0][0].module_id, u'2')
Beispiel #4
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')
Beispiel #5
0
 def test_valid_signature(self):
     import binascii
     from euphorie.client.cookie import _sign
     request = testRequest()
     value = "%s1" % _sign("secret", "1")
     request.cookies["euphorie"] = binascii.b2a_base64(value).rstrip()
     self.assertEqual(self.getCookie(request, "secret", "euphorie"), "1")
    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)
Beispiel #7
0
    def test_create_workbook_no_problem_description(self):
        import datetime
        import mock
        from euphorie.client.tests.utils import testRequest
        from euphorie.client import model

        module = model.Module(zodb_path="1", 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",
        )
        plan = model.ActionPlan(action_plan=u"Plan 2", planning_start=datetime.date(2011, 12, 15), budget=500)
        request = testRequest()
        request.survey = mock.Mock()
        zodb_node = mock.Mock()
        zodb_node.title = u"Risk title."
        zodb_node.problem_description = u"  "
        request.survey.restrictedTraverse.return_value = zodb_node
        view = self.ActionPlanTimeline(None, request)
        view.get_measures = lambda: [(module, risk, plan)]
        sheet = view.create_workbook().worksheets[0]
        self.assertEqual(sheet.cell("J2").value, u"Risk title")
Beispiel #8
0
 def test_valid_signature(self):
     import binascii
     from euphorie.client.cookie import _sign
     request = testRequest()
     value = "%s1" % _sign("secret", "1")
     request.cookies["euphorie"] = binascii.b2a_base64(value).rstrip()
     self.assertEqual(self.getCookie(request, "secret", "euphorie"), "1")
Beispiel #9
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')
Beispiel #10
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)
Beispiel #11
0
 def test_render_value(self):
     request = testRequest()
     request.survey = None
     view = self.ActionPlanTimeline(None, request)
     view.session = SurveySession(title=u'Acme')
     view.render()
     response = request.response
     self.assertEqual(
         response.headers['content-type'], 'application/vnd.openxmlformats-'
         'officedocument.spreadsheetml.sheet')
     self.assertEqual(response.headers['content-disposition'],
                      'attachment; filename="Timeline for Acme.xlsx"')
Beispiel #12
0
    def test_create_workbook_empty_session(self):
        # If there are no risks only the header row should be generated.
        from euphorie.client.tests.utils import testRequest

        request = testRequest()
        request.survey = None
        view = self.ActionPlanTimeline(None, request)
        view.get_measures = lambda: []
        book = view.create_workbook()
        self.assertEqual(len(book.worksheets), 1)
        sheet = book.worksheets[0]
        self.assertEqual(len(sheet.rows), 1)
Beispiel #13
0
    def testBaseURL(self):
        country = self.client['en']
        survey = self.client['en']['sector']['survey']

        request = testRequest()
        request.client = self.client
        view = WebHelpers(self.client, request)
        self.assertTrue(
                view._base_url().startswith(self.client.absolute_url()))
        self.assertFalse(view._base_url().startswith(country.absolute_url()))

        view = WebHelpers(country, testRequest())
        self.assertTrue(view._base_url().startswith(country.absolute_url()))

        request = testRequest()
        view = WebHelpers(survey, testRequest())
        view._survey = survey
        self.assertTrue(view._base_url().startswith(survey.absolute_url()))

        view = WebHelpers(country, testRequest())
        self.assertFalse(view._base_url().startswith(survey.absolute_url()))
        self.assertTrue(view._base_url().startswith(country.absolute_url()))
Beispiel #14
0
    def testBaseURL(self):
        country = self.client['en']
        survey = self.client['en']['sector']['survey']

        request = testRequest()
        request.client = self.client
        view = WebHelpers(self.client, request)
        self.assertTrue(view._base_url().startswith(
            self.client.absolute_url()))
        self.assertFalse(view._base_url().startswith(country.absolute_url()))

        view = WebHelpers(country, testRequest())
        self.assertTrue(view._base_url().startswith(country.absolute_url()))

        request = testRequest()
        view = WebHelpers(survey, testRequest())
        view._survey = survey
        self.assertTrue(view._base_url().startswith(survey.absolute_url()))

        view = WebHelpers(country, testRequest())
        self.assertFalse(view._base_url().startswith(survey.absolute_url()))
        self.assertTrue(view._base_url().startswith(country.absolute_url()))
Beispiel #15
0
 def test_create_workbook_plan_information(self):
     dbsession = Session()
     session = self._create_session(dbsession)
     module = model.Module(
         zodb_path='1',
         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')
     plan = model.ActionPlan(action_plan=u'Plan 2',
                             planning_start=datetime.date(2011, 12, 15),
                             budget=500)
     request = testRequest()
     request.survey = mock.Mock()
     zodb_node = mock.Mock()
     zodb_node.problem_description = u'This is wrong.'
     request.survey.restrictedTraverse.return_value = zodb_node
     view = self.ActionPlanTimeline(None, request)
     view.session = session
     view.get_measures = lambda: [(module, risk, plan)]
     sheet = view.create_workbook().worksheets[0]
     # planning start
     self.assertEqual(
         sheet.cell('A2').value.date(), datetime.date(2011, 12, 15))
     # planning end
     self.assertEqual(sheet.cell('B2').value, None)
     # action plan
     self.assertEqual(sheet.cell('C2').value, u'Plan 2')
     # prevention plan
     self.assertEqual(sheet.cell('D2').value, None)
     # requirements
     self.assertEqual(sheet.cell('E2').value, None)
     # responsible
     self.assertEqual(sheet.cell('F2').value, None)
     # budget
     self.assertEqual(sheet.cell('G2').value, 500)
     # module title
     self.assertEqual(sheet.cell('H2').value, u'Top-level Module title')
     # risk number
     self.assertEqual(sheet.cell('I2').value, u'1.2.3')
     # risk title
     self.assertEqual(sheet.cell('J2').value, u'This is wrong.')
     # risk priority
     self.assertEqual(sheet.cell('K2').value, u'High')
     # risk comment
     self.assertEqual(sheet.cell('L2').value, u'Risk comment')
Beispiel #16
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)
Beispiel #17
0
    def testCachedSession(self):
        from euphorie.client.tests.utils import testRequest
        from euphorie.client.utils import locals
        from euphorie.client import session
        request = testRequest()
        marker = []
        request.other["euphorie.session"] = marker
        mgr = session.SessionManagerFactory()

        locals.request = request
        try:
            self.failUnless(mgr.session is marker)
        finally:
            del locals.request
Beispiel #18
0
    def test_create_workbook_plan_information(self):
        import datetime
        import mock
        from euphorie.client.tests.utils import testRequest
        from euphorie.client import model

        module = model.Module(zodb_path="1", 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",
        )
        plan = model.ActionPlan(action_plan=u"Plan 2", planning_start=datetime.date(2011, 12, 15), budget=500)
        request = testRequest()
        request.survey = mock.Mock()
        zodb_node = mock.Mock()
        zodb_node.problem_description = u"This is wrong."
        request.survey.restrictedTraverse.return_value = zodb_node
        view = self.ActionPlanTimeline(None, request)
        view.get_measures = lambda: [(module, risk, plan)]
        sheet = view.create_workbook().worksheets[0]
        # planning start
        self.assertEqual(sheet.cell("A2").value.date(), datetime.date(2011, 12, 15))
        # planning end
        self.assertEqual(sheet.cell("B2").value, None)
        # action plan
        self.assertEqual(sheet.cell("C2").value, u"Plan 2")
        # prevention plan
        self.assertEqual(sheet.cell("D2").value, None)
        # requirements
        self.assertEqual(sheet.cell("E2").value, None)
        # responsible
        self.assertEqual(sheet.cell("F2").value, None)
        # budget
        self.assertEqual(sheet.cell("G2").value, 500)
        # module title
        self.assertEqual(sheet.cell("H2").value, u"Top-level Module title")
        # risk number
        self.assertEqual(sheet.cell("I2").value, u"1.2.3")
        # risk title
        self.assertEqual(sheet.cell("J2").value, u"This is wrong.")
        # risk priority
        self.assertEqual(sheet.cell("K2").value, u"High")
        # risk comment
        self.assertEqual(sheet.cell("L2").value, u"Risk comment")
Beispiel #19
0
    def test_render_value(self):
        from euphorie.client.tests.utils import testRequest
        from euphorie.client.model import SurveySession

        request = testRequest()
        request.survey = None
        view = self.ActionPlanTimeline(None, request)
        view.session = SurveySession(title=u"Acme")
        view.get_measures = lambda: []
        view.render()
        response = request.response
        self.assertEqual(
            response.headers["content-type"], "application/vnd.openxmlformats-" "officedocument.spreadsheetml.sheet"
        )
        self.assertEqual(response.headers["content-disposition"], 'attachment; filename="Timeline for Acme.xlsx"')
Beispiel #20
0
 def setUp(self):
     super(TestURLs, self).setUp()
     self.loginAsPortalOwner()
     self.client = self.portal.client
     # Set locals
     request = testRequest()
     locals.request = request
     # Add survey
     self.client['en'] = ClientCountry('en')
     country = self.client['en']
     country["sector"] = ClientSector('sector')
     country["sector"].title = u"Test sector"
     country["sector"].id = "sector"
     sector = country["sector"]
     survey = Survey('survey')
     survey.title = u'Test Survey'
     survey.language = 'en'
     sector['survey'] = survey
Beispiel #21
0
 def setUp(self):
     super(TestURLs, self).setUp()
     self.loginAsPortalOwner()
     self.client = self.portal.client
     # Set locals
     request = testRequest()
     locals.request = request
     # Add survey
     self.client['en'] = ClientCountry('en')
     country = self.client['en']
     country["sector"] = ClientSector('sector')
     country["sector"].title = u"Test sector"
     country["sector"].id = "sector"
     sector = country["sector"]
     survey = Survey('survey')
     survey.title = u'Test Survey'
     survey.introduction = u"This is a survey that is well suited for tests"
     survey.language = 'en'
     sector['survey'] = survey
Beispiel #22
0
 def setUp(self):
     super(TestURLs, self).setUp()
     # Set locals
     request = testRequest()
     locals.request = request
     self.loginAsPortalOwner()
     self.client = self.portal.client
     # Add survey
     self.client._setOb("en", ClientCountry("en"))
     country = self.client["en"]
     country._setOb("sector", ClientSector("sector"))
     country["sector"].title = "Test sector"
     country["sector"].id = "sector"
     sector = country["sector"]
     survey = Survey("survey")
     survey.title = "Test Survey"
     survey.introduction = "This is a survey that is well suited for tests"
     survey.language = "en"
     sector._setOb("survey", survey)
Beispiel #23
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)
Beispiel #24
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)
Beispiel #25
0
 def test_no_cookie(self):
     request = testRequest()
     self.assertEqual(self.getCookie(request, "secret", "euphorie"), None)
Beispiel #26
0
 def test_bad_base64(self):
     request = testRequest()
     request.cookies["euphorie"] = "invalid"
     self.assertEqual(self.getCookie(request, "secret", "euphorie"), None)
Beispiel #27
0
 def test_no_cookie(self):
     request = testRequest()
     self.assertEqual(self.getCookie(request, "secret", "euphorie"), None)
Beispiel #28
0
 def test_invalid_signature(self):
     import binascii
     request = testRequest()
     request.cookies["euphorie"] = binascii.b2a_base64(
             "12345678901234567890").rstrip()
     self.assertEqual(self.getCookie(request, "secret", "euphorie"), None)
Beispiel #29
0
 def test_short_cookie(self):
     import binascii
     request = testRequest()
     request.cookies["euphorie"] = binascii.b2a_base64("short").rstrip()
     self.assertEqual(self.getCookie(request, "secret", "euphorie"), None)
Beispiel #30
0
 def test_short_cookie(self):
     import binascii
     request = testRequest()
     request.cookies["euphorie"] = binascii.b2a_base64("short").rstrip()
     self.assertEqual(self.getCookie(request, "secret", "euphorie"), None)
Beispiel #31
0
 def setUp(self):
     from ..utils import setRequest
     from .utils import testRequest
     setRequest(testRequest())
     super(SessionManagerFactoryTests, self).setUp()
Beispiel #32
0
 def test_bad_base64(self):
     request = testRequest()
     request.cookies["euphorie"] = "invalid"
     self.assertEqual(self.getCookie(request, "secret", "euphorie"), None)
Beispiel #33
0
 def test_invalid_signature(self):
     import binascii
     request = testRequest()
     request.cookies["euphorie"] = binascii.b2a_base64(
         "12345678901234567890").rstrip()
     self.assertEqual(self.getCookie(request, "secret", "euphorie"), None)