Beispiel #1
0
 def testUnicodeReportFilename(self):
     from euphorie.content.tests.utils import BASIC_SURVEY
     # Test for http://code.simplon.biz/tracker/euphorie/ticket/156
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     browser = Browser()
     survey_url = self.portal.client.nl["ict"]["software-development"]\
             .absolute_url()
     browser.open(survey_url)
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="title:utf8:ustring").value = \
             u"Sessiøn".encode("utf-8")
     browser.getControl(name="next").click()
     # Start the survey
     browser.getForm().submit()
     browser.getLink("Start Risk Identification").click()
     # Force creation of the company data
     browser.open("%s/report/company" % survey_url)
     # Download the report
     browser.handleErrors = False
     browser.open("%s/report/download" % survey_url)
     self.assertEqual(browser.headers.type, "application/rtf")
     self.assertEqual(browser.headers.get("Content-Disposition"),
             'attachment; filename="Action plan Sessi\xc3\xb8n.rtf"')
Beispiel #2
0
 def test_set_unknown_answer_if_skipped(self):
     from euphorie.content.tests.utils import BASIC_SURVEY
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     # Register in the client
     browser = Browser()
     survey_url = self.portal.client.nl['ict']['software-development']\
             .absolute_url()
     browser.open(survey_url)
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name='title:utf8:ustring').value = u'Session'
     browser.getControl(name='next').click()
     # Start the survey
     browser.getForm().submit()
     browser.getLink('Start Risk Identification').click()
     browser.getControl('next').click()
     # No answer should be set on initial view
     self.assertEqual(browser.getControl(name='answer').value, [])
     # Do not give an identification answer
     risk_url = browser.url
     browser.getControl('next').click()
     # Go back and check the new answer
     browser.open(risk_url)
     self.assertTrue(
         'class="current postponed'
         in browser.contents)
Beispiel #3
0
 def testShowFrenchEvaluation(self):
     from euphorie.content.tests.utils import BASIC_SURVEY
     # Test for http://code.simplon.biz/tracker/tno-euphorie/ticket/150
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     browser = Browser()
     survey = self.portal.client.nl["ict"]["software-development"]
     survey.evaluation_algorithm = u"french"
     survey["1"]["2"].type = "risk"
     browser.open(survey.absolute_url())
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="title:utf8:ustring").value = \
             u"Sessiøn".encode("utf-8")
     browser.getControl(name="next").click()
     # Start the survey
     browser.getForm().submit()
     browser.getLink("Start Risk Identification").click()
     # Identify the risk
     browser.getControl("next").click()
     browser.getControl(name="answer").value = ["no"]
     # Verify number of options
     self.assertEqual(
             len(browser.getControl(name="frequency:int").controls), 4)
     self.assertEqual(
             len(browser.getControl(name="severity:int").controls), 4)
     # Enter some digits
     browser.getControl(name="frequency:int").value = ["7"]
     browser.getControl(name="severity:int").value = ["10"]
     browser.getControl("next").click()
     # Verify the result
     browser.open(
             "http://nohost/plone/client/nl/ict/"
             "software-development/actionplan/1/1")
     self.assertEqual(browser.getControl(name="priority").value, ["high"])
Beispiel #4
0
 def test_get(self):
     import datetime
     import json
     from z3c.saconfig import Session
     from euphorie.client.model import Company
     from euphorie.client.model import SurveySession
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addAccount
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.api.authentication import generate_token
     from Products.Five.testbrowser import Browser
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     account = addAccount(password='******')
     survey_session = SurveySession(
             title=u'Dummy session',
             created=datetime.datetime(2012, 4, 22, 23, 5, 12),
             modified=datetime.datetime(2012, 4, 23, 11, 50, 30),
             zodb_path='nl/ict/software-development',
             account=account,
             company=Company(country='nl',
                             employees='1-9',
                             referer='other'))
     Session.add(survey_session)
     browser = Browser()
     browser.addHeader('X-Euphorie-Token', generate_token(account))
     browser.open(
             'http://nohost/plone/client/api/users/1/sessions/1/company')
     self.assertEqual(browser.headers['Content-Type'], 'application/json')
     response = json.loads(browser.contents)
     self.assertEqual(response['type'], 'company')
Beispiel #5
0
 def testInvalidDateDoesNotBreakRendering(self):
     import datetime
     from euphorie.content.tests.utils import BASIC_SURVEY
     from z3c.saconfig import Session
     from euphorie.client import model
     # Test for http://code.simplon.biz/tracker/tno-euphorie/ticket/150
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     browser = Browser()
     survey_url = self.portal.client.nl["ict"]["software-development"]\
             .absolute_url()
     browser.open(survey_url)
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="title:utf8:ustring").value = \
             u"Sessiøn".encode("utf-8")
     browser.getControl(name="next").click()
     # Start the survey
     browser.getForm().submit()
     browser.getLink("Start Risk Identification").click()
     # Update the risk
     risk = Session.query(model.Risk).first()
     risk.identification = "no"
     risk.action_plans.append(model.ActionPlan(
         action_plan=u"Do something awesome",
         planning_start=datetime.date(1, 2, 3)))
     # Render the report
     browser.handleErrors = False
     browser.open("http://nohost/plone/client/nl/ict/"
                     "software-development/report/view")
Beispiel #6
0
    def test_get_no_company_data_present(self):
        import datetime
        import json
        from z3c.saconfig import Session
        from euphorie.client.model import SurveySession
        from euphorie.content.tests.utils import BASIC_SURVEY
        from euphorie.client.tests.utils import addAccount
        from euphorie.client.tests.utils import addSurvey
        from euphorie.client.api.authentication import generate_token
        from Products.Five.testbrowser import Browser

        self.loginAsPortalOwner()
        addSurvey(self.portal, BASIC_SURVEY)
        account = addAccount(password="******")
        survey_session = SurveySession(
            title=u"Dummy session",
            created=datetime.datetime(2012, 4, 22, 23, 5, 12),
            modified=datetime.datetime(2012, 4, 23, 11, 50, 30),
            zodb_path="nl/ict/software-development",
            account=account,
        )
        Session.add(survey_session)
        browser = Browser()
        browser.addHeader("X-Euphorie-Token", generate_token(account))
        browser.open("http://nohost/plone/client/api/users/1/sessions/1/company")
        self.assertEqual(browser.headers["Content-Type"], "application/json")
        response = json.loads(browser.contents)
        self.assertEqual(response["type"], "company")
 def test_sessions_ordering(self):
     import datetime
     from euphorie.content.tests.utils import BASIC_SURVEY
     from z3c.saconfig import Session
     from AccessControl.SecurityManagement import newSecurityManager
     from ..model import Account
     from ..model import SurveySession
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     session = Session()
     account = Account(loginname='johny',
             sessions=[
                 SurveySession(zodb_path='nl/ict/software-development',
                     title=u'One',
                     modified=datetime.datetime(2012, 12, 10)),
                 SurveySession(zodb_path='nl/ict/software-development',
                     title=u'Three',
                     modified=datetime.datetime(2012, 12, 12)),
                 SurveySession(zodb_path='nl/ict/software-development',
                     title=u'Two',
                     modified=datetime.datetime(2012, 12, 11))])
     session.add(account)
     newSecurityManager(None, account)
     view = self.View(self.portal.client['nl'], None)
     self.assertEqual(
             [s['title'] for s in view.sessions()],
             [u'Three', u'Two', 'One'])
 def test_surveys_filtered_by_language(self):
     from euphorie.client.tests.utils import registerUserInClient
     survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                   <title>Sector</title>
                   <survey>
                     <title>Survey</title>
                     <language>en</language>
                   </survey>
                 </sector>"""
     survey_nl = \
             """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                 <title>Branche</title>
                 <survey>
                   <title>Vragenlijst</title>
                   <language>nl</language>
                 </survey>
               </sector>"""
     self.loginAsPortalOwner()
     addSurvey(self.portal, survey)
     addSurvey(self.portal, survey_nl)
     browser = Browser()
     browser.open(self.portal.client.absolute_url())
     browser.getLink("Nederlands").click()
     registerUserInClient(browser, link="Registreer")
     self.assertEqual(
             browser.url,
             "http://nohost/plone/client/nl/?language=nl-NL")
     self.assertEqual(browser.getControl(name="survey").options,
             ["branche/vragenlijst"])
     browser.open(
             "%s?language=en" % self.portal.client["nl"].absolute_url())
     self.assertEqual(browser.getControl(name="survey").options,
             ["sector/survey"])
Beispiel #9
0
 def test_browser_get(self):
     import datetime
     from z3c.saconfig import Session
     from euphorie.client.model import SurveySession
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addAccount
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.api.authentication import generate_token
     from tno.euphorie.model import DutchCompany
     from Products.Five.testbrowser import Browser
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     account = addAccount(password='******')
     survey_session = SurveySession(
             title=u'Dummy session',
             created=datetime.datetime(2012, 4, 22, 23, 5, 12),
             modified=datetime.datetime(2012, 4, 23, 11, 50, 30),
             zodb_path='nl/ict/software-development',
             account=account)
     survey_session.dutch_company = DutchCompany(
             title=u'Acme B.V.',
             employees='40h',
             email='*****@*****.**',
             submit_date=datetime.date(2012, 6, 6))
     Session.add(survey_session)
     browser = Browser()
     browser.addHeader('X-Euphorie-Token', generate_token(account))
     browser.handleErrors = False
     browser.open(
             'http://nohost/plone/client/api/users/1/sessions/1/'
             'report-actionplan')
     self.assertEqual(browser.headers['Content-Type'], 'application/rtf')
     self.assertTrue('Bedrijfsnaam' in browser.contents)
Beispiel #10
0
 def test_browser(self):
     import datetime
     from z3c.saconfig import Session
     from euphorie.client.model import SurveySession
     from euphorie.client.api.authentication import generate_token
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addAccount
     from euphorie.client.tests.utils import addSurvey
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     account = addAccount(password='******')
     survey_session = SurveySession(
             title=u'Dummy session',
             created=datetime.datetime(2012, 4, 22, 23, 5, 12),
             modified=datetime.datetime(2012, 4, 23, 11, 50, 30),
             zodb_path='nl/ict/software-development',
             account=account)
     Session.add(survey_session)
     browser = Browser()
     browser.addHeader('X-Euphorie-Token', generate_token(account))
     browser.handleErrors = False
     browser.open('http://nohost/plone/client/api/users/1/'
                     'sessions/1/report-timeline')
     self.assertEqual(
             browser.headers['Content-Type'],
             'application/vnd.openxmlformats-'
                                     'officedocument.spreadsheetml.sheet')
Beispiel #11
0
 def test_with_introduction(self):
     import datetime
     import json
     from z3c.saconfig import Session
     from euphorie.client.model import SurveySession
     from euphorie.client.api.authentication import generate_token
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addAccount
     from euphorie.client.tests.utils import addSurvey
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     survey = self.portal.client['nl']['ict']['software-development']
     survey.introduction = u'<p>Fancy intro.</p>'
     account = addAccount(password='******')
     survey_session = SurveySession(
             title=u'Dummy session',
             created=datetime.datetime(2012, 4, 22, 23, 5, 12),
             modified=datetime.datetime(2012, 4, 23, 11, 50, 30),
             zodb_path='nl/ict/software-development',
             account=account)
     Session.add(survey_session)
     browser = Browser()
     browser.addHeader('X-Euphorie-Token', generate_token(account))
     browser.open('http://nohost/plone/client/api/users/1/sessions/1')
     self.assertEqual(browser.headers['Content-Type'], 'application/json')
     response = json.loads(browser.contents)
     self.assertTrue('introduction' in response)
     self.assertEqual(response['introduction'], u'<p>Fancy intro.</p>')
Beispiel #12
0
 def test_get(self):
     import json
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addSurvey
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     browser = Browser()
     browser.open('http://nohost/plone/client/api/surveys/nl/ict')
     response = json.loads(browser.contents)
     self.assertEqual(response['id'], 'ict')
 def addDummySurvey(self):
     from euphorie.client.tests.utils import addSurvey
     survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                   <title>Sector title</title>
                   <survey>
                     <title>Survey title</title>
                   </survey>
                 </sector>"""
     self.loginAsPortalOwner()
     addSurvey(self.portal, survey)
Beispiel #14
0
 def setUp(self):
     from Products.Five.testbrowser import Browser
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.tests.utils import registerUserInClient
     from euphorie.content.tests.utils import BASIC_SURVEY
     super(AccountDeleteTests, self).setUp()
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     survey = self.portal.client["nl"]["ict"]["software-development"]
     self.browser = Browser()
     self.browser.open(survey.absolute_url())
     registerUserInClient(self.browser)
Beispiel #15
0
def _setup_session(portal):
    from euphorie.content.tests.utils import BASIC_SURVEY
    from euphorie.client.tests.utils import addAccount
    from euphorie.client.tests.utils import addSurvey
    from euphorie.client.session import create_survey_session
    from euphorie.client.profile import set_session_profile
    addSurvey(portal, BASIC_SURVEY)
    survey = portal.client['nl']['ict']['software-development']
    account = addAccount(password='******')
    survey_session = create_survey_session(u'Dummy session',
            survey, account)
    survey_session = set_session_profile(survey, survey_session, {})
    return (account, survey, survey_session)
 def test_login_not_case_sensitive(self):
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.tests.utils import addAccount
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     addAccount(password='******')
     browser = Browser()
     browser.open(self.portal.client.nl.absolute_url())
     browser.getControl(name='__ac_name').value = '*****@*****.**'
     browser.getControl(name='__ac_password:utf8:ustring').value = 'secret'
     browser.getControl(name="next").click()
     self.assertTrue('@@login' not in browser.url)
Beispiel #17
0
 def test_extra_ga_pageview_post_login(self):
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.tests.utils import addAccount
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     addAccount(password='******')
     browser = Browser()
     browser.open(self.portal.client.nl.absolute_url())
     browser.getLink('Login').click()
     browser.getControl(name='__ac_name').value = '*****@*****.**'
     browser.getControl(name='__ac_password:utf8:ustring').value = 'secret'
     browser.getControl(name="next").click()
     self.assertTrue(re.search('trackPageview.*login_form/success', browser.contents) is not None)
 def test_use_session_cookie_by_default(self):
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.tests.utils import addAccount
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     addAccount(password='******')
     browser = Browser()
     browser.open(self.portal.client.nl.absolute_url())
     browser.getControl(name='__ac_name').value = '*****@*****.**'
     browser.getControl(name='__ac_password:utf8:ustring').value = 'secret'
     browser.getControl(name="next").click()
     auth_cookie = browser.cookies.getinfo('__ac')
     self.assertEqual(auth_cookie['expires'], None)
 def test_must_select_valid_survey(self):
     import urllib
     from euphorie.client.tests.utils import registerUserInClient
     from euphorie.content.tests.utils import BASIC_SURVEY
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     browser = Browser()
     browser.open(self.portal.client['nl'].absolute_url())
     registerUserInClient(browser)
     data = urllib.urlencode({'action': 'new',
                              'survey': '',
                              'title:utf8:ustring': 'Foo'})
     browser.handleErrors = False
     browser.open(browser.url, data)
     self.assertEqual(browser.url, 'http://nohost/plone/client/nl')
Beispiel #20
0
 def setUp(self):
     from Products.Five.testbrowser import Browser
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.tests.utils import registerUserInClient
     from euphorie.client.tests.utils import MockMailFixture
     from euphorie.content.tests.utils import BASIC_SURVEY
     super(NewEmailTests, self).setUp()
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     survey = self.portal.client["nl"]["ict"]["software-development"]
     self.browser = Browser()
     self.browser.open(survey.absolute_url())
     registerUserInClient(self.browser)
     self._mail_fixture = MockMailFixture()
     self.email_send = self._mail_fixture.storage
 def testUnpublishedSurvey(self):
     from euphorie.content.tests.utils import EMPTY_SURVEY
     from euphorie.content.tests.utils import createSector
     from euphorie.content.tests.utils import addSurvey
     sector = createSector(self.portal)
     survey = addSurvey(sector, EMPTY_SURVEY)
     self.handleSurveyUnpublish(survey, None)
Beispiel #22
0
 def test_guest_login_no_valid_survey(self):
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     self.logout()
     alsoProvides(self.portal.client.REQUEST, IClientSkinLayer)
     browser = self.get_browser()
     api.portal.set_registry_record("euphorie.allow_guest_accounts", True)
     commit()
     browser.open(self.portal.client.nl.absolute_url())
     self.assertIn("Start a test session", browser.contents)
     # No valid survey path is passed in came_from
     browser.open("%s/@@surveys?came_from=%s" % (
         self.portal.client.nl.absolute_url(),
         self.portal.client.nl.absolute_url(),
     ))
     # Therefore we land on the "start new session" page
     self.assertIn("Test session", browser.contents)
Beispiel #23
0
 def test_guest_login_with_valid_survey(self):
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     self.logout()
     alsoProvides(self.portal.client.REQUEST, IClientSkinLayer)
     browser = self.get_browser()
     api.portal.set_registry_record("euphorie.allow_guest_accounts", True)
     commit()
     browser.open(self.portal.client.nl.absolute_url())
     self.assertIn("Start a test session", browser.contents)
     url = "{}/ict/software-development".format(
         self.portal.client.nl.absolute_url())
     # We pass in a valid survey path in came_from
     browser.open("{url}/@@tryout?came_from={url}".format(url=url))
     # Therefore we land on the start page of the survey
     self.assertIn("Test session", browser.contents)
     self.assertIn("<h1>Software development</h1>", browser.contents)
    def testMultiProfiles(self):
        # Tests http://code.simplon.biz/tracker/euphorie/ticket/96
        survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                      <title>Sector title</title>
                      <survey>
                        <title>Survey title</title>
                        <profile-question>
                          <title>Multiple profile question</title>
                          <question>Profile titles</question>
                          <description>&lt;p&gt;Profile description.&lt;/p&gt;</description>
                          <risk type="policy">
                            <title>Profile risk</title>
                            <description>&lt;p&gt;Risk description.&lt;/p&gt;</description>
                            <evaluation-method>direct</evaluation-method>
                          </risk>
                        </profile-question>
                        <module optional="false">
                          <title>Module title</title>
                          <description>&lt;p&gt;Module description.&lt;/p&gt;</description>
                          <risk type="policy">
                            <title>Module risk</title>
                            <description>&lt;p&gt;Module description.&lt;/p&gt;</description>
                            <evaluation-method>direct</evaluation-method>
                          </risk>
                        </module>
                      </survey>
                    </sector>"""

        self.loginAsPortalOwner()
        addSurvey(self.portal, survey)
        browser = Browser()
        browser.open(self.portal.client.nl["sector-title"]
                     ["survey-title"].absolute_url())
        registerUserInClient(browser)
        # Create a new survey session
        browser.getControl(name="title:utf8:ustring").value = "Test session"
        browser.getControl(name="next").click()
        # Start the survey
        browser.getForm().submit()
        # Enter the profile information
        browser.getControl(name="1:utf8:utext:list",
                           index=0).value = "Profile 1"
        browser.getControl(name="1:utf8:utext:list",
                           index=1).value = "Profile 2"
        browser.getForm().submit()
    def testCompanySettingsRoundTrip(self):
        from euphorie.content.tests.utils import BASIC_SURVEY

        self.loginAsPortalOwner()
        addSurvey(self.portal, BASIC_SURVEY)
        browser = self.get_browser()
        survey_url = self.portal.client.nl["ict"][
            "software-development"].absolute_url()
        browser.open(survey_url)
        registerUserInClient(browser)
        # Create a new survey session
        browser.getControl(name="survey").value = ["ict/software-development"]
        browser.getForm(action="new-session").submit()
        browser.getControl(name="form.widgets.title").value = "Sessiøn".encode(
            "utf-8")  # noqa
        # Start the survey
        browser.getControl(name="form.button.submit").click()
        session_url = browser.url.replace("/@@identification", "")
        # Enter some company data
        browser.open("%s/@@report_company" % session_url)
        browser.getControl(name="form.widgets.country").value = ["be"]
        browser.getControl(name="form.widgets.employees").value = ["50-249"]
        browser.getControl(name="form.widgets.conductor").value = ["staff"]
        browser.getControl(name="form.widgets.referer").value = ["trade-union"]
        browser.getControl(name="form.widgets.workers_participated").value = [
            "True"
        ]
        browser.getControl(name="form.buttons.next").click()
        # Make sure all fields validated
        self.assertEqual(browser.url, "%s/@@report_view" % session_url)
        # Verify entered data
        browser.open("%s/@@report_company" % session_url)
        self.assertEqual(
            browser.getControl(name="form.widgets.country").value, ["be"])
        self.assertEqual(
            browser.getControl(name="form.widgets.employees").value,
            ["50-249"])
        self.assertEqual(
            browser.getControl(name="form.widgets.conductor").value, ["staff"])
        self.assertEqual(
            browser.getControl(name="form.widgets.referer").value,
            ["trade-union"])
        self.assertEqual(
            browser.getControl(name="form.widgets.workers_participated").value,
            ["True"])
Beispiel #26
0
 def setUp(self):
     super(TestTrainingQuestions, self).setUp()
     with api.env.adopt_user("admin"):
         addSurvey(self.portal, BASIC_SURVEY)
     self.account = addAccount(password="******")
     self.survey = self.portal.client.nl.ict["software-development"]
     alsoProvides(self.survey.REQUEST, IClientSkinLayer)
     api.portal.set_registry_record("euphorie.use_training_module", True)
     survey_session = model.SurveySession(
         title="Dummy session",
         zodb_path="nl/ict/software-development",
         account=self.account,
         company=model.Company(country="nl",
                               employees="1-9",
                               referer="other"),
     )
     model.Session.add(survey_session)
     seed(a="test_training_questions")
Beispiel #27
0
 def XtestPreventEarlyDate(self):
     """
     Deactivated until we decide what to do about this kind of validation
     error check
     """
     from euphorie.content.tests.utils import BASIC_SURVEY
     # Test for http://code.simplon.biz/tracker/tno-euphorie/ticket/150
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     browser = Browser()
     survey_url = self.portal.client.nl["ict"]["software-development"]\
             .absolute_url()
     browser.open(survey_url)
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="title:utf8:ustring").value = \
             u"Sessiøn".encode("utf-8")
     browser.getControl(name="next").click()
     # Start the survey
     browser.getForm().submit()
     browser.getLink("Start Risk Identification").click()
     # Identify the risk
     browser.getControl("next").click()
     browser.getControl(name="answer").value = ["no"]
     browser.getControl("next").click()
     # Move on to the risk's action plan form
     browser.getLink("Create action plan").click()
     browser.getLink("Next").click()
     # Try an early year
     browser.getControl(name="measure.action_plan:utf8:ustring:records", index=0)\
             .value = "Do something awesome"
     browser.getControl(name="measure.planning_start_day:records", index=0)\
             .value = "1"
     browser.getControl(name="measure.planning_start_month:records", index=0)\
             .value = ["2"]
     browser.getControl(name="measure.planning_start_year:records", index=0)\
             .value = "3"
     browser.getControl("next").click()
     self.assertEqual(browser.url,
             "http://nohost/plone/client/nl/ict/"
             "software-development/actionplan/1/1")
     self.assertTrue(
             "Please enter a year between 2000 and 2100"
             in browser.contents)
Beispiel #28
0
 def testCompanySettingsRoundTrip(self):
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.tests.utils import registerUserInClient
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     browser = Browser()
     survey_url = \
         self.portal.client.nl["ict"]["software-development"].absolute_url()
     browser.open(survey_url)
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="title:utf8:ustring").value = \
         u"Sessiøn".encode("utf-8")
     browser.getControl(name="next").click()
     # Start the survey
     browser.getForm().submit()
     browser.getLink("Start Risk Identification").click()
     # Enter some company data
     browser.open("%s/report/company" % survey_url)
     browser.getControl(name="form.widgets.country").value = ["be"]
     browser.getControl(name="form.widgets.employees").value = ["50-249"]
     browser.getControl(name="form.widgets.conductor").value = ["staff"]
     browser.getControl(name="form.widgets.referer").value = ["trade-union"]
     browser.getControl(name="form.widgets.workers_participated").value = \
         ['True']
     browser.getControl(name="form.buttons.next").click()
     # Make sure all fields validated
     self.assertEqual(browser.url, "%s/report/view" % survey_url)
     # Verify entered data
     browser.open("%s/report/company" % survey_url)
     self.assertEqual(
         browser.getControl(name="form.widgets.country").value, ["be"])
     self.assertEqual(
         browser.getControl(name="form.widgets.employees").value,
         ["50-249"])
     self.assertEqual(
         browser.getControl(name="form.widgets.conductor").value, ["staff"])
     self.assertEqual(
         browser.getControl(name="form.widgets.referer").value,
         ["trade-union"])
     self.assertEqual(
         browser.getControl(name="form.widgets.workers_participated").value,
         ["True"])
Beispiel #29
0
 def testCompanySettingsRoundTrip(self):
     from euphorie.content.tests.utils import BASIC_SURVEY
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     browser = Browser()
     survey_url = self.portal.client.nl["ict"]["software-development"]\
             .absolute_url()
     browser.open(survey_url)
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="title:utf8:ustring").value = \
             u"Sessiøn".encode("utf-8")
     browser.getControl(name="next").click()
     # Start the survey
     browser.getForm().submit()
     browser.getLink("Start Risk Identification").click()
     # Enter some company data
     browser.open("%s/report/company" % survey_url)
     browser.getControl(name="form.widgets.country").value = ["be"]
     browser.getControl(name="form.widgets.employees").value = ["50-249"]
     browser.getControl(name="form.widgets.conductor").value = ["staff"]
     browser.getControl(name="form.widgets.referer").value = ["trade-union"]
     browser.getControl(name="form.widgets.workers_participated")\
             .value = ['True']
     browser.getControl(name="form.buttons.next").click()
     # Make sure all fields validated
     self.assertEqual(browser.url, "%s/report/view" % survey_url)
     # Verify entered data
     browser.open("%s/report/company" % survey_url)
     self.assertEqual(
             browser.getControl(name="form.widgets.country").value, ["be"])
     self.assertEqual(
             browser.getControl(name="form.widgets.employees").value,
             ["50-249"])
     self.assertEqual(
             browser.getControl(name="form.widgets.conductor").value,
             ["staff"])
     self.assertEqual(
             browser.getControl(name="form.widgets.referer").value,
             ["trade-union"])
     self.assertEqual(
             browser.getControl(
                 name="form.widgets.workers_participated").value,
             ["True"])
 def XtestPreventEarlyDate(self):
     """
     Deactivated until we decide what to do about this kind of validation
     error check
     """
     # Test for http://code.simplon.biz/tracker/tno-euphorie/ticket/150
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     browser = self.get_browser()
     survey_url = self.portal.client.nl["ict"][
         "software-development"].absolute_url()  # noqa: E501
     browser.open(survey_url)
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="survey").value = ["ict/software-development"]
     browser.getForm(action="new-session").submit()
     browser.getControl(name="form.widgets.title").value = "Sessiøn".encode(
         "utf-8")  # noqa
     # Start the survey
     browser.getControl(name="form.button.submit").click()
     # Identify the risk
     browser.getControl("next").click()
     browser.getControl(name="answer").value = ["no"]
     browser.getControl("next").click()
     # Move on to the risk's action plan form
     browser.getLink("Create action plan").click()
     browser.getLink("Next").click()
     # Try an early year
     browser.getControl(name="measure.action_plan:utf8:ustring:records",
                        index=0).value = "Do something awesome"
     browser.getControl(name="measure.planning_start_day:records",
                        index=0).value = "1"
     browser.getControl(name="measure.planning_start_month:records",
                        index=0).value = ["2"]
     browser.getControl(name="measure.planning_start_year:records",
                        index=0).value = "3"
     browser.getControl("next").click()
     self.assertEqual(
         browser.url,
         "http://nohost/plone/client/nl/ict/"
         "software-development/actionplan/1/1",
     )
     self.assertTrue(
         "Please enter a year between 2000 and 2100" in browser.contents)
 def test_top5_skipped_in_evaluation(self):
     # Test for http://code.simplon.biz/tracker/euphorie/ticket/105
     survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                   <title>Sector title</title>
                   <survey>
                     <title>Survey title</title>
                     <evaluation-optional>false</evaluation-optional>
                     <module optional="false">
                       <title>Top5 parent</title>
                       <description>&lt;p&gt;Een module met een top-5 risico.&lt;/p&gt;</description>
                       <risk type="top5">
                         <title>Top-5 probleem!</title>
                         <problem-description>Er is een top-5 probleem.</problem-description>
                         <description>&lt;p&gt;Zomaar wat tekst.&lt;/p&gt;</description>
                         <show-not-applicable>false</show-not-applicable>
                       </risk>
                     </module>
                   </survey>
                 </sector>"""
     self.loginAsPortalOwner()
     addSurvey(self.portal, survey)
     browser = Browser()
     browser.open(self.portal.client.nl["sector-title"]["survey-title"]
             .absolute_url())
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="title:utf8:ustring").value = "Test session"
     browser.getControl(name="next", index=1).click()
     # Start the survey
     browser.getForm().submit()
     browser.getLink("Start Risk Identification").click()
     # Identify the top-5 risk
     browser.open("http://nohost/plone/client/nl/sector-title/"
                     "survey-title/identification/1/1")
     browser.getControl(name="answer").value = ["no"]
     browser.getControl(name="next", index=1).click()
     # Check what the evaluation found
     self.assertEqual(
             browser.url,
             "http://nohost/plone/client/nl/sector-title/"
             "survey-title/evaluation")
     self.assertTrue(
             "There are no risks that need to be evaluated"
             in browser.contents)
 def test_remember_user_sets_cookie_expiration(self):
     import datetime
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.tests.utils import addAccount
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     addAccount(password='******')
     browser = Browser()
     browser.open(self.portal.client.nl.absolute_url())
     browser.getControl(name='__ac_name').value = '*****@*****.**'
     browser.getControl(name='__ac_password:utf8:ustring').value = 'secret'
     browser.getControl(name='remember').value = ['True']
     browser.getControl(name="next").click()
     auth_cookie = browser.cookies.getinfo('__ac')
     self.assertNotEqual(auth_cookie['expires'], None)
     delta = auth_cookie['expires'] - datetime.datetime.now(
                                         auth_cookie['expires'].tzinfo)
     self.assertTrue(delta.days > 100)
Beispiel #33
0
 def setUp(self):
     super(TestDashboard, self).setUp()
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     self.account = addAccount(password="******")
     # We setup two surveys, an archived one and one which is not archived
     survey_session = model.SurveySession(
         title="Dummy session 1",
         zodb_path="nl/ict/software-development",
         account=self.account,
     )
     model.Session.add(survey_session)
     survey_session = model.SurveySession(
         title="Dummy session 2",
         zodb_path="nl/ict/software-development",
         account=self.account,
     )
     survey_session.archived = localized_now() - timedelta(days=1)
     model.Session.add(survey_session)
    def testMultiProfiles(self):
        # Tests http://code.simplon.biz/tracker/euphorie/ticket/96
        survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                      <title>Sector title</title>
                      <survey>
                        <title>Survey title</title>
                        <profile-question>
                          <title>Multiple profile question</title>
                          <question>Profile titles</question>
                          <description>&lt;p&gt;Profile description.&lt;/p&gt;</description>
                          <risk type="policy">
                            <title>Profile risk</title>
                            <description>&lt;p&gt;Risk description.&lt;/p&gt;</description>
                            <evaluation-method>direct</evaluation-method>
                          </risk>
                        </profile-question>
                        <module optional="false">
                          <title>Module title</title>
                          <description>&lt;p&gt;Module description.&lt;/p&gt;</description>
                          <risk type="policy">
                            <title>Module risk</title>
                            <description>&lt;p&gt;Module description.&lt;/p&gt;</description>
                            <evaluation-method>direct</evaluation-method>
                          </risk>
                        </module>
                      </survey>
                    </sector>"""

        self.loginAsPortalOwner()
        addSurvey(self.portal, survey)
        browser = Browser()
        browser.open(self.portal.client.nl["sector-title"]["survey-title"]
                .absolute_url())
        registerUserInClient(browser)
        # Create a new survey session
        browser.getControl(name="title:utf8:ustring").value = "Test session"
        browser.getControl(name="next", index=1).click()
        # Start the survey
        browser.getForm().submit()
        # Enter the profile information
        browser.getControl(name="1:utf8:utext:list", index=0).value = "Profile 1"
        browser.getControl(name="1:utf8:utext:list", index=1).value = "Profile 2"
        browser.getForm().submit()
 def test_policy_gets_high_priority(self):
     # Test for http://code.simplon.biz/tracker/tno-euphorie/ticket/93
     survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                   <title>Sector title</title>
                   <survey>
                     <title>Survey title</title>
                     <language>nl</language>
                     <evaluation-optional>false</evaluation-optional>
                     <module optional="false">
                       <title>Policy parent</title>
                       <description>&lt;p&gt;Een module met een beleidsrisico.&lt;/p&gt;</description>
                       <risk type="policy">
                         <title>Policy problem!</title>
                         <problem-description>There is a policy problem.</problem-description>
                         <description>&lt;p&gt;Random text.&lt;/p&gt;</description>
                         <show-not-applicable>false</show-not-applicable>
                       </risk>
                     </module>
                   </survey>
                 </sector>"""  # noqa: E501
     self.loginAsPortalOwner()
     addSurvey(self.portal, survey)
     commit()
     self.request.response.setHeader("X-Theme-Disabled", "1")
     browser = self.get_browser()
     url = self.portal.client.nl["sector-title"]["survey-title"].absolute_url()
     browser.open(url)
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="survey").value = ["sector-title/survey-title"]
     browser.getForm(action="new-session").submit()
     browser.getControl(name="form.widgets.title").value = "Test session"
     # Start the survey
     browser.getControl(name="form.button.submit").click()
     session_url = browser.url.replace("/@@identification", "")
     # Identify the risk
     browser.open("%s/1/1/@@identification" % session_url)
     browser.getControl(name="answer").value = ["no"]
     browser.getControl(name="next", index=1).click()
     # Check priority in action plan
     browser.open("%s/1/1/@@actionplan" % session_url)
     self.assertEqual(browser.getControl(name="priority").value, ["high"])
 def test_top5_skipped_in_evaluation(self):
     # Test for http://code.simplon.biz/tracker/euphorie/ticket/105
     survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                   <title>Sector title</title>
                   <survey>
                     <title>Survey title</title>
                     <language>nl</language>
                     <evaluation-optional>false</evaluation-optional>
                     <module optional="false">
                       <title>Top5 parent</title>
                       <description>&lt;p&gt;Een module met een top-5 risico.&lt;/p&gt;</description>
                       <risk type="top5">
                         <title>Top-5 probleem!</title>
                         <problem-description>Er is een top-5 probleem.</problem-description>
                         <description>&lt;p&gt;Zomaar wat tekst.&lt;/p&gt;</description>
                         <show-not-applicable>false</show-not-applicable>
                       </risk>
                     </module>
                   </survey>
                 </sector>"""  # noqa: E501
     self.loginAsPortalOwner()
     addSurvey(self.portal, survey)
     browser = self.get_browser()
     browser.open(
         self.portal.client.nl["sector-title"]["survey-title"].absolute_url()
     )
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="survey").value = ["sector-title/survey-title"]
     browser.getForm(action="new-session").submit()
     browser.getControl(name="form.widgets.title").value = "Test session"
     # Start the survey
     browser.getControl(name="form.button.submit").click()
     session_url = browser.url.replace("/@@identification", "")
     # Identify the top-5 risk
     browser.open("%s/1/1/@@identification" % session_url)
     browser.getControl(name="answer").value = ["no"]
     # No evaluation is necessary
     self.assertIn(
         "De tool heeft automatisch een risico-evaluatie uitgevoerd",
         browser.contents,
     )
Beispiel #37
0
 def test_remember_user_sets_cookie_expiration(self):
     import datetime
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.tests.utils import addAccount
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     addAccount(password='******')
     browser = Browser()
     browser.open(self.portal.client.nl.absolute_url())
     browser.getLink('Login').click()
     browser.getControl(name='__ac_name').value = '*****@*****.**'
     browser.getControl(name='__ac_password:utf8:ustring').value = 'secret'
     browser.getControl(name='remember').value = ['True']
     browser.getControl(name="next").click()
     auth_cookie = browser.cookies.getinfo('__ac')
     self.assertNotEqual(auth_cookie['expires'], None)
     delta = auth_cookie['expires'] - datetime.datetime.now(
         auth_cookie['expires'].tzinfo)
     self.assertTrue(delta.days > 100)
Beispiel #38
0
    def testCountryDefaultsToCurrentCountry(self):
        from euphorie.client.tests.utils import addSurvey
        from euphorie.client.tests.utils import registerUserInClient
        from euphorie.content.tests.utils import BASIC_SURVEY

        self.loginAsPortalOwner()
        addSurvey(self.portal, BASIC_SURVEY)
        browser = Browser()
        survey_url = self.portal.client.nl["ict"]["software-development"].absolute_url()
        browser.open(survey_url)
        registerUserInClient(browser)
        # Create a new survey session
        browser.getControl(name="title:utf8:ustring").value = "Sessiøn".encode("utf-8")
        browser.getControl(name="next").click()
        # Start the survey
        browser.getForm().submit()
        browser.getLink("Start Risk Identification").click()
        # Check the company data
        browser.open("%s/report/company" % survey_url)
        self.assertEqual(browser.getControl(name="form.widgets.country").value, ["nl"])
 def Xtest_do_not_abort_on_far_future(self):
     """
     Deactivated, since such a far-future date can not be entered any more
     in modern browsers
     """
     # Test for http://code.simplon.biz/tracker/tno-euphorie/ticket/150
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     browser = self.get_browser()
     survey_url = self.portal.client.nl["ict"][
         "software-development"].absolute_url()
     browser.open(survey_url)
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="survey").value = ["ict/software-development"]
     browser.getForm(action="new-session").submit()
     browser.getControl(name="form.widgets.title").value = "Sessiøn".encode(
         "utf-8")  # noqa
     # Start the survey
     browser.getControl(name="form.button.submit").click()
     # Identify the risk
     browser.getControl("next").click()
     browser.getControl(name="answer").value = ["no"]
     browser.getControl("next").click()
     # Move on to the risk's action plan form
     browser.getLink("Create action plan").click()
     browser.getLink("Next").click()
     # Try an early year
     browser.getControl(name="measure.action_plan:utf8:ustring:records",
                        index=0).value = "Do something awesome"
     browser.getControl(name="measure.planning_start:records",
                        index=0).value = "12345/02/01"
     browser.handleErrors = False
     browser.getControl("next").click()
     self.assertEqual(
         browser.url,
         "http://nohost/plone/client/nl/ict/"
         "software-development/actionplan/1/1",
     )
     self.assertTrue(
         "Please enter a year between 2000 and 2100" in browser.contents)
Beispiel #40
0
 def Xtest_do_not_abort_on_far_future(self):
     """
     Deactivated, since such a far-future date can not be entered any more
     in modern browsers
     """
     from euphorie.content.tests.utils import BASIC_SURVEY
     # Test for http://code.simplon.biz/tracker/tno-euphorie/ticket/150
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     browser = Browser()
     survey_url = (self.portal.client.nl["ict"]
             ["software-development"].absolute_url())
     browser.open(survey_url)
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="title:utf8:ustring").value = \
             u"Sessiøn".encode("utf-8")
     browser.getControl(name="next").click()
     # Start the survey
     browser.getForm().submit()
     browser.getLink("Start Risk Identification").click()
     # Identify the risk
     browser.getControl("next").click()
     browser.getControl(name="answer").value = ["no"]
     browser.getControl("next").click()
     # Move on to the risk's action plan form
     browser.getLink("Create action plan").click()
     browser.getLink("Next").click()
     # Try an early year
     browser.getControl(name="measure.action_plan:utf8:ustring:records", index=0)\
             .value = "Do something awesome"
     browser.getControl(name="measure.planning_start:records", index=0)\
             .value = "12345/02/01"
     browser.handleErrors = False
     browser.getControl("next").click()
     self.assertEqual(browser.url,
             "http://nohost/plone/client/nl/ict/"
             "software-development/actionplan/1/1")
     self.assertTrue(
             "Please enter a year between 2000 and 2100"
             in browser.contents)
Beispiel #41
0
 def testCountryDefaultsToCurrentCountry(self):
     from euphorie.content.tests.utils import BASIC_SURVEY
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     browser = Browser()
     survey_url = self.portal.client.nl["ict"]["software-development"]\
             .absolute_url()
     browser.open(survey_url)
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="title:utf8:ustring").value = \
             u"Sessiøn".encode("utf-8")
     browser.getControl(name="next").click()
     # Start the survey
     browser.getForm().submit()
     browser.getLink("Start Risk Identification").click()
     # Check the company data
     browser.open("%s/report/company" % survey_url)
     self.assertEqual(
             browser.getControl(name="form.widgets.country").value,
             ["nl"])
Beispiel #42
0
 def test_do_POST_survey_with_profile(self):
     from z3c.saconfig import Session
     from AccessControl.SecurityManagement import newSecurityManager
     from zope.publisher.browser import TestRequest
     from euphorie.content.tests.utils import PROFILE_SURVEY
     from euphorie.client.model import SurveySession
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.tests.utils import addAccount
     account = addAccount()
     self.loginAsPortalOwner()
     addSurvey(self.portal, PROFILE_SURVEY)
     request = TestRequest()
     request.client = self.portal.client
     survey = self.portal.client['nl']['ict']['software-development']
     view = self.View(survey, request)
     view.input = {'survey': 'nl/ict/software-development'}
     newSecurityManager(None, account)
     response = view.do_POST()
     self.assertTrue(response['next-step'].endswith('profile'))
     survey_session = Session.query(SurveySession).first()
     self.assertTrue(not survey_session.hasTree())
Beispiel #43
0
 def test_get(self):
     import datetime
     import json
     from z3c.saconfig import Session
     from euphorie.client.model import SurveySession
     from euphorie.client.api.authentication import generate_token
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addAccount
     from euphorie.client.tests.utils import addSurvey
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     account = addAccount(password='******')
     survey_session = SurveySession(
         title=u'Dummy session',
         created=datetime.datetime(2012, 4, 22, 23, 5, 12),
         modified=datetime.datetime(2012, 4, 23, 11, 50, 30),
         zodb_path='nl/ict/software-development',
         account=account)
     Session.add(survey_session)
     browser = Browser()
     browser.addHeader('X-Euphorie-Token', generate_token(account))
     browser.open('http://nohost/plone/client/api/users/1/sessions/1')
     self.assertEqual(browser.headers['Content-Type'], 'application/json')
     response = json.loads(browser.contents)
     self.assertEqual(
         set(response),
         set([
             'id', 'survey', 'type', 'created', 'modified', 'title',
             'next-step'
         ]))
     self.assertEqual(response['id'], 1)
     self.assertEqual(response['survey'], 'nl/ict/software-development')
     self.assertEqual(response['type'], 'session')
     self.assertEqual(response['title'], 'Dummy session')
     self.assertEqual(response['created'], '2012-04-22T23:05:12')
     self.assertEqual(response['modified'], '2012-04-23T11:50:30')
     self.assertEqual(
         response['next-step'],
         'http://nohost/plone/client/api/users/1/sessions/1/'
         'identification')
 def test_policy_gets_high_priority(self):
     # Test for http://code.simplon.biz/tracker/tno-euphorie/ticket/93
     survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                   <title>Sector title</title>
                   <survey>
                     <title>Survey title</title>
                     <evaluation-optional>false</evaluation-optional>
                     <module optional="false">
                       <title>Policy parent</title>
                       <description>&lt;p&gt;Een module met een beleidsrisico.&lt;/p&gt;</description>
                       <risk type="policy">
                         <title>Policy problem!</title>
                         <problem-description>There is a policy problem.</problem-description>
                         <description>&lt;p&gt;Random text.&lt;/p&gt;</description>
                         <show-not-applicable>false</show-not-applicable>
                       </risk>
                     </module>
                   </survey>
                 </sector>"""
     self.loginAsPortalOwner()
     addSurvey(self.portal, survey)
     browser = Browser()
     browser.open(self.portal.client.nl["sector-title"]["survey-title"]
                     .absolute_url())
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="title:utf8:ustring").value = "Test session"
     browser.getControl(name="next").click()
     # Start the survey
     browser.getForm().submit()
     browser.getLink("Start Risk Identification").click()
     # Identify the risk
     browser.open("http://nohost/plone/client/nl/sector-title/"
                  "survey-title/identification/1/1")
     browser.getControl(name="answer").value = ["no"]
     browser.getControl(name="next", index=1).click()
     # Check priority in action plan
     browser.open("http://nohost/plone/client/nl/sector-title/"
                  "survey-title/actionplan/1/1")
     self.assertEqual(browser.getControl(name="priority").value, ["high"])
    def testCountryDefaultsToCurrentCountry(self):
        from euphorie.content.tests.utils import BASIC_SURVEY

        self.loginAsPortalOwner()
        addSurvey(self.portal, BASIC_SURVEY)
        survey_url = self.portal.client.nl["ict"][
            "software-development"].absolute_url()  # noqa: E501
        browser = self.get_browser()
        browser.open(survey_url)
        registerUserInClient(browser)
        # Create a new survey session
        browser.getControl(name="survey").value = ["ict/software-development"]
        browser.getForm(action="new-session").submit()
        browser.getControl(name="form.widgets.title").value = "Sessiøn".encode(
            "utf-8")  # noqa
        # Start the survey
        browser.getControl(name="form.button.submit").click()
        session_url = browser.url.replace("/@@identification", "")
        # Check the company data
        browser.open("%s/@@report_company" % session_url)
        self.assertEqual(
            browser.getControl(name="form.widgets.country").value, ["nl"])
Beispiel #46
0
 def test_do_POST_survey_with_profile(self):
     from z3c.saconfig import Session
     from AccessControl.SecurityManagement import newSecurityManager
     from zope.publisher.browser import TestRequest
     from euphorie.content.tests.utils import PROFILE_SURVEY
     from euphorie.client.model import SurveySession
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.tests.utils import addAccount
     account = addAccount()
     self.loginAsPortalOwner()
     addSurvey(self.portal, PROFILE_SURVEY)
     request = TestRequest()
     request.client = self.portal.client
     survey = self.portal.client['nl']['ict']['software-development']
     view = self.View(survey, request)
     view.input = {'survey': 'nl/ict/software-development'}
     newSecurityManager(None, account)
     response = view.do_POST()
     self.assertTrue(
             response['next-step'].endswith('profile'))
     survey_session = Session.query(SurveySession).first()
     self.assertTrue(not survey_session.hasTree())
 def test_top5_skipped_in_evaluation(self):
     # Test for http://code.simplon.biz/tracker/euphorie/ticket/105
     survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                   <title>Sector title</title>
                   <survey>
                     <title>Survey title</title>
                     <evaluation-optional>false</evaluation-optional>
                     <module optional="false">
                       <title>Top5 parent</title>
                       <description>&lt;p&gt;Een module met een top-5 risico.&lt;/p&gt;</description>
                       <risk type="top5">
                         <title>Top-5 probleem!</title>
                         <problem-description>Er is een top-5 probleem.</problem-description>
                         <description>&lt;p&gt;Zomaar wat tekst.&lt;/p&gt;</description>
                         <show-not-applicable>false</show-not-applicable>
                       </risk>
                     </module>
                   </survey>
                 </sector>"""
     self.loginAsPortalOwner()
     addSurvey(self.portal, survey)
     browser = Browser()
     browser.open(self.portal.client.nl["sector-title"]["survey-title"]
             .absolute_url())
     registerUserInClient(browser)
     # Create a new survey session
     browser.getControl(name="title:utf8:ustring").value = "Test session"
     browser.getControl(name="next").click()
     # Start the survey
     browser.getForm().submit()
     browser.getLink("Start Risk Identification").click()
     # Identify the top-5 risk
     browser.open("http://nohost/plone/client/nl/sector-title/"
                     "survey-title/identification/1/1")
     browser.getControl(name="answer").value = ["no"]
     # No evaluation is necessary
     self.assertTrue(
             "The risk evaluation has been automatically done by the tool"
             in browser.contents)
Beispiel #48
0
 def test_guest_login_with_valid_survey(self):
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addSurvey
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     self.logout()
     alsoProvides(self.portal.client.REQUEST, IClientSkinLayer)
     browser = Browser()
     appconfig = component.getUtility(IAppConfig)
     allow_guest_accounts = appconfig['euphorie'].get(
         'allow_guest_accounts', False)
     appconfig['euphorie']['allow_guest_accounts'] = True
     browser.open(self.portal.client.nl.absolute_url())
     self.assertTrue(
         re.search('run a test session', browser.contents) is not None)
     url = "{}/ict/software-development".format(
         self.portal.client.nl.absolute_url())
     # We pass in a valid survey path in came_from
     browser.open("{url}/@@tryout?came_from={url}".format(url=url))
     # Therefore we land on the start page of the survey
     self.assertTrue("This is a test session" in browser.contents)
     self.assertTrue("<h1>Software development</h1>" in browser.contents)
     appconfig['euphorie']['allow_guest_accounts'] = allow_guest_accounts
Beispiel #49
0
 def test_guest_login_no_valid_survey(self):
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addSurvey
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     self.logout()
     alsoProvides(self.portal.client.REQUEST, IClientSkinLayer)
     browser = Browser()
     appconfig = component.getUtility(IAppConfig)
     allow_guest_accounts = appconfig['euphorie'].get(
         'allow_guest_accounts', False)
     appconfig['euphorie']['allow_guest_accounts'] = True
     browser.open(self.portal.client.nl.absolute_url())
     self.assertTrue(
         re.search('run a test session', browser.contents) is not None)
     # No valid survey path is passed in came_from
     browser.open("%s/@@tryout?came_from=%s" %
                  (self.portal.client.nl.absolute_url(),
                   self.portal.client.nl.absolute_url()))
     # Therefore we land on the "start new session" page
     self.assertTrue("This is a test session" in browser.contents)
     self.assertTrue("start a new session" in browser.contents)
     appconfig['euphorie']['allow_guest_accounts'] = allow_guest_accounts
Beispiel #50
0
 def test_surveys_filtered_by_language(self):
     from euphorie.client.tests.utils import registerUserInClient
     survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                   <title>Sector</title>
                   <survey>
                     <title>Survey</title>
                     <language>en</language>
                   </survey>
                 </sector>"""
     survey_nl = \
             """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                 <title>Branche</title>
                 <survey>
                   <title>Vragenlijst</title>
                   <language>nl</language>
                 </survey>
               </sector>"""
     self.loginAsPortalOwner()
     addSurvey(self.portal, survey)
     addSurvey(self.portal, survey_nl)
     browser = Browser()
     browser.open(self.portal.client.absolute_url())
     browser.getLink("Nederlands").click()
     registerUserInClient(browser, link="Registreer")
     # Note, this used to test that the URL was that of the client,
     # in the correct country (nl), with `?language=nl-NL` appended.
     # I don't see where in the code this language URL parameter would
     # come from, so I remove it in this test as well.
     self.assertEqual(browser.url, "http://nohost/plone/client/nl")
     browser.getLink(id='button-new-session').click()
     self.assertEqual(
         browser.getControl(name="survey").options, ["branche/vragenlijst"])
     browser.open("%s?language=en" %
                  self.portal.client["nl"].absolute_url())
     browser.getLink(id='button-new-session').click()
     self.assertEqual(
         browser.getControl(name="survey").options, ["sector/survey"])
Beispiel #51
0
 def test_browser(self):
     import datetime
     from z3c.saconfig import Session
     from euphorie.client.model import SurveySession
     from euphorie.client.api.authentication import generate_token
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addAccount
     from euphorie.client.tests.utils import addSurvey
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     account = addAccount(password='******')
     survey_session = SurveySession(
         title=u'Dummy session',
         created=datetime.datetime(2012, 4, 22, 23, 5, 12),
         modified=datetime.datetime(2012, 4, 23, 11, 50, 30),
         zodb_path='nl/ict/software-development',
         account=account)
     Session.add(survey_session)
     browser = Browser()
     browser.addHeader('X-Euphorie-Token', generate_token(account))
     browser.handleErrors = False
     browser.open('http://nohost/plone/client/api/users/1/'
                  'sessions/1/report-identification')
     self.assertEqual(browser.headers['Content-Type'], 'application/rtf')
Beispiel #52
0
 def test_do_POST_survey_specify_title(self):
     from z3c.saconfig import Session
     from AccessControl.SecurityManagement import newSecurityManager
     from zope.publisher.browser import TestRequest
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.model import SurveySession
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.tests.utils import addAccount
     account = addAccount()
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     request = TestRequest()
     request.client = self.portal.client
     survey = self.portal.client['nl']['ict']['software-development']
     view = self.View(survey, request)
     view.input = {
         'survey': 'nl/ict/software-development',
         'title': u'Alternative title'
     }
     newSecurityManager(None, account)
     response = view.do_POST()
     self.assertTrue(response['next-step'].endswith('identification'))
     survey_session = Session.query(SurveySession).first()
     self.assertEqual(survey_session.title, u'Alternative title')
Beispiel #53
0
    def test_company_timestamp(self, mock_render, mock_applyChanges):
        with api.env.adopt_user("admin"):
            survey = addSurvey(self.portal, BASIC_SURVEY)
        account = addAccount(password="******")
        survey_session = model.SurveySession(
            id=456,
            title="Dummy session",
            created=datetime(2021, 4, 9, 9, 11, 31),
            modified=datetime(2021, 4, 9, 9, 11, 52),
            zodb_path="nl/ict/software-development",
            account=account,
        )
        model.Session.add(survey_session)
        survey = self.portal.client.nl.ict["software-development"]

        session_id = "++session++%d" % survey_session.id
        traversed_survey_session = survey.restrictedTraverse(session_id)

        with api.env.adopt_user(user=survey_session.account):
            with self._get_view(
                "report_company", traversed_survey_session, survey_session
            ) as view:
                view.request.form = {
                    "form.widgets.conductor": "staff",
                    "form.widgets.country": "nl",
                    "form.widgets.employees": "10-49",
                    "form.widgets.referer": "health-safety-experts",
                    "form.widgets.workers_participated": False,
                    "form.widgets.needs_met": True,
                    "form.widgets.recommend_tool": True,
                    "form.buttons.next": "",
                }
                view()
                timestamp = mock_applyChanges.call_args[0][0]["timestamp"]
                self.assertLess(datetime.now() - timestamp, timedelta(seconds=3))

                del view.request.form["form.buttons.next"]
                view.request.form["form.buttons.previous"] = ""
                view()
                self.assertEqual(mock_applyChanges.call_count, 2)
                timestamp = mock_applyChanges.call_args[0][0]["timestamp"]
                self.assertLess(datetime.now() - timestamp, timedelta(seconds=3))
Beispiel #54
0
    def createSurvey(self, survey):
        from euphorie.client.tests.utils import addSurvey

        self.loginAsPortalOwner()
        addSurvey(self.portal, survey)
    def XtestUpdateShowsRepeatableProfileItems(self):
        # Tests http://code.simplon.biz/tracker/tno-euphorie/ticket/85
        survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                      <title>Sector title</title>
                      <survey>
                        <title>Survey title</title>
                        <language>nl</language>
                        <profile-question>
                          <title>Multiple profile question</title>
                          <question>Profile titles</question>
                          <description>&lt;p&gt;Profile description.&lt;/p&gt;</description>
                          <risk type="policy">
                            <title>Profile risk</title>
                            <description>&lt;p&gt;Risk description.&lt;/p&gt;</description>
                            <evaluation-method>direct</evaluation-method>
                          </risk>
                        </profile-question>
                      </survey>
                    </sector>"""  # noqa: E501
        self.loginAsPortalOwner()
        addSurvey(self.portal, survey)
        browser = self.get_browser()
        browser.open(self.portal.client.nl["sector-title"]
                     ["survey-title"].absolute_url())
        registerUserInClient(browser)
        # Create a new survey session
        browser.getControl(name="title:utf8:ustring").value = "Test session"
        browser.getControl(name="next", index=1).click()
        # Start the survey
        browser.getForm().submit()
        # Enter the profile information
        browser.getControl(name="1:utext:list", index=0).value = "Profile 1"
        browser.getControl(name="1:utext:list", index=1).value = "Profile 2"
        browser.getForm().submit()
        # Change the survey and publish again
        from euphorie.client import publish

        survey = self.portal.sectors["nl"]["sector-title"]["survey-title"][
            "test-import"]
        survey.invokeFactory("euphorie.module", "test module")
        publisher = publish.PublishSurvey(survey, self.portal.REQUEST)
        publisher.publish()
        # We should get an update notification now
        browser.getLink("Start Risk Identification").click()
        self.assertEqual(
            browser.url,
            "http://nohost/plone/client/nl/sector-title/survey-title/update",
        )
        # And our current profile should be listed
        self.assertEqual(
            browser.getControl(name="1:utext:list", index=0).value,
            "Profile 1")
        self.assertEqual(
            browser.getControl(name="1:utext:list", index=1).value,
            "Profile 2")
        # Confirm the profile
        browser.getForm().submit()
        self.assertEqual(
            browser.url,
            "http://nohost/plone/client/nl/sector-title/"
            "survey-title/identification",
        )
        # Make sure the profile is correct
        browser.getLink("Start Risk Identification").click()
        self.assertTrue("Profile 1" in browser.contents)
        self.assertTrue("Profile 2" in browser.contents)
    def XtestSkipChildrenFalseForMandatoryModules(self):
        """Mandatory modules must have skip_children=False. It's possible that
        the module was optional with skip_children=True and now after the
        update must be mandatory.
        """
        survey = """<sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
                      <title>Sector title</title>
                      <survey>
                          <title>Survey title</title>
                          <language>nl</language>
                          <module optional="true">
                              <title>Module Title</title>
                              <description>&lt;p&gt;Testing ticket #3860&lt;/p&gt;</description>
                              <question>What is the sound of one hand clapping?</question>
                              <risk type="risk">
                                  <title>This risk exists</title>
                                  <problem-description>This risk doesn't exist</problem-description>
                                  <description>&lt;p&gt;asdg&lt;/p&gt;</description>
                                  <show-not-applicable>false</show-not-applicable>
                                  <evaluation-method>direct</evaluation-method>
                              </risk>
                          </module>
                      </survey>
                  </sector>"""  # noqa: E501

        self.loginAsPortalOwner()
        addSurvey(self.portal, survey)
        browser = self.get_browser()
        client_survey = self.portal.client.nl["sector-title"]["survey-title"]
        browser.open(client_survey.absolute_url())
        registerUserInClient(browser)
        # Create a new survey session
        browser.getControl(name="title:utf8:ustring").value = "Test session"
        browser.getControl(name="next", index=1).click()
        # Start the survey
        browser.getForm().submit()
        # Enter the profile information
        browser.getLink("Start Risk Identification").click()
        # Set Skip-children to True
        module_identification_url = browser.url
        browser.handleErrors = False
        # XXX: The following breaks when testing with sqlite but not with
        # postgres.
        browser.getControl(name="skip_children:boolean").controls[1].click()
        browser.getControl(name="next", index=1).click()
        # Change the survey to make the module required and publish again
        from euphorie.client import publish

        survey = self.portal.sectors["nl"]["sector-title"]["survey-title"][
            "test-import"]
        module = survey["1"]
        module.optional = False
        publisher = publish.PublishSurvey(survey, self.portal.REQUEST)
        publisher.publish()

        # We should get an update notification now
        browser.open(client_survey.absolute_url())
        browser.getLink("Start Risk Identification").click()
        # We should now be on the module
        self.assertEqual(browser.url, module_identification_url)
        # But this time, the module's "optional" question (i.e to skip the
        # children) should not be there
        self.assertRaises(LookupError,
                          browser.getControl,
                          name="skip_children:boolean")
        browser.getControl(name="next", index=1).click()
        # Now we must see the risk, i.e skip_children=False so we *must* answer
        # the risk
        self.assertEqual(
            "<legend>This risk exists</legend>" in browser.contents, True)
        # There are 2 inputs (2 radio, 1 hidden), for yes, no and postponed.
        self.assertEqual(len(browser.getControl(name="answer").controls), 3)
        self.assertEqual(
            browser.getControl(name="answer:default").value, "postponed")
Beispiel #57
0
    def createSurvey(self):
        from euphorie.client.tests.utils import addSurvey
        from euphorie.content.tests.utils import BASIC_SURVEY

        self.loginAsPortalOwner()
        addSurvey(self.portal, BASIC_SURVEY)
    def createSurvey(self):
        from euphorie.client.tests.utils import addSurvey

        addSurvey(self.portal, BASIC_SURVEY)
        return self.portal.sectors["nl"]["ict"]["software-development"][
            "test-import"]
    def testUnpublishedSurvey(self):
        from euphorie.content.tests.utils import addSurvey

        sector = createSector(self.portal)
        survey = addSurvey(sector, EMPTY_SURVEY)
        handleSurveyUnpublish(survey, None)