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"])
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")
class CKEditorTestCase(ptc.FunctionalTestCase): """base test case with convenience methods for all ckeditor tests""" def afterSetUp(self): super(CKEditorTestCase, self).afterSetUp() self.browser = Browser() self.uf = self.portal.acl_users self.uf.userFolderAddUser('root', 'secret', ['Manager'], []) self.ptool = getToolByName(self.portal, 'portal_properties') def loginAsManager(self, user='******', pwd='secret'): """points the browser to the login screen and logs in as user root with Manager role.""" self.browser.open('http://nohost/plone/') self.browser.getLink('Log in').click() self.browser.getControl('Login Name').value = user self.browser.getControl('Password').value = pwd self.browser.getControl('Log in').click() class layer(PloneSite): @classmethod def setUp(cls): # doctests don't play nicely with ipython try: iphook = sys.displayhook sys.displayhook = sys.__displayhook__ except: pass @classmethod def tearDown(cls): try: sys.displayhook = iphook except: pass
def test6734(self): self.loginAsPortalOwner() # We start off by copying the existing SimpleFolder type to # our own type 'MySimpleFolder'. For this type, we set the # SimpleFolder type to be the sole allowed content type. types = self.portal.portal_types types.manage_pasteObjects(types.manage_copyObjects(['SimpleFolder'])) types.manage_renameObjects(['copy_of_SimpleFolder'], ['MySimpleFolder']) my_type = types['MySimpleFolder'] attrs = dict(allowed_content_types=('SimpleFolder',), filter_content_types=True, portal_type='MySimpleFolder', title='MySimpleFolder') my_type.__dict__.update(attrs) browser = Browser() browser.addHeader('Authorization', 'Basic %s:%s' % ('portal_owner', user_password)) browser.open(self.folder.absolute_url()) browser.getLink('Add new').click() browser.getControl('MySimpleFolder').click() browser.getControl('Add').click() browser.getControl('Title').value = 'My dope folder' browser.getControl('Save').click() self.failUnless('Changes saved.' in browser.contents) self.failUnless('My dope folder' in browser.contents)
def testEmail(self): from euphorie.client.tests.utils import MockMailFixture from euphorie.client.tests.utils import addAccount self.addDummySurvey() addAccount() mail_fixture = MockMailFixture() self.portal.email_from_address = "*****@*****.**" self.portal.email_from_name = "Euphorie website" browser = Browser() browser.open(self.portal.client.nl.absolute_url()) browser.getLink('Login').click() browser.getLink("I forgot my password").click() browser.getControl(name="loginname").value = "*****@*****.**" browser.getControl(name="next").click() self.assertEqual(len(mail_fixture.storage), 1) (args, kw) = mail_fixture.storage[0] (mail, mto, mfrom) = args[:3] self.assertEqual(mfrom, "*****@*****.**") self.assertEqual(mto, "*****@*****.**") self.assertEqual( unicode(mail["Subject"]), u"OiRA registration reminder") body = mail.get_payload(0).get_payload(decode=True)\ .decode(mail.get_content_charset("utf-8")) self.failUnless(u"Øle" in body)
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)
class FuiLockerFunctionalTestCase(ptc.FunctionalTestCase): """Test case class used for functional (doc-)tests """ def afterSetUp(self): self.browser = Browser() # The following is useful when writing and debugging testself.browser tests. It lets # us see error messages properly. self.browser.handleErrors = False self.portal.error_log._ignored_exceptions = () # We then turn off the various portlets, because they sometimes duplicate links # and text (e.g. the navtree, the recent recent items listing) that we wish to # test for in our own views. Having no portlets makes things easier. left_column = getUtility(IPortletManager, name=u"plone.leftcolumn") left_assignable = getMultiAdapter((self.portal, left_column), IPortletAssignmentMapping) for name in left_assignable.keys(): del left_assignable[name] right_column = getUtility(IPortletManager, name=u"plone.rightcolumn") right_assignable = getMultiAdapter((self.portal, right_column), IPortletAssignmentMapping) for name in right_assignable.keys(): del right_assignable[name] def loginAdminClick(self): portal_url = self.portal.absolute_url() self.browser.open(portal_url + '/login_form?came_from=' + portal_url) self.browser.getControl(name='__ac_name').value = portal_owner self.browser.getControl(name='__ac_password').value = default_password self.browser.getControl(name='submit').click() def logoutClick(self): portal_url = self.portal.absolute_url() self.browser.getLink("Log out").click()
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 = 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"])
class TestCase(ptc.PloneTestCase): class layer(PloneSite): @classmethod def setUp(cls): fiveconfigure.debug_mode = True zcml.load_config('configure.zcml', uwosh.static.fix) fiveconfigure.debug_mode = False @classmethod def tearDown(cls): pass def afterSetUp(self): super(TestCase, self).afterSetUp() self.browser = Browser() self.uf = self.portal.acl_users self.uf.userFolderAddUser('root', 'secret', ['Manager'], []) def loginAsManager(self, user='******', pwd='secret'): """points the browser to the login screen and logs in as user root with Manager role.""" self.browser.open('http://nohost/plone/') self.browser.getLink('Log in').click() self.browser.getControl('Login Name').value = user self.browser.getControl('Password').value = pwd self.browser.getControl('Log in').click()
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 testUnknownAccount(self): self.addDummySurvey() browser = Browser() browser.open(self.portal.client.nl.absolute_url()) browser.getLink("I forgot my password").click() browser.getControl(name="loginname").value = "*****@*****.**" browser.getControl(name="next").click() self.failUnless("Unknown email address" in browser.contents)
def testUnknownAccount(self): self.addDummySurvey() browser = Browser() browser.open(self.portal.client.nl.absolute_url()) browser.getLink('Login').click() browser.getLink("I forgot my password").click() browser.getControl(name="loginname").value = "*****@*****.**" browser.getControl(name="next").click() self.failUnless("Unknown email address" in browser.contents)
def test_actions(self): # Ensure that all actions were registered. b = Browser() b.open(self.portal.absolute_url()+'/login') b.getControl(name='__ac_name').value = self.portal_owner b.getControl(name='__ac_password').value = self.default_password b.getControl(name='submit').click() b.open(self.portal.absolute_url()) self.assert_(b.getLink('Link management')) self.assert_(b.getLink('My links')) self.assert_(b.getLink('Links'))
def getBrowser(url): browser = Browser() browser.open(url) try: browser.getLink('Log in').click() except LinkNotFoundError: #!Plone4 pass browser.getControl(name='__ac_name').value = portal_owner browser.getControl(name='__ac_password').value = default_password browser.getControl(name='submit').click() return browser
def test_download_signatures(self): self.browser.open('http://nohost/plone/megaphone/signers') self.failIf('Download signatures' in self.browser.contents) browser = Browser() browser.handleErrors = False browser.addHeader('Authorization', 'Basic root:secret') browser.open('http://nohost/plone/megaphone/signers') browser.getLink('Download signatures as CSV').click() self.assertEqual('attachment; filename="saved-letters.csv"', browser.headers['content-disposition']) self.assertEqual('text/comma-separated-values;charset=utf-8', browser.headers['content-type']) self.assertEqual('body,Harvey,Frank,[email protected],,Seattle,WA,,body\r\n', browser.contents)
def test_delete_all_signatures(self): self.browser.open('http://nohost/plone/megaphone/signers') self.failIf('Delete all signatures' in self.browser.contents) browser = Browser() browser.handleErrors = False browser.addHeader('Authorization', 'Basic root:secret') browser.open('http://nohost/plone/megaphone/signers') self.failUnless('Harvey' in browser.contents) browser.getLink('Delete all signatures').click() self.assertEqual('http://nohost/plone/megaphone/signers', browser.url) self.failIf('Harvey' in browser.contents)
def test_remove_signature(self): # users can't remove unless they have Manage Portal permission self.browser.open('http://nohost/plone/megaphone/signers') self.failIf('Delete' in self.browser.contents) browser = Browser() browser.handleErrors = False browser.addHeader('Authorization', 'Basic root:secret') browser.open('http://nohost/plone/megaphone/signers') self.failUnless('Harvey' in browser.contents) browser.getLink('Delete').click() self.assertEqual('http://nohost/plone/megaphone/signers', browser.url) self.failIf('Harvey' in browser.contents)
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.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('@@login' not in browser.url)
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 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_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.getLink('Login').click() 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_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)
class ControlPanelTestCase(FunctionalTestCase): """base test case with convenience methods for all control panel tests""" def afterSetUp(self): super(ControlPanelTestCase, self).afterSetUp() self.browser = Browser() self.uf = self.portal.acl_users self.uf.userFolderAddUser('root', 'secret', ['Manager'], []) self.ptool = getToolByName(self.portal, 'portal_properties') self.site_props = self.ptool.site_properties self.fake_request = FakeRequest() def loginAsManager(self, user='******', pwd='secret'): """points the browser to the login screen and logs in as user root with Manager role.""" self.browser.open('http://nohost/plone/') self.browser.getLink('Log in').click() self.browser.getControl('Login Name').value = user self.browser.getControl('Password').value = pwd self.browser.getControl('Log in').click() def simplify_white_space(self, text): """For easier testing we replace all white space with one space. And we remove white space around '<' and '>'. So this: <p id="foo"> Bar </p> becomes this: <p id="foo">Bar</p> """ text = re.sub('\s*<\s*', '<', text) text = re.sub('\s*>\s*', '>', text) text = re.sub('\s+', ' ', text) return text
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"])
class PDFBookFunctionalTestCase(ptc.FunctionalTestCase, TestCaseMixin): def afterSetUp(self): super(PDFBookFunctionalTestCase, self).afterSetUp() self.makeBaseContent() self.browser = Browser() self.uf = self.portal.acl_users self.uf.userFolderAddUser('root', 'secret', ['Manager'], []) self.ptool = getToolByName(self.portal, 'portal_properties') self.site_props = self.ptool.site_properties return def loginAsManager(self, user='******', pwd='secret'): """points the browser to the login screen and logs in as user root with Manager role.""" self.browser.open('http://nohost/plone/') self.browser.getLink('Log in').click() self.browser.getControl('Login Name').value = user self.browser.getControl('Password').value = pwd self.browser.getControl('Log in').click() return
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)
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 _create_megaphone(self, type='letter'): browser = Browser() browser.handleErrors = False browser.addHeader('Authorization', 'Basic root:secret') browser.open('http://nohost/plone') browser.getLink('Megaphone Action').click() browser.getControl(name='intro.widgets.megaphone_type:list').value = [type] browser.getControl('Continue').click() browser.getControl('Title').value = 'Megaphone' browser.getControl('Continue').click() browser.getControl(name='crud-edit.captcha.widgets.select:list').value = ['true'] browser.getControl('Delete').click() while 1: try: browser.getControl('Continue').click() except LookupError: break browser.getControl('Finish').click() browser.open('http://nohost/plone/megaphone') browser.getLink('Publish').click()
class ControlPanelTestCase(FunctionalTestCase): """base test case with convenience methods for all control panel tests""" def afterSetUp(self): super(ControlPanelTestCase, self).afterSetUp() self.browser = Browser() self.uf = self.portal.acl_users self.uf.userFolderAddUser('root', 'secret', ['Manager'], []) self.ptool = getToolByName(self.portal, 'portal_properties') self.site_props = self.ptool.site_properties def loginAsManager(self, user='******', pwd='secret'): """points the browser to the login screen and logs in as user root with Manager role.""" self.browser.open('http://nohost/plone/') self.browser.getLink('Log in').click() self.browser.getControl('Login Name').value = user self.browser.getControl('Password').value = pwd self.browser.getControl('Log in').click() def simplify_white_space(self, text): """For easier testing we replace all white space with one space. And we remove white space around '<' and '>'. So this: <p id="foo"> Bar </p> becomes this: <p id="foo">Bar</p> """ text = re.sub('\s*<\s*', '<', text) text = re.sub('\s*>\s*', '>', text) text = re.sub('\s+', ' ', text) return text
class ControlPanelTestCase(FunctionalTestCase): """base test case with convenience methods for all control panel tests""" def afterSetUp(self): super(ControlPanelTestCase, self).afterSetUp() self.browser = Browser() self.uf = self.portal.acl_users self.uf.userFolderAddUser('root', 'secret', ['Manager'], []) self.ptool = getToolByName(self.portal, 'portal_properties') self.site_props = self.ptool.site_properties def loginAsManager(self, user='******', pwd='secret'): """points the browser to the login screen and logs in as user root with Manager role.""" self.browser.open('http://nohost/plone/') self.browser.getLink('Log in').click() self.browser.getControl('Login Name').value = user self.browser.getControl('Password').value = pwd self.browser.getControl('Log in').click()
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"])
class FolderTestCase(FunctionalTestCase): """base test case with convenience methods for all control panel tests""" def afterSetUp(self): super(FolderTestCase, self).afterSetUp() from Products.Five.testbrowser import Browser self.browser = Browser() self.uf = self.portal.acl_users self.uf.userFolderAddUser('root', 'secret', ['Manager'], []) def createDocuments(self, amount): self.setRoles([ 'Manager', ]) for i in xrange(1, amount + 1): self.portal.invokeFactory('Document', 'testing-%d' % i) document = getattr(self.portal, 'testing-%d' % i) document.setTitle(unicode('Testing \xc3\xa4 %d' % i, 'utf-8')) document.setExcludeFromNav(True) document.reindexObject() def createFolder(self, id='new-folder'): self.setRoles([ 'Manager', ]) self.portal.invokeFactory(id=id, type_name='Folder') folder = getattr(self.portal, id) folder.setTitle('New Folder') folder.setExcludeFromNav(True) folder.reindexObject() def loginAsManager(self): """points the browser to the login screen and logs in as user root with Manager role.""" self.browser.open('http://nohost/plone/') self.browser.getLink('Log in').click() self.browser.getControl('Login Name').value = 'root' self.browser.getControl('Password').value = 'secret' self.browser.getControl('Log in').click()
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 testEmail(self): from euphorie.client.tests.utils import MockMailFixture from euphorie.client.tests.utils import addAccount self.addDummySurvey() addAccount() mail_fixture = MockMailFixture() self.portal.email_from_address = "*****@*****.**" self.portal.email_from_name = "Euphorie website" browser = Browser() browser.open(self.portal.client.nl.absolute_url()) browser.getLink('Login').click() browser.getLink("I forgot my password").click() browser.getControl(name="loginname").value = "*****@*****.**" browser.getControl(name="next").click() self.assertEqual(len(mail_fixture.storage), 1) (args, kw) = mail_fixture.storage[0] (mail, mto, mfrom) = args[:3] self.assertEqual(mfrom, "*****@*****.**") self.assertEqual(mto, "*****@*****.**") self.assertEqual(unicode(mail["Subject"]), u"OiRA registration reminder") body = mail.get_payload(0).get_payload(decode=True)\ .decode(mail.get_content_charset("utf-8")) self.failUnless(u"Øle" in body)
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()
class FolderTestCase(FunctionalTestCase): """base test case with convenience methods for all control panel tests""" def afterSetUp(self): super(FolderTestCase, self).afterSetUp() from Products.Five.testbrowser import Browser self.browser = Browser() self.uf = self.portal.acl_users self.uf.userFolderAddUser('root', 'secret', ['Manager'], []) def createDocuments(self, amount): self.setRoles(['Manager',]) for i in xrange(1, amount + 1): self.portal.invokeFactory('Document', 'testing-%d' % i) document = getattr(self.portal, 'testing-%d' % i) document.setTitle(unicode('Testing \xc3\xa4 %d' % i, 'utf-8')) document.setExcludeFromNav(True) document.reindexObject() def createFolder(self, id='new-folder'): self.setRoles(['Manager',]) self.portal.invokeFactory(id=id, type_name='Folder') folder = getattr(self.portal, id) folder.setTitle('New Folder') folder.setExcludeFromNav(True) folder.reindexObject() def loginAsManager(self): """points the browser to the login screen and logs in as user root with Manager role.""" self.browser.open('http://nohost/plone/') self.browser.getLink('Log in').click() self.browser.getControl('Login Name').value = 'root' self.browser.getControl('Password').value = 'secret' self.browser.getControl('Log in').click()
def test_do_not_abort_on_far_future(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_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", index=1).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("Go to action plan").click() browser.getLink("Create action plan").click() browser.getLink("Next").click() # Try an early year browser.getControl(name="measure.action_plan:utf8:ustring:records")\ .value = "Do something awesome" browser.getControl(name="measure.planning_start_day:records")\ .value = "1" browser.getControl(name="measure.planning_start_month:records")\ .value = ["2"] browser.getControl(name="measure.planning_start_year:records")\ .value = "12345" 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 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"])
def testAliasesTab(self): browser = Browser() browser.addHeader("Authorization", "Basic %s:%s" % (portal_owner, default_password)) browser.open(self.portal.absolute_url()) aliases = browser.getLink(text='Aliases') self.failUnless('@@manage-aliases' in aliases.url)
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 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)