def testImageFromOtherSectorAccount(self): # http://code.simplon.biz/tracker/euphorie/ticket/143 import re from euphorie.content.tests.utils import createSector from euphorie.content.tests.utils import addSurvey from Products.Five.testbrowser import Browser sector = createSector(self.portal, login="******") self.loginAsPortalOwner() survey = addSurvey(sector) createSector(self.portal, id="sector2", login="******", password="******") self.logout() browser = Browser() browser.open("%s/@@login" % self.portal.absolute_url()) browser.getControl(name="__ac_name").value = "sector2" browser.getControl(name="__ac_password").value = "sector2" browser.getForm(id="loginForm").submit() risk = survey["1"]["2"] browser.open(risk.absolute_url()) match = re.search(r'<div class="introduction">\s*<img[^>]+src="([^"]+)', browser.contents) self.assertTrue(match) image_url = match.group(1) browser.open(image_url) self.assertEqual(browser.isHtml, False) self.assertEqual(browser.headers.maintype, "image")
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"])
def testImageFromOtherSectorAccount(self): # http://code.simplon.biz/tracker/euphorie/ticket/143 import re from euphorie.content.tests.utils import createSector from euphorie.content.tests.utils import addSurvey from Products.Five.testbrowser import Browser sector = createSector(self.portal, login="******") self.loginAsPortalOwner() survey = addSurvey(sector) createSector(self.portal, id="sector2", login="******", password="******") self.logout() browser = Browser() browser.open("%s/@@login" % self.portal.absolute_url()) browser.getControl(name="__ac_name").value = "sector2" browser.getControl(name="__ac_password").value = "sector2" browser.getForm(id="loginForm").submit() risk = survey["1"]["2"] browser.open(risk.absolute_url()) match = re.search( r'<div class="introduction">\s*<img[^>]+src="([^"]+)', browser.contents) self.assertTrue(match) image_url = match.group(1) browser.open(image_url) self.assertEqual(browser.isHtml, False) self.assertEqual(browser.headers.maintype, "image")
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")
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)
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"')
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 = "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 = "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() browser.open( "http://nohost/plone/client/nl/ict/software-development/actionplan/1/1" ) self.assertEqual(browser.getControl(name="priority").value, ["high"])
def adminBrowser(self): """Return a browser logged in as the site owner.""" from Products.PloneTestCase.setup import portal_owner from Products.PloneTestCase.setup import default_password from Products.Five.testbrowser import Browser browser = Browser() browser.open("%s/@@login" % self.portal.absolute_url()) browser.getControl(name="__ac_name").value = portal_owner browser.getControl(name="__ac_password").value = default_password browser.getForm(id="loginForm").submit() return browser
def startSurveySession(self): from Products.Five.testbrowser import Browser browser=Browser() browser.open(self.BASE_URL) # Register a new user testing.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.handleErrors=False return browser
def startSurveySession(self): from Products.Five.testbrowser import Browser browser = Browser() browser.open(self.BASE_URL) # Register a new user testing.registerUserInClient(browser) # Create a new survey session browser.getLink(id="button-new-session").click() browser.getControl(name="title:utf8:ustring").value = "Test session" browser.getControl(name="next").click() # Start the survey browser.getForm().submit() browser.handleErrors = False return browser
def test_recurrence(self): browser = Browser() browser.handleErrors = False browser.addHeader('Authorization', 'Basic %s:%s' % (portal_owner, default_password)) folder_url = self.folder.absolute_url() # Add event browser.open(folder_url + '/createObject?type_name=Event') form = browser.getForm('event-base-edit') form.getControl(name='title').value = 'An Event' form.getControl(name='startDate_year').value = ['2007'] form.getControl(name='startDate_month').value = ['04'] form.getControl(name='startDate_day').value = ['01'] form.getControl(name='startDate_hour').value = ['11'] form.getControl(name='startDate_minute').value = ['00'] form.getControl(name='endDate_year').value = ['2007'] form.getControl(name='endDate_month').value = ['04'] form.getControl(name='endDate_day').value = ['01'] form.getControl(name='endDate_hour').value = ['11'] form.getControl(name='endDate_minute').value = ['00'] # Edit the recurrence info: form.getControl(name='frequency').value = ['1'] form.getControl(name='interval').value = '6' form.getControl(name='form.button.save').click() # Make sure it's properly indexed: cat = self.portal.portal_catalog self.failUnless(len(cat(portal_type='Event', recurrence_days=732950)) == 1)
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><p>Profile description.</p></description> <risk type="policy"> <title>Profile risk</title> <description><p>Risk description.</p></description> <evaluation-method>direct</evaluation-method> </risk> </profile-question> <module optional="false"> <title>Module title</title> <description><p>Module description.</p></description> <risk type="policy"> <title>Module risk</title> <description><p>Module description.</p></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 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)
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><p>Een module met een top-5 risico.</p></description> <risk type="top5"> <title>Top-5 probleem!</title> <problem-description>Er is een top-5 probleem.</problem-description> <description><p>Zomaar wat tekst.</p></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 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 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><p>Profile description.</p></description> <risk type="policy"> <title>Profile risk</title> <description><p>Risk description.</p></description> <evaluation-method>direct</evaluation-method> </risk> </profile-question> <module optional="false"> <title>Module title</title> <description><p>Module description.</p></description> <risk type="policy"> <title>Module risk</title> <description><p>Module description.</p></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 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 """ 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)
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"])
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><p>Een module met een beleidsrisico.</p></description> <risk type="policy"> <title>Policy problem!</title> <problem-description>There is a policy problem.</problem-description> <description><p>Random text.</p></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 test_ui(self): from Products.Five.testbrowser import Browser browser = Browser() browser.addHeader("Authorization", "Basic %s:%s" % (portal_owner, default_password)) browser.handleErrors = False portal_url = self.portal.absolute_url() browser.open(portal_url) # Create a folder: browser.getLink("Folder").click() form = browser.getForm("folder-base-edit") form.getControl(name="title").value = "A Calendar" form.getControl(name="form_submit").click() # Create an event: browser.getLink(id="event").click() form = browser.getForm("event-base-edit") form.getControl(name="title").value = "An Event" form.getControl(name="startDate_year").value = ["2007"] form.getControl(name="startDate_month").value = ["04"] form.getControl(name="startDate_day").value = ["01"] form.getControl(name="startDate_hour").value = ["11"] form.getControl(name="startDate_minute").value = ["00"] form.getControl(name="endDate_year").value = ["2007"] form.getControl(name="endDate_month").value = ["04"] form.getControl(name="endDate_day").value = ["01"] form.getControl(name="endDate_hour").value = ["11"] form.getControl(name="endDate_minute").value = ["00"] form.getControl(name="form_submit").click() self.failUnless("an-event" in browser.url) browser.getLink("A Calendar").click() folder_url = browser.url browser.open(folder_url + "?date=2007-04-01") calendar = browser.contents[browser.contents.index('class="ploneCalendar"') :] self.failUnless("An Event" in calendar) browser.open(folder_url + "?date=2007-05-01") calendar = browser.contents[browser.contents.index('class="ploneCalendar"') :] self.failUnless("An Event" in calendar)
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><p>Een module met een top-5 risico.</p></description> <risk type="top5"> <title>Top-5 probleem!</title> <problem-description>Er is een top-5 probleem.</problem-description> <description><p>Zomaar wat tekst.</p></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)
def afterSetUp(self): ZopeTestCase.utils.setupCoreSessions(self.app) browser = Browser() browser.addHeader('Authorization', 'Basic %s:%s' % (portal_owner, default_password)) browser.handleErrors = False portal_url = self.portal.absolute_url() browser.open(portal_url) # Create a folder: browser.getLink('Folder').click() form = browser.getForm('folder-base-edit') form.getControl(name='title').value = 'A Calendar' if 'form_submit' in browser.contents: self.submit_name = 'form_submit' else: self.submit_name = 'form.button.save' form.getControl(name=self.submit_name).click() # Create a blank topic: browser.open(portal_url) browser.getLink('Collection').click() form = browser.getForm(name='edit_form') form.getControl(name='title').value = 'A Calendar Collection' form.getControl(name=self.submit_name).click()
def test_basic_views(self): browser = Browser() browser.addHeader('Authorization', 'Basic %s:%s' % (portal_owner, default_password)) browser.handleErrors = False portal_url = self.portal.absolute_url() # First check that they work empty: browser.open(portal_url + '/a-calendar') browser.getLink('Week').click() browser.getLink('Day').click() browser.getLink('List').click() browser.getLink('Past').click() # Create an event: browser.open(portal_url + '/a-calendar') browser.getLink(id='event').click() form = browser.getForm('event-base-edit') form.getControl(name='title').value = 'An Event' form.getControl(name='startDate_year').value = ['2007'] form.getControl(name='startDate_month').value = ['04'] form.getControl(name='startDate_day').value = ['01'] form.getControl(name='startDate_hour').value = ['11'] form.getControl(name='startDate_minute').value = ['00'] form.getControl(name='endDate_year').value = ['2007'] form.getControl(name='endDate_month').value = ['04'] form.getControl(name='endDate_day').value = ['01'] form.getControl(name='endDate_hour').value = ['11'] form.getControl(name='endDate_minute').value = ['00'] form.getControl(name=self.submit_name).click() self.failUnless('an-event' in browser.url) # Check that it still works: browser.open(portal_url + '/a-calendar/day.html?date=2007-04-01') self.failUnless(self._isInCalendar(browser, "An Event")) browser.getLink('Week').click() self.failUnless(self._isInCalendar(browser, "An Event")) browser.getLink('Day').click() self.failUnless(self._isInCalendar(browser, "An Event")) # This event is in the past (unless you have borrowed Guidos time-machine) browser.getLink('Past').click() self.failUnless(self._isInCalendar(browser, "An Event")) browser.getLink('List').click() self.failIf(self._isInCalendar(browser, "An Event"))
class BaseFunctionalTestCase(ptc.FunctionalTestCase): test_article_url = ( "https://www.borger.dk/_layouts/BorgerDK/Permalink/" "permalink.aspx?PageId=663a8046-3ab6-4d0e-8ec8-" "f27571137835&KommuneId=101" ) def afterSetUp(self): ptc.FunctionalTestCase.afterSetUp(self) self.browser = Browser() self.browser.handleErrors = False self.portal.error_log._ignored_exceptions = () def raising(self, info): import traceback traceback.print_tb(info[2]) print info[1] from Products.SiteErrorLog.SiteErrorLog import SiteErrorLog SiteErrorLog.raising = raising def loginAsAdmin(self): from Products.PloneTestCase.setup import portal_owner, default_password browser = self.browser browser.open(self.portal_url + "/login_form") browser.getControl(name="__ac_name").value = portal_owner browser.getControl(name="__ac_password").value = default_password browser.getControl(name="submit").click() def addTestArticle(self): self.loginAsAdmin() self.browser.open(self.portal_url + "/add-synchronized-document") form = self.browser.getForm(index=1) form.getControl("Article URL").value = self.test_article_url form.getControl("Add").click() @property def portal_url(self): return self.portal.absolute_url()
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> <profile-question> <title>Multiple profile question</title> <question>Profile titles</question> <description><p>Profile description.</p></description> <risk type="policy"> <title>Profile risk</title> <description><p>Risk description.</p></description> <evaluation-method>direct</evaluation-method> </risk> </profile-question> </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: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 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> <profile-question> <title>Multiple profile question</title> <question>Profile titles</question> <description><p>Profile description.</p></description> <risk type="policy"> <title>Profile risk</title> <description><p>Risk description.</p></description> <evaluation-method>direct</evaluation-method> </risk> </profile-question> </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: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> <module optional="true"> <title>Module Title</title> <description><p>Testing ticket #3860</p></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><p>asdg</p></description> <show-not-applicable>false</show-not-applicable> <evaluation-method>direct</evaluation-method> </risk> </module> </survey> </sector>""" self.loginAsPortalOwner() addSurvey(self.portal, survey) browser = 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')
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> <module optional="true"> <title>Module Title</title> <description><p>Testing ticket #3860</p></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><p>asdg</p></description> <show-not-applicable>false</show-not-applicable> <evaluation-method>direct</evaluation-method> </risk> </module> </survey> </sector>""" self.loginAsPortalOwner() addSurvey(self.portal, survey) browser = 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')