def _reinstall(self): """ We must uninstall and install the package, it seems generic setup profile is not applied coorectly by plone.app.testing in this testing layer. """ browser = Browser(self.app) # Login as site owner browser.open('{0}/login_form'.format(self.portal.absolute_url())) browser.getControl(name='__ac_name').value = SITE_OWNER_NAME browser.getControl(name='__ac_password').value = SITE_OWNER_PASSWORD browser.getControl(name='submit').click() # We must uninstall and install the package, it seems generic setup profile # is not applied coorectly by plone.app.testing in this testing layer. browser.open('{0}/prefs_install_products_form'.format(self.portal.absolute_url())) form = browser.getForm(index=2) self.assertEqual( form.action, '{0}/portal_quickinstaller'.format(self.portal.absolute_url()), u'Uninstall form not found') form.getControl(name='products:list').value = (u"collective.overridemailrecipients",) form.getControl(label='Deactivate').click() form = browser.getForm(index=1) self.assertEqual( form.action, '{0}/portal_quickinstaller/installProducts'.format(self.portal.absolute_url()), u'Install form not found') form.getControl(name='products:list').value = (u"collective.overridemailrecipients",) form.getControl(label='Activate').click()
class AutoCSRFProtectTests(unittest.TestCase, _BaseAutoTest): def setUp(self): self.portal = self.layer['portal'] self.browser = Browser(self.layer['app']) self.request = self.layer['request'] login(self.portal, TEST_USER_NAME) self.browser.open(self.portal.absolute_url() + '/login_form') self.browser.getControl(name='__ac_name').value = TEST_USER_NAME self.browser.getControl( name='__ac_password').value = TEST_USER_PASSWORD self.browser.getControl(name='submit').click() def open(self, path): self.browser.open(self.portal.absolute_url() + '/' + path) def test_CSRF_header(self): self.request.environ['HTTP_X_CSRF_TOKEN'] = createToken() view = AuthenticatorView(None, self.request) self.assertEqual(view.verify(), True) def test_incorrect_CSRF_header(self): self.request.environ['HTTP_X_CSRF_TOKEN'] = 'foobar' view = AuthenticatorView(None, self.request) self.assertEqual(view.verify(), False) def test_only_add_auth_when_user_logged_in(self): logout() self.open('logout') self.open('test-unprotected') try: self.browser.getForm('one').getControl(name="_authenticator") self.assertEqual('anonymous should not be protected', '') except LookupError: pass
class TestCSRF(unittest.TestCase): layer = PROTECT_FUNCTIONAL_TESTING def setUp(self): self.portal = self.layer['portal'] self.browser = Browser(self.layer['app']) self.request = self.layer['request'] self.browser.addHeader( 'Authorization', 'Basic %s:%s' % ( SITE_OWNER_NAME, SITE_OWNER_PASSWORD, )) def test_change_password_on_root_does_not_throw_other_csrf_protection( self): self.browser.open( '%s/acl_users/users/manage_users?user_id=%s&passwd=1' % (self.layer['app'].absolute_url(), SITE_OWNER_NAME)) self.browser.getControl(name='password').value = SITE_OWNER_PASSWORD self.browser.getControl(name='confirm').value = SITE_OWNER_PASSWORD self.browser.getForm().submit() self.assertEquals( self.browser.url, '%s/acl_users/users/manage_users?manage_tabs_message=password+updated' % (self.layer['app'].absolute_url()))
class FunctionalBaseTestCase(BaseTestCase): layer = PLONEINTRANET_WORKSPACE_FUNCTIONAL_TESTING def setUp(self): super(FunctionalBaseTestCase, self).setUp() self.browser = Browser(self.app) self.browser.handleErrors = False def browser_login_as_site_administrator(self): self.browser.open(self.portal.absolute_url() + "/login_form") self.browser.getControl(name="__ac_name").value = SITE_OWNER_NAME self.browser.getControl(name="__ac_password").value = SITE_OWNER_PASSWORD self.browser.getForm(id="login-panel").submit()
class FunctionalBaseTestCase(BaseTestCase): layer = PLONEINTRANET_WORKSPACE_FUNCTIONAL_TESTING def setUp(self): super(FunctionalBaseTestCase, self).setUp() self.browser = Browser(self.app) self.browser.handleErrors = False def browser_login_as_site_administrator(self): self.browser.open(self.portal.absolute_url() + '/login_form') self.browser.getControl(name='__ac_name').value = SITE_OWNER_NAME self.browser.getControl(name='__ac_password').value = \ SITE_OWNER_PASSWORD self.browser.getForm(id='login-panel').submit()
def _install(self): browser = Browser(self.app) # Login as site owner browser.open('{0}/login_form'.format(self.portal.absolute_url())) browser.getControl(name='__ac_name').value = SITE_OWNER_NAME browser.getControl(name='__ac_password').value = SITE_OWNER_PASSWORD browser.getControl(name='submit').click() # We must uninstall and install the package, it seems generic setup profile # is not applied coorectly by plone.app.testing in this testing layer. browser.open('{0}/prefs_install_products_form'.format(self.portal.absolute_url())) form = browser.getForm(index=1) self.assertEqual( form.action, '{0}/portal_quickinstaller/installProducts'.format(self.portal.absolute_url()), u'Install form not found') products_list = form.getControl(name='products:list') install_products = [ u"redomino.advancedkeyword", u"eea.facetednavigation", u"eea.facetednavigationtaxonomiccheckbox", ] for product in install_products: if product in products_list.options: products_list.value = (product,) form.getControl(label='Activate').click() browser.open(self.portal.absolute_url() + '/logout')
class TestCSRF(unittest.TestCase): layer = PROTECT_FUNCTIONAL_TESTING def setUp(self): self.portal = self.layer['portal'] self.browser = Browser(self.layer['app']) self.request = self.layer['request'] self.browser.addHeader( 'Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,)) def test_change_password_on_root_does_not_throw_other_csrf_protection(self): self.browser.open('%s/acl_users/users/manage_users?user_id=%s&passwd=1' % ( self.layer['app'].absolute_url(), SITE_OWNER_NAME)) self.browser.getControl(name='password').value = SITE_OWNER_PASSWORD self.browser.getControl(name='confirm').value = SITE_OWNER_PASSWORD self.browser.getForm().submit() self.assertEquals( self.browser.url, '%s/acl_users/users/manage_users?manage_tabs_message=password+updated' % ( self.layer['app'].absolute_url()))
class TestControlPanel(unittest.TestCase): """Test JSON views.""" layer = FUNCTIONAL_TESTING def setUp(self): self.portal = self.layer['portal'] self.document = api.content.create( container=self.portal, type='Document', title='Doc') self.browser = Browser(self.layer['app']) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic {0}:{1}'.format(SITE_OWNER_NAME, SITE_OWNER_PASSWORD)) commit() def test_add_vocabulary(self): self.browser.open(self.portal.absolute_url() + '/@@taxonomy-settings') self.assertIn('id="TaxonomySettings"', self.browser.contents) self.browser.getControl('Add').click() self.browser.getControl(name='form.widgets.taxonomy').value = 'foobar' self.browser.getControl(name='form.widgets.field_title').value = 'Foo Bar Vocabulary' self.browser.getControl(name='form.widgets.default_language:list').value = ['en'] self.browser.getForm(id='form').submit('Add') self.assertIn('<span class="label">Foo Bar Vocabulary</span>', self.browser.contents) def test_edit_vocabulary(self): self.browser.open(self.portal.absolute_url() + '/@@taxonomy-settings') self.assertIn('id="TaxonomySettings"', self.browser.contents) taxonomies = self.browser.getControl(name="form.widgets.taxonomies:list") taxonomies.controls[0].selected = True self.browser.getForm(id='TaxonomySettings').submit(name='form.buttons.edit-taxonomy') self.browser.getControl(name='form.widgets.field_title').value = 'Edited Test Vocabulary' self.browser.getForm(id='form').submit('Save') self.assertIn('<span class="label">Edited Test Vocabulary</span>', self.browser.contents)
class PortletMailmanTest(unittest.TestCase): layer = PORTLET_MAILMAN_FUNCTIONAL_TESTING def setUp(self): self.app = self.layer['app'] self.portal = self.layer['portal'] self.request = self.layer['request'] setRoles(self.portal, TEST_USER_ID, ['Manager']) self.quick_installer = getToolByName(self.portal, 'portal_quickinstaller') self.quick_installer.installProduct('collective.portlet.mailman') transaction.commit() self.browser = Browser(self.app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % ( TEST_USER_NAME, TEST_USER_PASSWORD,)) def test_add_portlet(self): portal_url = self.portal.absolute_url() self.browser.open(portal_url + '/@@manage-portlets') form = self.browser.getForm(index=1) field = form.getControl( name=':action', index=0) value = '/++contextportlets++plone.leftcolumn' + \ '/+/collective.portlet.mailman.Mailman' field.value = [value, ] form.submit() self.browser.getControl( name='form.header').value = "testlist header" self.browser.getControl( name='form.name').value = "TestList" self.browser.getControl( name='form.address').value = '*****@*****.**' self.browser.getControl( name='form.message').value = 'Thank you for subscribing' self.browser.getControl( name='form.actions.save').click()
class TestControlPanel(unittest.TestCase): """Test JSON views.""" layer = FUNCTIONAL_TESTING def setUp(self): self.portal = self.layer["portal"] setRoles(self.portal, TEST_USER_ID, ["Manager"]) self.portal.portal_workflow.setDefaultChain( "simple_publication_workflow") applyProfile(self.portal, "plone.app.contenttypes:plone-content") self.document = api.content.create(container=self.portal, type="Document", title="Doc") self.browser = Browser(self.layer["app"]) self.browser.handleErrors = False self.browser.addHeader( "Authorization", "Basic {0}:{1}".format(SITE_OWNER_NAME, SITE_OWNER_PASSWORD), ) commit() def test_add_vocabulary(self): self.browser.open(self.portal.absolute_url() + "/@@taxonomy-settings") self.assertIn('id="TaxonomySettings"', self.browser.contents) self.browser.getControl("Add").click() self.browser.getControl(name="form.widgets.taxonomy").value = "foobar" self.browser.getControl( name="form.widgets.field_title").value = "Foo Bar Vocabulary" self.browser.getControl( name="form.widgets.default_language:list").value = ["en"] self.browser.getForm(id="form").submit("Add") self.assertIn('<span class="label">Foo Bar Vocabulary</span>', self.browser.contents) def test_edit_vocabulary(self): self.browser.open(self.portal.absolute_url() + "/@@taxonomy-settings") self.assertIn('id="TaxonomySettings"', self.browser.contents) taxonomies = self.browser.getControl( name="form.widgets.taxonomies:list") taxonomies.controls[0].selected = True self.browser.getForm(id="TaxonomySettings").submit( name="form.buttons.edit-taxonomy") self.browser.getControl( name="form.widgets.field_title").value = "Edited Test Vocabulary" self.browser.getForm(id="form").submit("Save") self.assertIn('<span class="label">Edited Test Vocabulary</span>', self.browser.contents)
def _install(self): browser = Browser(self.app) # Login as site owner browser.open('{0}/login_form'.format(self.portal.absolute_url())) browser.getControl(name='__ac_name').value = SITE_OWNER_NAME browser.getControl(name='__ac_password').value = SITE_OWNER_PASSWORD browser.getControl(name='submit').click() # We must uninstall and install the package, it seems generic setup profile # is not applied coorectly by plone.app.testing in this testing layer. browser.open('{0}/prefs_install_products_form'.format(self.portal.absolute_url())) form = browser.getForm(index=1) self.assertEqual( form.action, '{0}/portal_quickinstaller/installProducts'.format(self.portal.absolute_url()), u'Install form not found') products_list = form.getControl(name='products:list') if "collective.googleauthenticator" in products_list.options: products_list.value = (u"collective.googleauthenticator",) form.getControl(label='Activate').click() browser.open(self.portal.absolute_url() + '/logout')
def test_mockmailhost_setting(self): # open contact form browser = Browser(self.app) browser.open('http://nohost/plone/contact-info') # Now fill in the form: form = browser.getForm(name='feedback_form') form.getControl(name='sender_fullname').value = 'T\xc3\xa4st user' form.getControl(name='sender_from_address').value = '*****@*****.**' form.getControl(name='subject').value = 'Saluton amiko to\xc3\xb1o' form.getControl( name='message' ).value = 'Message with funny chars: \xc3\xa1\xc3\xa9\xc3\xad\xc3\xb3\xc3\xba\xc3\xb1.' # And submit it: form.submit() self.assertEqual(browser.url, 'http://nohost/plone/contact-info') self.assertIn('Mail sent', browser.contents) # As part of our test setup, we replaced the original MailHost with our # own version. Our version doesn't mail messages, it just collects them # in a list called ``messages``: mailhost = self.portal.MailHost self.assertEqual(len(mailhost.messages), 1) msg = message_from_string(mailhost.messages[0]) self.assertEqual(msg['MIME-Version'], '1.0') self.assertEqual(msg['Content-Type'], 'text/plain; charset="utf-8"') self.assertEqual(msg['Content-Transfer-Encoding'], 'quoted-printable') self.assertEqual(msg['Subject'], '=?utf-8?q?Saluton_amiko_to=C3=B1o?=') self.assertEqual(msg['From'], '*****@*****.**') self.assertEqual(msg['To'], '*****@*****.**') msg_body = msg.get_payload() self.assertIn( u'Message with funny chars: =C3=A1=C3=A9=C3=AD=C3=B3=C3=BA=C3=B1', msg_body)
def _install(self): browser = Browser(self.app) # Login as site owner browser.open('{0}/login_form'.format(self.portal.absolute_url())) browser.getControl(name='__ac_name').value = SITE_OWNER_NAME browser.getControl(name='__ac_password').value = SITE_OWNER_PASSWORD browser.getControl(name='submit').click() # We must uninstall and install the package, it seems generic setup profile # is not applied coorectly by plone.app.testing in this testing layer. browser.open('{0}/prefs_install_products_form'.format( self.portal.absolute_url())) form = browser.getForm(index=1) self.assertEqual( form.action, '{0}/portal_quickinstaller/installProducts'.format( self.portal.absolute_url()), u'Install form not found') products_list = form.getControl(name='products:list') if "collective.googleauthenticator" in products_list.options: products_list.value = (u"collective.googleauthenticator", ) form.getControl(label='Activate').click() browser.open(self.portal.absolute_url() + '/logout')
class TestControlPanel(unittest.TestCase): """Test JSON views.""" layer = FUNCTIONAL_TESTING def setUp(self): self.portal = self.layer['portal'] self.portal.portal_workflow.setDefaultChain( 'simple_publication_workflow') applyProfile(self.portal, 'plone.app.contenttypes:plone-content') self.document = api.content.create( container=self.portal, type='Document', title='Doc') self.browser = Browser(self.layer['app']) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic {0}:{1}'.format(SITE_OWNER_NAME, SITE_OWNER_PASSWORD)) commit() def test_add_vocabulary(self): self.browser.open(self.portal.absolute_url() + '/@@taxonomy-settings') self.assertIn('id="TaxonomySettings"', self.browser.contents) self.browser.getControl('Add').click() self.browser.getControl(name='form.widgets.taxonomy').value = 'foobar' self.browser.getControl(name='form.widgets.field_title').value = 'Foo Bar Vocabulary' self.browser.getControl(name='form.widgets.default_language:list').value = ['en'] self.browser.getForm(id='form').submit('Add') self.assertIn('<span class="label">Foo Bar Vocabulary</span>', self.browser.contents) def test_edit_vocabulary(self): self.browser.open(self.portal.absolute_url() + '/@@taxonomy-settings') self.assertIn('id="TaxonomySettings"', self.browser.contents) taxonomies = self.browser.getControl(name="form.widgets.taxonomies:list") taxonomies.controls[0].selected = True self.browser.getForm(id='TaxonomySettings').submit(name='form.buttons.edit-taxonomy') self.browser.getControl(name='form.widgets.field_title').value = 'Edited Test Vocabulary' self.browser.getForm(id='form').submit('Save') self.assertIn('<span class="label">Edited Test Vocabulary</span>', self.browser.contents)
class AutoCSRFProtectTests(unittest.TestCase): layer = PROTECT_FUNCTIONAL_TESTING def setUp(self): self.portal = self.layer['portal'] self.browser = Browser(self.layer['app']) self.request = self.layer['request'] login(self.portal, TEST_USER_NAME) self.open('login_form') self.browser.getControl(name='__ac_name').value = TEST_USER_NAME self.browser.getControl( name='__ac_password').value = TEST_USER_PASSWORD self.browser.getControl(name='submit').click() def open(self, path): self.browser.open(self.portal.absolute_url() + '/' + path) def test_adds_csrf_protection_input(self): self.open('test-unprotected') self.assertTrue('name="_authenticator"' in self.browser.contents) def test_adds_csrf_protection_for_scheme_relative_same_domain(self): self.open('test-unprotected') form = self.browser.getForm('five') form.getControl(name="_authenticator") def test_adds_csrf_protection_for_relative_path(self): self.open('test-unprotected') form = self.browser.getForm('seven') form.getControl(name="_authenticator") def test_adds_csrf_protection_for_no_action(self): self.open('test-unprotected') form = self.browser.getForm('one') form.getControl(name="_authenticator") def test_does_not_add_csrf_protection_to_different_domain(self): self.open('test-unprotected') form = self.browser.getForm('six') try: form.getControl(name="_authenticator") self.assertEqual('should not add authenticator', '') except: pass def test_does_not_add_csrf_protection_to_different_domain_scheme_relative( self): self.open('test-unprotected') form = self.browser.getForm('four') try: form.getControl(name="_authenticator") self.assertEqual('should not add authenticator', '') except: pass def test_authentication_works_automatically(self): self.open('test-unprotected') self.browser.getControl('submit1').click() self.assertEqual(self.portal.foo, "bar") def test_authentication_works_for_other_form(self): self.open('test-unprotected') self.browser.getControl('submit2').click() self.assertEqual(self.portal.foo, "bar") def test_works_for_get_form_yet(self): self.open('test-unprotected') self.browser.getControl('submit3').click() def test_forbidden_raised_if_auth_failure(self): self.open('test-unprotected') self.browser.getForm('one').\ getControl(name="_authenticator").value = 'foobar' # XXX: plone.transformchain don't reraise exceptions # try: # self.browser.getControl('submit1').click() # except Exception, ex: # self.assertEquals(ex.getcode(), 403) self.browser.getControl('submit1').click() self.assertFalse(hasattr(self.portal, "foo")) def test_CSRF_header(self): self.request.environ['HTTP_X_CSRF_TOKEN'] = createToken() view = AuthenticatorView(None, self.request) self.assertEqual(view.verify(), True) def test_incorrect_CSRF_header(self): self.request.environ['HTTP_X_CSRF_TOKEN'] = 'foobar' view = AuthenticatorView(None, self.request) self.assertEqual(view.verify(), False) def test_only_add_auth_when_user_logged_in(self): logout() self.open('logout') self.open('test-unprotected') try: self.browser.getForm('one').getControl(name="_authenticator") self.assertEqual('anonymous should not be protected', '') except LookupError: pass def test_safe_to_write_with_v_safe_write(self): self.open('test-safetowrite') self.assertTrue(self.portal.foo, 'bar') self.assertEqual(self.browser.contents, 'done')
class AutoCSRFProtectTests(unittest.TestCase): layer = PROTECT_FUNCTIONAL_TESTING def setUp(self): self.portal = self.layer['portal'] self.browser = Browser(self.layer['app']) self.request = self.layer['request'] login(self.portal, TEST_USER_NAME) self.open('login_form') self.browser.getControl(name='__ac_name').value = TEST_USER_NAME self.browser.getControl( name='__ac_password').value = TEST_USER_PASSWORD self.browser.getControl(name='submit').click() def open(self, path): self.browser.open(self.portal.absolute_url() + '/' + path) def test_adds_csrf_protection_input(self): self.open('test-unprotected') self.assertTrue('name="_authenticator"' in self.browser.contents) def test_adds_csrf_protection_for_scheme_relative_same_domain(self): self.open('test-unprotected') form = self.browser.getForm('five') form.getControl(name="_authenticator") def test_adds_csrf_protection_for_relative_path(self): self.open('test-unprotected') form = self.browser.getForm('seven') form.getControl(name="_authenticator") def test_adds_csrf_protection_for_no_action(self): self.open('test-unprotected') form = self.browser.getForm('one') form.getControl(name="_authenticator") def test_does_not_add_csrf_protection_to_different_domain(self): self.open('test-unprotected') form = self.browser.getForm('six') try: form.getControl(name="_authenticator") self.assertEqual('should not add authenticator', '') except: pass def test_does_not_add_csrf_protection_to_different_domain_scheme_relative( self): self.open('test-unprotected') form = self.browser.getForm('four') try: form.getControl(name="_authenticator") self.assertEqual('should not add authenticator', '') except: pass def test_authentication_works_automatically(self): self.open('test-unprotected') self.browser.getControl('submit1').click() def test_authentication_works_for_other_form(self): self.open('test-unprotected') self.browser.getControl('submit2').click() def test_works_for_get_form_yet(self): self.open('test-unprotected') self.browser.getControl('submit3').click() def test_forbidden_raised_if_auth_failure(self): self.open('test-unprotected') self.browser.getForm('one').\ getControl(name="_authenticator").value = 'foobar' try: self.browser.getControl('submit1').click() except Exception, ex: self.assertEquals(ex.getcode(), 403)
class TestStudentBrowser(unittest.TestCase, CollectiveDataTableBrowserMixin): """ """ layer = COLLECTIVE_DATATABLE_FUNCTIONAL_TESTING def setUp(self): """ :return: """ self.school = None self.portal = self.layer['portal'] setRoles(self.portal, TEST_USER_ID, ['Manager', ]) self.installer = api.portal.get_tool('portal_quickinstaller') init_fixture(self, True) self.browser = Browser(self.layer['app']) def test_adding_by_browser(self): """ :return: """ _resource_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resources') _id = safe_unicode('test-first-name') _first_name = safe_unicode('Test First Name') _last_name = safe_unicode('Last') _gender = safe_unicode('male') _roll_number = safe_unicode('1001') _grade = safe_unicode('g4') _contact_number = safe_unicode('980000000') _profile_photo = 'student.jpg' _url = self.school.absolute_url() + '/++add++' + CONTENT_TYPE_STUDENT self.browser.open(_url) try: form = self.browser.getForm(id='form') except LookupError as exc: if not self.browser.cookies.get('__ac', None): self.browser_login() form = self.browser.getForm(id='form') else: raise LookupError(exc.message) # Fill the form form.getControl(name='form.widgets.first_name').value = _first_name form.getControl(name='form.widgets.last_name').value = _last_name form.getControl(name='form.widgets.gender:list').value = (_gender, ) form.getControl(name='form.widgets.roll_number').value = _roll_number form.getControl(name='form.widgets.grade:list').value = (_grade, ) form.getControl(name='form.widgets.contact_number').value = _contact_number form.getControl(name='form.widgets.IShortName.id').value = "test-first-name" form.getControl(name='form.widgets.IExcludeFromNavigation.exclude_from_nav:list').value = 1 form.getControl(name='form.widgets.INextPreviousToggle.nextPreviousEnabled:list').value = 1 image_control = form.getControl(name='form.widgets.profile_photo') image_control.add_file(open(os.path.join(_resource_path, _profile_photo), 'rb'), 'image/jpeg', _profile_photo) form.submit(form.getControl(name='form.buttons.save').value) self.assertEqual(self.school.absolute_url() + '/' + _id + '/view', self.browser.url, 'Current URL should be default view for newly created student') student = self.portal.portal_catalog.searchResults(portal_type=CONTENT_TYPE_STUDENT, id=_id) student = student[0] self.assertEqual(student.getObject().first_name, _first_name) self.assertEqual(student.getObject().gender, _gender) self.assertEqual(student.grade, _grade) self.assertEqual(student.roll_number, int(_roll_number)) self.assertEqual(_first_name + ' ' + _last_name, student.Title) def test_unique_roll_number(self): """ :return: """ _id = self.school.generateUniqueId(CONTENT_TYPE_STUDENT) _first_name = safe_unicode('Test First Name') _last_name = safe_unicode('Last') _gender = safe_unicode('male') _roll_number = safe_unicode('1001') _grade = safe_unicode('g4') _contact_number = safe_unicode('980000000') _url = self.school.absolute_url() + '/++add++' + CONTENT_TYPE_STUDENT self.browser.open(_url) try: form = self.browser.getForm(id='form') except LookupError as exc: if not self.browser.cookies.get('__ac', None): self.browser_login() form = self.browser.getForm(id='form') else: raise LookupError(exc.message) # Fill the form form.getControl(name='form.widgets.first_name').value = _first_name form.getControl(name='form.widgets.last_name').value = _last_name form.getControl(name='form.widgets.gender:list').value = (_gender, ) form.getControl(name='form.widgets.roll_number').value = _roll_number form.getControl(name='form.widgets.grade:list').value = (_grade, ) form.getControl(name='form.widgets.contact_number').value = _contact_number form.getControl(name='form.widgets.IShortName.id').value = _id form.getControl(name='form.widgets.IExcludeFromNavigation.exclude_from_nav:list').value = 1 form.getControl(name='form.widgets.INextPreviousToggle.nextPreviousEnabled:list').value = 1 form.submit(form.getControl(name='form.buttons.save').value) _id = self.school.generateUniqueId(CONTENT_TYPE_STUDENT) self.browser.open(_url) # Fill the form again form = self.browser.getForm(id='form') form.getControl(name='form.widgets.first_name').value = _first_name form.getControl(name='form.widgets.last_name').value = _last_name form.getControl(name='form.widgets.gender:list').value = (_gender, ) form.getControl(name='form.widgets.roll_number').value = _roll_number form.getControl(name='form.widgets.grade:list').value = (_grade, ) form.getControl(name='form.widgets.contact_number').value = _contact_number form.getControl(name='form.widgets.IShortName.id').value = _id form.getControl(name='form.widgets.IExcludeFromNavigation.exclude_from_nav:list').value = 1 form.getControl(name='form.widgets.INextPreviousToggle.nextPreviousEnabled:list').value = 1 form.submit(form.getControl(name='form.buttons.save').value) self.assertNotEqual(self.school.absolute_url() + '/' + _id + '/view', self.browser.url, 'Current URL should not be default view, as validation error.') html_output = BeautifulSoup(self.browser.contents.strip('\n'), 'lxml') roll_container = html_output.find('div', id='formfield-form-widgets-roll_number') error = roll_container.find('div', class_='fieldErrorBox').find('div', class_='error') # We make sure error message shown. self.assertIsNotNone(error) self.assertTrue(0 < len(error.text)) def tearDown(self): """ :return: """ error_log = getToolByName(self.portal, 'error_log') if len(error_log.getLogEntries()): print error_log.getLogEntries()[-1]['tb_text'] super(TestStudentBrowser, self).tearDown()
class LanguageControlPanelFunctionalTest(unittest.TestCase): """Test that changes in the language control panel are actually stored in the registry. """ layer = PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING def setUp(self): self.app = self.layer['app'] self.portal = self.layer['portal'] self.portal_url = self.portal.absolute_url() self.browser = Browser(self.app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % ( SITE_OWNER_NAME, SITE_OWNER_PASSWORD, )) def _inject_available_languages_field(self, value): """The in-and-out widget does not work without javascript, therefore we have to inject some values in order to make saving the form work. """ form = self.browser.getForm(id='LanguageControlPanel') form.mech_form.new_control( type='hidden', name='form.widgets.available_languages:list', attrs=dict(value=value)) self.browser.getControl('Save').click() def test_language_control_panel_link(self): self.browser.open("%s/plone_control_panel" % self.portal_url) self.browser.getLink('Language').click() self.assertTrue("Language Settings" in self.browser.contents) def test_language_control_panel_backlink(self): self.browser.open("%s/@@language-controlpanel" % self.portal_url) self.assertTrue("Plone Configuration" in self.browser.contents) def test_language_control_panel_sidebar(self): self.browser.open("%s/@@language-controlpanel" % self.portal_url) self.browser.getLink('Site Setup').click() self.assertEqual(self.browser.url, 'http://nohost/plone/@@overview-controlpanel') def test_language_controlpanel_view(self): view = getMultiAdapter((self.portal, self.portal.REQUEST), name="language-controlpanel") view = view.__of__(self.portal) self.assertTrue(view()) def test_default_language(self): registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open("%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.default_language, 'en') self.assertEqual( self.browser.getControl('Site language').value, ['en']) self.browser.getControl('Site language').value = ['de'] self._inject_available_languages_field('en') self._inject_available_languages_field('de') self.browser.getControl(name='form.buttons.save').click() self.assertEqual(settings.default_language, 'de') # def test_available_languages(self): # registry = getUtility(IRegistry) # settings = registry.forInterface(ILanguageSchema, prefix='plone') # self.browser.open( # "%s/@@language-controlpanel" % self.portal_url) # self.assertEqual(settings.available_languages, ['en']) # self.assertEqual( # self.browser.getControl( # name='form.widgets.available_languages.to' # ).options, # ['en'] # ) # control = self.browser.getForm(index=1) # self.in_out_select( # control, 'form.widgets.available_languages:list', 'Deutsch') # self.browser.getControl('Save').click() # self.assertEqual(settings.available_languages, ['en', 'de']) def test_use_combined_language_codes(self): registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open("%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_combined_language_codes, False) self.assertEqual( self.browser.getControl( 'Show country-specific language variants').selected, False) self.browser.getControl( 'Show country-specific language variants').selected = True self._inject_available_languages_field('en') self.browser.getControl('Save').click() self.assertEqual(settings.use_combined_language_codes, True) def test_display_flags(self): registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open("%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.display_flags, False) self.assertEqual( self.browser.getControl('Show language flags').selected, False) self.browser.getControl('Show language flags').selected = True self._inject_available_languages_field('en') self.browser.getControl('Save').click() self.assertEqual(settings.display_flags, True) def test_use_content_negotiation(self): registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open("%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_content_negotiation, False) self.assertEqual( self.browser.getControl( 'Use the language of the content item').selected, False) self.browser.getControl( 'Use the language of the content item').selected = True self._inject_available_languages_field('en') self.browser.getControl('Save').click() self.assertEqual(settings.use_content_negotiation, True) def test_use_path_negotiation(self): registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open("%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_path_negotiation, False) self.assertEqual( self.browser.getControl( 'Use language codes in URL path for manual override').selected, False) self.browser.getControl( 'Use language codes in URL path for manual override' ).selected = True self._inject_available_languages_field('en') self.browser.getControl('Save').click() self.assertEqual(settings.use_path_negotiation, True) def test_use_cookie_negotiation(self): registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open("%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_cookie_negotiation, False) self.assertEqual( self.browser.getControl('Use cookie for manual override').selected, False) self.browser.getControl( 'Use cookie for manual override').selected = True self._inject_available_languages_field('en') self.browser.getControl('Save').click() self.assertEqual(settings.use_cookie_negotiation, True) def test_authenticated_users_only(self): control_label = "Authenticated users only" registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open("%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.authenticated_users_only, False) self.assertEqual( self.browser.getControl(control_label).selected, False) self.browser.getControl(control_label).selected = True self._inject_available_languages_field('en') self.browser.getControl('Save').click() self.assertEqual(settings.authenticated_users_only, True) def test_set_cookie_always(self): control_label = "Set the language cookie always" registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open("%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.set_cookie_always, False) self.assertEqual( self.browser.getControl(control_label).selected, False) self.browser.getControl(control_label).selected = True # The in-and-out widget does not work without javascript, therefore # we have to inject some values in order to make saving the form work. form = self.browser.getForm(id='LanguageControlPanel') form.mech_form.new_control( type='hidden', name='form.widgets.available_languages:list', attrs=dict(value='en')) self.browser.getControl('Save').click() self.assertEqual(settings.set_cookie_always, True) def test_use_subdomain_negotiation(self): control_label = "Use subdomain" registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open("%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_subdomain_negotiation, False) self.assertEqual( self.browser.getControl(control_label).selected, False) self.browser.getControl(control_label).selected = True # The in-and-out widget does not work without javascript, therefore # we have to inject some values in order to make saving the form work. form = self.browser.getForm(id='LanguageControlPanel') form.mech_form.new_control( type='hidden', name='form.widgets.available_languages:list', attrs=dict(value='en')) self.browser.getControl('Save').click() self.assertEqual(settings.use_subdomain_negotiation, True) def test_use_cctld_negotiation(self): control_label = "Use top-level domain" registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open("%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_cctld_negotiation, False) self.assertEqual( self.browser.getControl(control_label).selected, False) self.browser.getControl(control_label).selected = True # The in-and-out widget does not work without javascript, therefore # we have to inject some values in order to make saving the form work. form = self.browser.getForm(id='LanguageControlPanel') form.mech_form.new_control( type='hidden', name='form.widgets.available_languages:list', attrs=dict(value='en')) self.browser.getControl('Save').click() self.assertEqual(settings.use_cctld_negotiation, True) def test_use_request_negotiation(self): control_label = "Use browser language request negotiation" registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open("%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_request_negotiation, False) self.assertEqual( self.browser.getControl(control_label).selected, False) self.browser.getControl(control_label).selected = True # The in-and-out widget does not work without javascript, therefore # we have to inject some values in order to make saving the form work. form = self.browser.getForm(id='LanguageControlPanel') form.mech_form.new_control( type='hidden', name='form.widgets.available_languages:list', attrs=dict(value='en')) self.browser.getControl('Save').click() self.assertEqual(settings.use_request_negotiation, True)
class TypesControlPanelFunctionalTest(unittest.TestCase): """Test that changes in the types control panel are actually stored in the registry. """ layer = PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING def setUp(self): self.app = self.layer['app'] self.portal = self.layer['portal'] self.portal_url = self.portal.absolute_url() self.types_url = "%s/@@types-controlpanel" % self.portal_url self.browser = Browser(self.app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) ) def test_types_control_panel_link(self): self.browser.open( "%s/plone_control_panel" % self.portal_url) self.browser.getLink('Editing').click() def test_standard_type_select(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.assertIn('types-controlpanel', self.browser.url) def test_standard_type_cancel(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getControl('Cancel').click() self.assertIn('plone_control_panel', self.browser.url) def test_standard_type_allow_commenting(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.browser.getControl('Allow comments').selected = True self.browser.getControl('Apply Changes').click() # Check if settings got saved correctly self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.assertIn('Globally addable', self.browser.contents) self.assertIn('Allow comments', self.browser.contents) self.assertEquals( self.browser.getControl('Allow comments').selected, True ) self.assertIn('Visible in searches', self.browser.contents) self.assertIn( '<input id="redirect_links" type="checkbox" class="noborder"' ' name="redirect_links:boolean" checked="checked" />', self.browser.contents) self.assertIn( '<label for="redirect_links">Redirect immediately to link target', self.browser.contents ) def test_standard_types_redirect_links(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.browser.getControl( 'Redirect immediately to link target' ).selected = True self.browser.getControl('Apply Changes').click() # Check if settings got saved correctly self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.assertTrue( 'Redirect immediately to link target' in self.browser.contents ) self.assertEquals( self.browser.getControl( 'Redirect immediately to link target').selected, True ) def test_set_no_default_workflow(self): # references http://dev.plone.org/plone/ticket/11901 self.browser.open(self.types_url) self.browser.getControl(name="new_workflow").value = ['[none]'] self.browser.getControl(name="form.button.Save").click() # Check that setting No workflow as default workflow doesn't break # break editing types self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.assertIn('Globally addable', self.browser.contents) self.assertIn('Allow comments', self.browser.contents) self.assertIn('Visible in searches', self.browser.contents)
class TestBookBrowser(unittest.TestCase, CollectiveDataTableBrowserMixin): """ """ layer = COLLECTIVE_DATATABLE_FUNCTIONAL_TESTING def setUp(self): """ :return: """ self.school = None self.library = None self.portal = self.layer['portal'] setRoles(self.portal, TEST_USER_ID, ['Manager', ]) self.installer = api.portal.get_tool('portal_quickinstaller') init_fixture(self, True) self.browser = Browser(self.layer['app']) def test_adding_by_browser(self): """ :return: """ _resource_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resources') _id = safe_unicode('test-first-book') _title = safe_unicode('Test First Book') _description = safe_unicode('The test description') _details = safe_unicode('<h1>Test Book Details</h1>') _isbn = safe_unicode('ISBN 978-0-306-40615-7') _author = safe_unicode('Test Author') _publisher = safe_unicode('Test Publisher') _number_of_copy = safe_unicode('10') _cover_photo = 'book.jpg' _url = self.library.absolute_url() + '/++add++' + CONTENT_TYPE_BOOK self.browser.open(_url) try: form = self.browser.getForm(id='form') except LookupError as exc: if not self.browser.cookies.get('__ac', None): self.browser_login() form = self.browser.getForm(id='form') else: raise LookupError(exc.message) # Fill the form form.getControl(name='form.widgets.title').value = _title form.getControl(name='form.widgets.description').value = _description form.getControl(name='form.widgets.isbn').value = _isbn form.getControl(name='form.widgets.details').value = _details form.getControl(name='form.widgets.publisher').value = _publisher form.getControl(name='form.widgets.author').value = _author form.getControl(name='form.widgets.number_of_copy').value = _number_of_copy form.getControl(name='form.widgets.IShortName.id').value = _id form.getControl(name='form.widgets.IExcludeFromNavigation.exclude_from_nav:list').value = 1 form.getControl(name='form.widgets.INextPreviousToggle.nextPreviousEnabled:list').value = 1 image_control = form.getControl(name='form.widgets.cover_photo') image_control.add_file(open(os.path.join(_resource_path, _cover_photo), 'rb'), 'image/jpeg', _cover_photo) form.submit(form.getControl(name='form.buttons.save').value) self.assertEqual(self.library.absolute_url() + '/' + _id + '/view', self.browser.url, 'Current URL should be default view for newly created book') book = self.portal.portal_catalog.searchResults(portal_type=CONTENT_TYPE_BOOK, id=_id) book = book[0] self.assertEqual(book.Title, _title) self.assertEqual(book.getObject().isbn, _isbn) # Test Indexer self.assertEqual(book_stock(book.getObject())(), book.book_stock) # Test Default value self.assertEqual(book.getObject().number_of_loan_copy, 0) self.assertEqual(int(book.getObject().number_of_copy), int(_number_of_copy)) def test_invalid_ssn(self): """ :return: """ _id = safe_unicode('test-first-book') _title = safe_unicode('Test First Book') _description = safe_unicode('The test description') _isbn = safe_unicode('ISBN 978-0-3-0-40615-7') _number_of_copy = safe_unicode('10') _url = self.library.absolute_url() + '/++add++' + CONTENT_TYPE_BOOK self.browser.open(_url) try: form = self.browser.getForm(id='form') except LookupError as exc: if not self.browser.cookies.get('__ac', None): self.browser_login() form = self.browser.getForm(id='form') else: raise LookupError(exc.message) # Fill the form form.getControl(name='form.widgets.title').value = _title form.getControl(name='form.widgets.description').value = _description form.getControl(name='form.widgets.isbn').value = _isbn form.getControl(name='form.widgets.number_of_copy').value = _number_of_copy form.getControl(name='form.widgets.IShortName.id').value = _id form.submit(form.getControl(name='form.buttons.save').value) self.assertEqual(self.library.absolute_url() + '/++add++' + CONTENT_TYPE_BOOK, self.browser.url, 'Current URL should be same as add url `++add++%s`, because of validation error' % CONTENT_TYPE_BOOK) html_output = BeautifulSoup(self.browser.contents.strip('\n'), 'lxml') isbn_container = html_output.find('div', id='formfield-form-widgets-isbn') error = isbn_container.find('div', class_='fieldErrorBox').find('div', class_='error') # We make sure error message shown. self.assertIsNotNone(error) # We make sure `ISBN` related message self.assertIn('isbn', error.text.lower()) def tearDown(self): """ :return: """ error_log = getToolByName(self.portal, 'error_log') if len(error_log.getLogEntries()): print error_log.getLogEntries()[-1]['tb_text'] super(TestBookBrowser, self).tearDown()
class TestBookReviewBrowser(unittest.TestCase, CollectiveDataTableBrowserMixin): """ """ layer = COLLECTIVE_DATATABLE_FUNCTIONAL_TESTING def setUp(self): """ :return: """ self.school = None self.student = None self.library = None self.book = None self.portal = self.layer["portal"] setRoles(self.portal, TEST_USER_ID, ["Manager"]) self.installer = api.portal.get_tool("portal_quickinstaller") init_fixture(self, True) self.browser = Browser(self.layer["app"]) def test_adding_by_browser(self): """ :return: """ _resource_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "resources") _id = safe_unicode("test-first-review") _title = safe_unicode("Test First Review") _description = safe_unicode("<h1>Test Book Review</h1>") _reviewer = self.student.UID() _attachment = "test-review.pdf" _url = self.book.absolute_url() + "/++add++" + CONTENT_TYPE_BOOK_REVIEW self.browser.open(_url) try: form = self.browser.getForm(id="form") except LookupError as exc: if not self.browser.cookies.get("__ac", None): self.browser_login() form = self.browser.getForm(id="form") else: raise LookupError(exc.message) # Fill the form form.getControl(name="form.widgets.title").value = _title form.getControl(name="form.widgets.description").value = _description form.getControl(name="form.widgets.reviewer").value = _reviewer form.getControl(name="form.widgets.IShortName.id").value = _id form.getControl(name="form.widgets.IExcludeFromNavigation.exclude_from_nav:list").value = 1 form.getControl(name="form.widgets.INextPreviousToggle.nextPreviousEnabled:list").value = 1 file_control = form.getControl(name="form.widgets.attachment") file_control.add_file(open(os.path.join(_resource_path, _attachment), "rb"), "application/pdf", _attachment) form.submit(form.getControl(name="form.buttons.save").value) self.assertEqual( self.book.absolute_url() + "/" + _id + "/view", self.browser.url, "Current URL should be default view for newly created review", ) review = self.portal.portal_catalog.searchResults(portal_type=CONTENT_TYPE_BOOK_REVIEW, id=_id) review = review[0] self.assertEqual(review.Title, _title) self.assertEqual(review.getObject().reviewer.to_object, self.student) self.assertEqual(review.getObject().attachment.filename, _attachment) def tearDown(self): """ :return: """ error_log = getToolByName(self.portal, "error_log") if len(error_log.getLogEntries()): print error_log.getLogEntries()[-1]["tb_text"] super(TestBookReviewBrowser, self).tearDown()
class TypesControlPanelFunctionalTest(unittest.TestCase): """Test that changes in the types control panel are actually stored in the registry. """ layer = PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING def setUp(self): self.app = self.layer['app'] self.portal = self.layer['portal'] self.portal_url = self.portal.absolute_url() self.types_url = "%s/@@content-controlpanel" % self.portal_url self.browser = Browser(self.app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) ) def test_types_control_panel_link(self): self.browser.open( "%s/@@overview-controlpanel" % self.portal_url) self.browser.getLink('Editing').click() def test_standard_type_select(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.assertIn('content-controlpanel', self.browser.url) def test_standard_type_cancel(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getControl('Cancel').click() self.assertIn('@@overview-controlpanel', self.browser.url) def test_standard_type_allow_commenting(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.browser.getControl('Allow comments').selected = True self.browser.getControl('Save').click() # Check if settings got saved correctly self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.assertIn('Globally addable', self.browser.contents) self.assertIn('Allow comments', self.browser.contents) self.assertEquals( self.browser.getControl('Allow comments').selected, True ) self.assertIn('Visible in searches', self.browser.contents) self.assertIn( '<input id="redirect_links" type="checkbox" class="noborder"' ' name="redirect_links:boolean" checked="checked" />', self.browser.contents) self.assertIn( '<label for="redirect_links">Redirect immediately to link target', self.browser.contents ) def test_standard_types_redirect_links(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.browser.getControl( 'Redirect immediately to link target' ).selected = True self.browser.getControl('Save').click() # Check if settings got saved correctly self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.assertTrue( 'Redirect immediately to link target' in self.browser.contents ) self.assertEquals( self.browser.getControl( 'Redirect immediately to link target').selected, True ) def test_set_no_default_workflow(self): # references http://dev.plone.org/plone/ticket/11901 self.browser.open(self.types_url) self.browser.getControl(name="new_workflow").value = ['[none]'] self.browser.getControl(name="form.button.Save").click() # Check that setting No workflow as default workflow doesn't break # break editing types self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.assertIn('Globally addable', self.browser.contents) self.assertIn('Allow comments', self.browser.contents) self.assertIn('Visible in searches', self.browser.contents) def test_disable_versioning_removes_behavior(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Document'] self.browser.getForm(action=self.types_url).submit() self.browser.getControl(name='versionpolicy').value = ['off'] self.browser.getForm(action=self.types_url).submit() portal_types = self.portal.portal_types doc_type = portal_types.Document self.assertTrue( 'plone.app.versioningbehavior.behaviors.IVersionable' not in doc_type.behaviors) # noqa def test_enable_versioning_behavior_on_document(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Document'] self.browser.getForm(action=self.types_url).submit() self.browser.getControl(name='versionpolicy').value = ['off'] self.browser.getForm(action=self.types_url).submit() portal_types = self.portal.portal_types doc_type = portal_types.Document self.assertTrue( 'plone.app.versioningbehavior.behaviors.IVersionable' not in doc_type.behaviors) # noqa self.browser.getControl(name='versionpolicy').value = ['manual'] self.browser.getForm(action=self.types_url).submit() self.assertTrue( 'plone.app.versioningbehavior.behaviors.IVersionable' in doc_type.behaviors) def test_enable_versioning_behavior_on_file(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['File'] self.browser.getForm(action=self.types_url).submit() self.browser.getControl(name='versionpolicy').value = ['off'] self.browser.getForm(action=self.types_url).submit() portal_types = self.portal.portal_types file_type = portal_types.File # File has no Versioning and no Locking on default, but needs it self.assertTrue( 'plone.app.versioningbehavior.behaviors.IVersionable' not in file_type.behaviors) # noqa self.assertTrue( 'plone.app.lockingbehavior.behaviors.ILocking' not in file_type.behaviors) # noqa self.browser.getControl(name='versionpolicy').value = ['manual'] self.browser.getForm(action=self.types_url).submit() self.assertTrue( 'plone.app.versioningbehavior.behaviors.IVersionable' in file_type.behaviors) self.assertTrue( 'plone.app.lockingbehavior.behaviors.ILocking' in file_type.behaviors)
class TestLibraryBrowser(unittest.TestCase, CollectiveDataTableBrowserMixin): """ """ layer = COLLECTIVE_DATATABLE_FUNCTIONAL_TESTING def setUp(self): """ :return: """ self.school = None self.portal = self.layer['portal'] setRoles(self.portal, TEST_USER_ID, ['Manager', ]) self.installer = api.portal.get_tool('portal_quickinstaller') init_fixture(self, True) self.browser = Browser(self.layer['app']) def test_adding_by_browser(self): """ :return: """ _url = self.school.absolute_url() + '/++add++' + CONTENT_TYPE_LIBRARY self.browser.open(_url) try: form = self.browser.getForm(id='form') except LookupError as exc: if not self.browser.cookies.get('__ac', None): self.browser_login() form = self.browser.getForm(id='form') else: raise LookupError(exc.message) # Fill the form form.getControl(name='form.widgets.title').value = 'New Test Library' form.getControl(name='form.widgets.description').value = "<b>Test description for this library</b>" form.getControl(name='form.widgets.IShortName.id').value = "test-library-url" form.getControl(name='form.widgets.IExcludeFromNavigation.exclude_from_nav:list').value = 1 form.getControl(name='form.widgets.INextPreviousToggle.nextPreviousEnabled:list').value = 1 form.submit(form.getControl(name='form.buttons.save').value) self.assertEqual(self.school.absolute_url() + '/test-library-url/view', self.browser.url, 'Current URL should be default view for newly created library') library = self.portal.portal_catalog.searchResults(portal_type=CONTENT_TYPE_LIBRARY, id='test-library-url') library = library[0] self.assertEqual(library.Title, 'New Test Library') def tearDown(self): """ :return: """ error_log = getToolByName(self.portal, 'error_log') if len(error_log.getLogEntries()): print error_log.getLogEntries()[-1]['tb_text'] super(TestLibraryBrowser, self).tearDown()
def XtestNoKey(self): browser = Browser(self.layer["app"]) browser.open("%s/reset-password" % self.layer["portal"].absolute_url()) browser.getForm().submit()
class AutoCSRFProtectTests(unittest.TestCase): layer = PROTECT_FUNCTIONAL_TESTING def setUp(self): self.portal = self.layer['portal'] self.browser = Browser(self.layer['app']) self.request = self.layer['request'] login(self.portal, TEST_USER_NAME) self.open('login_form') self.browser.getControl(name='__ac_name').value = TEST_USER_NAME self.browser.getControl( name='__ac_password').value = TEST_USER_PASSWORD self.browser.getControl(name='submit').click() def open(self, path): self.browser.open(self.portal.absolute_url() + '/' + path) def test_adds_csrf_protection_input(self): self.open('test-unprotected') self.assertTrue('name="_authenticator"' in self.browser.contents) def test_adds_csrf_protection_for_scheme_relative_same_domain(self): self.open('test-unprotected') form = self.browser.getForm('five') form.getControl(name="_authenticator") def test_adds_csrf_protection_for_relative_path(self): self.open('test-unprotected') form = self.browser.getForm('seven') form.getControl(name="_authenticator") def test_adds_csrf_protection_for_no_action(self): self.open('test-unprotected') form = self.browser.getForm('one') form.getControl(name="_authenticator") def test_does_not_add_csrf_protection_to_different_domain(self): self.open('test-unprotected') form = self.browser.getForm('six') try: form.getControl(name="_authenticator") self.assertEqual('should not add authenticator', '') except: pass def test_does_not_add_csrf_protection_to_different_domain_scheme_relative( self): self.open('test-unprotected') form = self.browser.getForm('four') try: form.getControl(name="_authenticator") self.assertEqual('should not add authenticator', '') except: pass def test_authentication_works_automatically(self): self.open('test-unprotected') self.browser.getControl('submit1').click() self.assertEqual(self.portal.foo, "bar") def test_authentication_works_for_other_form(self): self.open('test-unprotected') self.browser.getControl('submit2').click() self.assertEqual(self.portal.foo, "bar") def test_works_for_get_form_yet(self): self.open('test-unprotected') self.browser.getControl('submit3').click() def test_forbidden_raised_if_auth_failure(self): self.open('test-unprotected') self.browser.getForm('one').\ getControl(name="_authenticator").value = 'foobar' # XXX: plone.transformchain don't reraise exceptions # try: # self.browser.getControl('submit1').click() # except Exception, ex: # self.assertEquals(ex.getcode(), 403) # import pdb; pdb.set_trace() self.browser.getControl('submit1').click() self.assertFalse(hasattr(self.portal, "foo")) def test_forbidden_raised_if_auth_failure_with_savepoint(self): self.open('test-unprotected') self.browser.getForm('one').\ getControl(name="_authenticator").value = 'foobar' self.browser.getForm('one').\ getControl(name="savepoint").value = 'true' self.browser.getControl('submit1').click() self.assertFalse(hasattr(self.portal, "foo")) def test_CSRF_header(self): self.request.environ['HTTP_X_CSRF_TOKEN'] = createToken() view = AuthenticatorView(None, self.request) self.assertEqual(view.verify(), True) def test_incorrect_CSRF_header(self): self.request.environ['HTTP_X_CSRF_TOKEN'] = 'foobar' view = AuthenticatorView(None, self.request) self.assertEqual(view.verify(), False) def test_only_add_auth_when_user_logged_in(self): logout() self.open('logout') self.open('test-unprotected') try: self.browser.getForm('one').getControl(name="_authenticator") self.assertEqual('anonymous should not be protected', '') except LookupError: pass
class TestBookLoanBrowser(unittest.TestCase, CollectiveDataTableBrowserMixin): """ """ layer = COLLECTIVE_DATATABLE_FUNCTIONAL_TESTING def setUp(self): """ :return: """ self.school = None self.student = None self.library = None self.book = None self.portal = self.layer['portal'] setRoles(self.portal, TEST_USER_ID, ['Manager', ]) self.installer = api.portal.get_tool('portal_quickinstaller') init_fixture(self, True) self.browser = Browser(self.layer['app']) self._book_structure() def _book_structure(self): """ :return: """ _resource_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resources') _id = safe_unicode('book') _title = safe_unicode('Test First Book') _description = safe_unicode('The test description') _details = safe_unicode('<h1>Test Book Details</h1>') _isbn = safe_unicode('ISBN 978-0-306-40615-7') _author = safe_unicode('Test Author') _publisher = safe_unicode('Test Publisher') _number_of_copy = safe_unicode('2') _cover_photo = 'book.jpg' _url = self.library.absolute_url() + '/++add++' + CONTENT_TYPE_BOOK self.browser.open(_url) try: form = self.browser.getForm(id='form') except LookupError as exc: if not self.browser.cookies.get('__ac', None): self.browser_login() form = self.browser.getForm(id='form') else: raise LookupError(exc.message) # Fill the form form.getControl(name='form.widgets.title').value = _title form.getControl(name='form.widgets.description').value = _description form.getControl(name='form.widgets.isbn').value = _isbn form.getControl(name='form.widgets.details').value = _details form.getControl(name='form.widgets.publisher').value = _publisher form.getControl(name='form.widgets.author').value = _author form.getControl(name='form.widgets.number_of_copy').value = _number_of_copy form.getControl(name='form.widgets.IShortName.id').value = _id form.getControl(name='form.widgets.IExcludeFromNavigation.exclude_from_nav:list').value = 1 form.getControl(name='form.widgets.INextPreviousToggle.nextPreviousEnabled:list').value = 1 image_control = form.getControl(name='form.widgets.cover_photo') image_control.add_file(open(os.path.join(_resource_path, _cover_photo), 'rb'), 'image/jpeg', _cover_photo) form.submit(form.getControl(name='form.buttons.save').value) book = self.portal.portal_catalog.searchResults(portal_type=CONTENT_TYPE_BOOK, id=_id)[0] self.book = book.getObject() def test_adding_by_browser(self): """ :return: """ _id = self.book.generateUniqueId(CONTENT_TYPE_BOOK_LOAN).replace('.', '-') _url = self.book.absolute_url() + '/++add++' + CONTENT_TYPE_BOOK_LOAN self.browser.open(_url) try: form = self.browser.getForm(id='form') except LookupError as exc: if not self.browser.cookies.get('__ac', None): self.browser_login() form = self.browser.getForm(id='form') else: raise LookupError(exc.message) # Fill the form form.getControl(name='form.widgets.book').value = self.book.UID() form.getControl(name='form.widgets.student').value = self.student.UID() form.getControl(name='form.widgets.loan_duration:list').value = ['2'] form.getControl(name='form.widgets.IShortName.id').value = _id form.getControl(name='form.widgets.IExcludeFromNavigation.exclude_from_nav:list').value = 1 form.getControl(name='form.widgets.INextPreviousToggle.nextPreviousEnabled:list').value = 1 form.submit(form.getControl(name='form.buttons.save').value) self.assertEqual(self.book.absolute_url() + '/' + _id + '/view', self.browser.url, 'Current URL should be default view for newly created loan') loan = self.portal.portal_catalog.searchResults(portal_type=CONTENT_TYPE_BOOK_LOAN, id=_id) loan = loan[0] self.assertEqual(loan.getObject().student.to_object, self.student) self.assertEqual(loan.getObject().book.to_object, self.book) # Make sure events fired self.assertFalse(loan.getObject().is_lock) self.assertEqual(self.book.number_of_loan_copy, 1) book = self.portal.portal_catalog.searchResults(portal_type=CONTENT_TYPE_BOOK, id=self.book.getId())[0] # Book stock should be decreased self.assertEqual(book.book_stock, 1) self.assertEqual(book.getObject().number_of_copy, 2) def test_book_stock_validator(self): """ :return: """ self.book.number_of_loan_copy += 2 self.book.reindexObject() transaction.commit() _id = self.book.generateUniqueId(CONTENT_TYPE_BOOK_LOAN).replace('.', '-') _url = self.book.absolute_url() + '/++add++' + CONTENT_TYPE_BOOK_LOAN self.browser.open(_url) try: form = self.browser.getForm(id='form') except LookupError as exc: if not self.browser.cookies.get('__ac', None): self.browser_login() form = self.browser.getForm(id='form') else: raise LookupError(exc.message) # Fill the form form.getControl(name='form.widgets.book').value = self.book.UID() form.getControl(name='form.widgets.student').value = self.student.UID() form.getControl(name='form.widgets.loan_duration:list').value = ['2'] form.getControl(name='form.widgets.IShortName.id').value = _id form.getControl(name='form.widgets.IExcludeFromNavigation.exclude_from_nav:list').value = 1 form.getControl(name='form.widgets.INextPreviousToggle.nextPreviousEnabled:list').value = 1 form.submit(form.getControl(name='form.buttons.save').value) self.assertNotEqual( self.book.absolute_url() + '/' + _id + '/view', self.browser.url, 'Current URL should not be default view, because of validation error.') html_output = BeautifulSoup(self.browser.contents.strip('\n'), 'lxml') portal_message = html_output.find('dl', class_='portalMessage') error = portal_message.find('dt') # We make sure error message shown. self.assertIsNotNone(error) self.assertTrue(0 < len(error.text)) def tearDown(self): """ :return: """ error_log = getToolByName(self.portal, 'error_log') if len(error_log.getLogEntries()): print error_log.getLogEntries()[-1]['tb_text'] super(TestBookLoanBrowser, self).tearDown()
class UserGroupsControlPanelFunctionalTest(unittest.TestCase): """Test that changes in the user groups control panel are actually creating and changing users and groups. """ layer = PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING def _generateGroups(self): groupsTool = getToolByName(self.portal, 'portal_groups') self.groups = [ {'id': 'group1', 'title': "Group 1"}, {'id': 'group2', 'title': "Group 2"}, {'id': 'group3', 'title': "Group 3 accentué"} ] for group in self.groups: groupsTool.addGroup(group['id'], [], [], title=group['title']) def _generateUsers(self): self.members = [ {'username': '******', 'fullname': 'Kevin Hughes', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Richard Ramirez', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Kyle Brown', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Julian Green', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Makayla Coleman', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Sean Foster', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Molly Martin', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Jordan Thompson', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Tyler Rivera', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Megan Murphy', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Gracie Diaz', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Rachel Morgan', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Maya Price', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Blake Jenkins', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Owen Ramirez', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Owen Cook', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Jayden Hill', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Joseph Ramirez', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Nathan Young', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Kaitlyn Hernandez', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Faith Price', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Sofia Williams', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'David Sanders', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Jack Simmons', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Cole Howard', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Rachel Miller', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Henry Patterson', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Avery Cooper', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Sydney Bennett', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Daniel Johnson', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Autumn Brooks', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Alexandra Nelson', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Brian Simmons', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Kevin Hughes', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Sydney Evans', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Emma Brown', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Lauren Martin', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Isabelle Russell', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Anna Baker', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Brady Watson', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Kaitlyn Robinson', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Riley Richardson', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Kayla Sanders', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Sara Richardson', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Trinity Gonzales', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Madeline Garcia', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Brian Gray', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Victoria Perez', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Charles Rodriguez', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Abigail Simmons', 'email': '*****@*****.**'}, {'username': '******', 'fullname': 'Émilie Richard', 'email': '*****@*****.**'}, ] rtool = getToolByName(self.portal, 'portal_registration') for member in self.members: rtool.addMember(member['username'], 'somepassword', properties=member) def setUp(self): self.app = self.layer['app'] self.portal = self.layer['portal'] self.portal_url = self.portal.absolute_url() self.usergroups_url = "%s/@@usergroup-userprefs" % self.portal_url self.groups_url = "%s/@@usergroup-groupprefs" % self.portal_url self._generateGroups() self._generateUsers() transaction.commit() self.browser = Browser(self.app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) ) def test_usergroups_control_panel_link(self): self.browser.open( "%s/@@overview-controlpanel" % self.portal_url) self.browser.getLink('Users and Groups').click() self.assertEqual( self.browser.url, self.usergroups_url ) def test_usergroups_groups_link(self): self.browser.open(self.usergroups_url) self.browser.getLink('Groups', index=0).click() self.assertEqual( self.browser.url, "%s/@@usergroup-groupprefs" % self.portal_url ) def test_usergroups_settings_link(self): self.browser.open(self.usergroups_url) self.browser.getLink('Settings').click() self.assertEqual( self.browser.url, "%s/@@usergroup-controlpanel" % self.portal_url ) def test_usergroups_memberfields_link(self): self.browser.open(self.usergroups_url) self.browser.getLink('Member fields').click() self.assertEqual( self.browser.url, "%s/@@member-fields" % self.portal_url ) def test_user_search_by_name(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'Richard' self.browser.getControl(name='form.button.Search').click() self.assertIn('Richard Ramirez', self.browser.contents) self.assertIn('Sara Richardson', self.browser.contents) self.assertIn('Émilie Richard', self.browser.contents) def test_user_search_by_name_accent(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'Émilie' self.browser.getControl(name='form.button.Search').click() self.assertIn('Émilie Richard', self.browser.contents) def test_user_search_by_id(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'TWrMCLIo' self.browser.getControl(name='form.button.Search').click() self.assertIn('Autumn Brooks', self.browser.contents) def test_user_search_by_mail(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'DohPmgIa@' self.browser.getControl(name='form.button.Search').click() self.assertIn('Gracie Diaz', self.browser.contents) def test_user_show_all(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='form.button.FindAll').click() # Check that first 10 members (sorted by fullname) are shown. for member in sorted( self.members, key=lambda k: normalizeString(k['fullname']) )[:10]: self.assertIn(member['fullname'], self.browser.contents) def test_user_show_all_with_search_term(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'no-user' self.browser.getControl(name='form.button.FindAll').click() # Check that all members is shown and search term is ignored self.assertIn('Avery Cooper', self.browser.contents) def test_user_add_new_link(self): self.browser.open(self.usergroups_url) self.browser.getLink(id='add-user').click() self.assertEqual( self.browser.url, "%s/@@new-user" % self.portal_url ) def test_user_modify_roles(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'TWrMCLIo' self.browser.getControl(name='form.button.Search').click() # Check that contributor role is not enabled and enable it self.assertFalse(self.browser.getControl( name='users.roles:list:records' ).getControl(value='Contributor').selected) self.browser.getControl( name='users.roles:list:records' ).getControl(value='Contributor').selected = True self.browser.getControl(name='form.button.Modify').click() # Check that contributor role is now enabled for this user self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'TWrMCLIo' self.browser.getControl(name='form.button.Search').click() self.assertTrue(self.browser.getControl( name='users.roles:list:records' ).getControl(value='Contributor').selected) def test_user_delete(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'TWrMCLIo' self.browser.getControl(name='form.button.Search').click() self.assertIn('Autumn Brooks', self.browser.contents) # Delete user self.browser.getControl(name='delete:list').getControl( value='TWrMCLIo').selected = True self.browser.getControl(name='form.button.Modify').click() # Check that user does not exist anymore self.browser.getControl(name='searchstring').value = 'TWrMCLIo' self.browser.getControl(name='form.button.Search').click() self.assertNotIn('Autumn Brooks', self.browser.contents) def test_groups_search_by_id(self): self.browser.open(self.groups_url) self.browser.getControl(name='searchstring').value = 'group1' self.browser.getControl(name='form.button.Search').click() self.assertIn('Group 1', self.browser.contents) def test_groups_search_by_name(self): self.browser.open(self.groups_url) self.browser.getControl(name='searchstring').value = 'Group 3 accentué' self.browser.getControl(name='form.button.Search').click() self.assertIn('Group 3 accentué', self.browser.contents) def test_groups_modify_roles(self): self.browser.open(self.groups_url) self.browser.getControl(name='searchstring').value = 'group1' # Check that role is not selected yet and then select it and apply it. form = self.browser.getForm(id='groups_search') ctrl = form._form.get('group_group1:list', index=1) self.assertEqual(ctrl._value, 'Site Administrator') self.assertFalse(ctrl.checked) ctrl.checked = True self.browser.getControl('Save').click() # Check that role is now selected form = self.browser.getForm(id='groups_search') ctrl = form._form.get('group_group1:list', index=1) self.assertEqual(ctrl._value, 'Site Administrator') self.assertTrue(ctrl.checked) def test_groups_delete_group(self): self.browser.open(self.groups_url) self.browser.getControl(name='searchstring').value = 'group1' # Delete a group self.browser.getControl( name='delete:list' ).getControl(value='group1').selected = True self.browser.getControl(name='form.button.Modify').click() # Check that group doesn't exist anymore self.browser.getControl(name='searchstring').value = 'group1' self.assertNotIn('Group 1', self.browser.contents) def test_groups_show_all(self): self.browser.open(self.groups_url) self.browser.getControl(name='form.button.FindAll').click() for group in self.groups: self.assertIn(group['title'], self.browser.contents) def test_group_add_users(self): self.browser.open(self.groups_url) self.browser.getLink('Group 1 (group1)').click() self.assertIn( 'There is no group or user attached to this group.', self.browser.contents ) # Add user (Autumn Brooks) to selected group (Group 1) self.browser.getControl(name='searchstring').value = 'TWrMCLIo' self.browser.getControl(name='form.button.Search').click() self.browser.getControl(name='add:list').getControl( value='TWrMCLIo').selected = True # Check that user is now part of the group self.browser.getControl( 'Add selected groups and users to this group').click() self.assertIn('Autumn Brooks', self.browser.contents) def test_group_add_group(self): self.browser.open(self.groups_url) self.browser.getLink('Group 1 (group1)').click() self.assertIn( 'There is no group or user attached to this group.', self.browser.contents ) # Add group2 to selected group 1 self.browser.getControl(name='searchstring').value = 'group2' self.browser.getControl(name='form.button.Search').click() self.browser.getControl(name='add:list').getControl( value='group2').selected = True # Check that group is now part of the group self.browser.getControl( 'Add selected groups and users to this group').click() self.assertIn('Group 2', self.browser.contents) def test_usergroups_settings_many_users(self): self.browser.open("%s/@@usergroup-controlpanel" % self.portal_url) self.browser.getControl( name='form.widgets.many_users:list' ).controls[0].selected = True self.browser.getControl('Save').click() # Check that show all button for users is no longer available self.browser.open(self.usergroups_url) self.assertNotIn('Show all', self.browser.contents) # Check that empty search does not trigger show all self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = '' def test_usergroups_settings_many_groups(self): self.browser.open("%s/@@usergroup-controlpanel" % self.portal_url) self.browser.getControl( name='form.widgets.many_groups:list' ).controls[0].selected = True self.browser.getControl('Save').click() # Check that show all button for groups is no longer available self.browser.open(self.groups_url) self.assertNotIn('Show all', self.browser.contents) self.assertNotIn('DIispfuF', self.browser.contents)
class TypesControlPanelFunctionalTest(unittest.TestCase): """Test that changes in the types control panel are actually stored in the registry. """ layer = PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING def setUp(self): self.app = self.layer['app'] self.portal = self.layer['portal'] self.portal_url = self.portal.absolute_url() self.types_url = "%s/@@content-controlpanel" % self.portal_url self.browser = Browser(self.app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % ( SITE_OWNER_NAME, SITE_OWNER_PASSWORD, )) def test_types_control_panel_link(self): self.browser.open("%s/@@overview-controlpanel" % self.portal_url) self.browser.getLink('Editing').click() def test_standard_type_select(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.assertIn('content-controlpanel', self.browser.url) def test_standard_type_cancel(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getControl('Cancel').click() self.assertIn('@@overview-controlpanel', self.browser.url) def test_standard_type_allow_commenting(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.browser.getControl('Allow comments').selected = True self.browser.getControl('Save').click() # Check if settings got saved correctly self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.assertIn('Globally addable', self.browser.contents) self.assertIn('Allow comments', self.browser.contents) self.assertEquals( self.browser.getControl('Allow comments').selected, True) self.assertIn('Visible in searches', self.browser.contents) self.assertIn( '<input id="redirect_links" type="checkbox" class="noborder"' ' name="redirect_links:boolean" checked="checked" />', self.browser.contents) self.assertIn( '<label for="redirect_links">Redirect immediately to link target', self.browser.contents) def test_standard_types_redirect_links(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.browser.getControl( 'Redirect immediately to link target').selected = True self.browser.getControl('Save').click() # Check if settings got saved correctly self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.assertTrue( 'Redirect immediately to link target' in self.browser.contents) self.assertEquals( self.browser.getControl( 'Redirect immediately to link target').selected, True) def test_set_no_default_workflow(self): # references http://dev.plone.org/plone/ticket/11901 self.browser.open(self.types_url) self.browser.getControl(name="new_workflow").value = ['[none]'] self.browser.getControl(name="form.button.Save").click() # Check that setting No workflow as default workflow doesn't break # break editing types self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Link'] self.browser.getForm(action=self.types_url).submit() self.assertIn('Globally addable', self.browser.contents) self.assertIn('Allow comments', self.browser.contents) self.assertIn('Visible in searches', self.browser.contents) def test_disable_versioning_removes_behavior(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Document'] self.browser.getForm(action=self.types_url).submit() self.browser.getControl(name='versionpolicy').value = ['off'] self.browser.getForm(action=self.types_url).submit() portal_types = self.portal.portal_types doc_type = portal_types.Document self.assertTrue('plone.app.versioningbehavior.behaviors.IVersionable' not in doc_type.behaviors) # noqa def test_enable_versioning_behavior(self): self.browser.open(self.types_url) self.browser.getControl(name='type_id').value = ['Document'] self.browser.getForm(action=self.types_url).submit() self.browser.getControl(name='versionpolicy').value = ['off'] self.browser.getForm(action=self.types_url).submit() portal_types = self.portal.portal_types doc_type = portal_types.Document self.assertTrue('plone.app.versioningbehavior.behaviors.IVersionable' not in doc_type.behaviors) # noqa self.browser.getControl(name='versionpolicy').value = ['manual'] self.browser.getForm(action=self.types_url).submit() self.assertTrue('plone.app.versioningbehavior.behaviors.IVersionable' in doc_type.behaviors)
class UserGroupsControlPanelFunctionalTest(unittest.TestCase): """Test that changes in the user groups control panel are actually creating and changing users and groups. """ layer = PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING def _generateGroups(self): groupsTool = getToolByName(self.portal, 'portal_groups') self.groups = [{ 'id': 'group1', 'title': "Group 1" }, { 'id': 'group2', 'title': "Group 2" }, { 'id': 'group3', 'title': "Group 3 accentué" }] for group in self.groups: groupsTool.addGroup(group['id'], [], [], title=group['title']) def _generateUsers(self): self.members = [ { 'username': '******', 'fullname': 'Kevin Hughes', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Richard Ramirez', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Kyle Brown', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Julian Green', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Makayla Coleman', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Sean Foster', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Molly Martin', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Jordan Thompson', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Tyler Rivera', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Megan Murphy', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Gracie Diaz', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Rachel Morgan', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Maya Price', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Blake Jenkins', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Owen Ramirez', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Owen Cook', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Jayden Hill', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Joseph Ramirez', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Nathan Young', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Kaitlyn Hernandez', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Faith Price', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Sofia Williams', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'David Sanders', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Jack Simmons', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Cole Howard', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Rachel Miller', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Henry Patterson', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Avery Cooper', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Sydney Bennett', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Daniel Johnson', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Autumn Brooks', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Alexandra Nelson', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Brian Simmons', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Kevin Hughes', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Sydney Evans', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Emma Brown', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Lauren Martin', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Isabelle Russell', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Anna Baker', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Brady Watson', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Kaitlyn Robinson', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Riley Richardson', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Kayla Sanders', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Sara Richardson', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Trinity Gonzales', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Madeline Garcia', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Brian Gray', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Victoria Perez', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Charles Rodriguez', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Abigail Simmons', 'email': '*****@*****.**' }, { 'username': '******', 'fullname': 'Émilie Richard', 'email': '*****@*****.**' }, ] rtool = getToolByName(self.portal, 'portal_registration') for member in self.members: rtool.addMember(member['username'], 'somepassword', properties=member) def setUp(self): self.app = self.layer['app'] self.portal = self.layer['portal'] self.portal_url = self.portal.absolute_url() self.usergroups_url = "%s/@@usergroup-userprefs" % self.portal_url self.groups_url = "%s/@@usergroup-groupprefs" % self.portal_url self._generateGroups() self._generateUsers() transaction.commit() self.browser = Browser(self.app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % ( SITE_OWNER_NAME, SITE_OWNER_PASSWORD, )) def test_usergroups_control_panel_link(self): self.browser.open("%s/@@overview-controlpanel" % self.portal_url) self.browser.getLink('Users and Groups').click() self.assertEqual(self.browser.url, self.usergroups_url) def test_usergroups_groups_link(self): self.browser.open(self.usergroups_url) self.browser.getLink('Groups', index=0).click() self.assertEqual(self.browser.url, "%s/@@usergroup-groupprefs" % self.portal_url) def test_usergroups_settings_link(self): self.browser.open(self.usergroups_url) self.browser.getLink('Settings').click() self.assertEqual(self.browser.url, "%s/@@usergroup-controlpanel" % self.portal_url) def test_usergroups_memberfields_link(self): self.browser.open(self.usergroups_url) self.browser.getLink('Member fields').click() self.assertEqual(self.browser.url, "%s/@@member-fields" % self.portal_url) def test_user_search_by_name(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'Richard' self.browser.getControl(name='form.button.Search').click() self.assertIn('Richard Ramirez', self.browser.contents) self.assertIn('Sara Richardson', self.browser.contents) self.assertIn('Émilie Richard', self.browser.contents) def test_user_search_by_name_accent(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'Émilie' self.browser.getControl(name='form.button.Search').click() self.assertIn('Émilie Richard', self.browser.contents) def test_user_search_by_id(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'TWrMCLIo' self.browser.getControl(name='form.button.Search').click() self.assertIn('Autumn Brooks', self.browser.contents) def test_user_search_by_mail(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'DohPmgIa@' self.browser.getControl(name='form.button.Search').click() self.assertIn('Gracie Diaz', self.browser.contents) def test_user_show_all(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='form.button.FindAll').click() # Check that first 10 members (sorted by fullname) are shown. for member in sorted( self.members, key=lambda k: normalizeString(k['fullname']))[:10]: self.assertIn(member['fullname'], self.browser.contents) def test_user_show_all_with_search_term(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'no-user' self.browser.getControl(name='form.button.FindAll').click() # Check that all members is shown and search term is ignored self.assertIn('Avery Cooper', self.browser.contents) def test_user_add_new_link(self): self.browser.open(self.usergroups_url) self.browser.getLink(id='add-user').click() self.assertEqual(self.browser.url, "%s/@@new-user" % self.portal_url) def test_user_modify_roles(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'TWrMCLIo' self.browser.getControl(name='form.button.Search').click() # Check that contributor role is not enabled and enable it self.assertFalse( self.browser.getControl( name='users.roles:list:records').getControl( value='Contributor').selected) self.browser.getControl(name='users.roles:list:records').getControl( value='Contributor').selected = True self.browser.getControl(name='form.button.Modify').click() # Check that contributor role is now enabled for this user self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'TWrMCLIo' self.browser.getControl(name='form.button.Search').click() self.assertTrue( self.browser.getControl( name='users.roles:list:records').getControl( value='Contributor').selected) def test_user_delete(self): self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = 'TWrMCLIo' self.browser.getControl(name='form.button.Search').click() self.assertIn('Autumn Brooks', self.browser.contents) # Delete user self.browser.getControl(name='delete:list').getControl( value='TWrMCLIo').selected = True self.browser.getControl(name='form.button.Modify').click() # Check that user does not exist anymore self.browser.getControl(name='searchstring').value = 'TWrMCLIo' self.browser.getControl(name='form.button.Search').click() self.assertNotIn('Autumn Brooks', self.browser.contents) def test_groups_search_by_id(self): self.browser.open(self.groups_url) self.browser.getControl(name='searchstring').value = 'group1' self.browser.getControl(name='form.button.Search').click() self.assertIn('Group 1', self.browser.contents) def test_groups_search_by_name(self): self.browser.open(self.groups_url) self.browser.getControl(name='searchstring').value = 'Group 3 accentué' self.browser.getControl(name='form.button.Search').click() self.assertIn('Group 3 accentué', self.browser.contents) def test_groups_modify_roles(self): self.browser.open(self.groups_url) self.browser.getControl(name='searchstring').value = 'group1' # Check that role is not selected yet and then select it and apply it. form = self.browser.getForm(id='groups_search') ctrl = form._form.get('group_group1:list', index=1) self.assertEqual(ctrl._value, 'Site Administrator') self.assertFalse(ctrl.checked) ctrl.checked = True self.browser.getControl('Save').click() # Check that role is now selected form = self.browser.getForm(id='groups_search') ctrl = form._form.get('group_group1:list', index=1) self.assertEqual(ctrl._value, 'Site Administrator') self.assertTrue(ctrl.checked) def test_groups_delete_group(self): self.browser.open(self.groups_url) self.browser.getControl(name='searchstring').value = 'group1' # Delete a group self.browser.getControl(name='delete:list').getControl( value='group1').selected = True self.browser.getControl(name='form.button.Modify').click() # Check that group doesn't exist anymore self.browser.getControl(name='searchstring').value = 'group1' self.assertNotIn('Group 1', self.browser.contents) def test_groups_show_all(self): self.browser.open(self.groups_url) self.browser.getControl(name='form.button.FindAll').click() for group in self.groups: self.assertIn(group['title'], self.browser.contents) def test_group_add_users(self): self.browser.open(self.groups_url) self.browser.getLink('Group 1 (group1)').click() self.assertIn('There is no group or user attached to this group.', self.browser.contents) # Add user (Autumn Brooks) to selected group (Group 1) self.browser.getControl(name='searchstring').value = 'TWrMCLIo' self.browser.getControl(name='form.button.Search').click() self.browser.getControl(name='add:list').getControl( value='TWrMCLIo').selected = True # Check that user is now part of the group self.browser.getControl( 'Add selected groups and users to this group').click() self.assertIn('Autumn Brooks', self.browser.contents) def test_group_add_group(self): self.browser.open(self.groups_url) self.browser.getLink('Group 1 (group1)').click() self.assertIn('There is no group or user attached to this group.', self.browser.contents) # Add group2 to selected group 1 self.browser.getControl(name='searchstring').value = 'group2' self.browser.getControl(name='form.button.Search').click() self.browser.getControl(name='add:list').getControl( value='group2').selected = True # Check that group is now part of the group self.browser.getControl( 'Add selected groups and users to this group').click() self.assertIn('Group 2', self.browser.contents) def test_usergroups_settings_many_users(self): self.browser.open("%s/@@usergroup-controlpanel" % self.portal_url) self.browser.getControl( name='form.widgets.many_users:list').controls[0].selected = True self.browser.getControl('Save').click() # Check that show all button for users is no longer available self.browser.open(self.usergroups_url) self.assertNotIn('Show all', self.browser.contents) # Check that empty search does not trigger show all self.browser.open(self.usergroups_url) self.browser.getControl(name='searchstring').value = '' def test_usergroups_settings_many_groups(self): self.browser.open("%s/@@usergroup-controlpanel" % self.portal_url) self.browser.getControl( name='form.widgets.many_groups:list').controls[0].selected = True self.browser.getControl('Save').click() # Check that show all button for groups is no longer available self.browser.open(self.groups_url) self.assertNotIn('Show all', self.browser.contents) self.assertNotIn('DIispfuF', self.browser.contents)
class LanguageControlPanelFunctionalTest(unittest.TestCase): """Test that changes in the language control panel are actually stored in the registry. """ layer = PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING def setUp(self): self.app = self.layer['app'] self.portal = self.layer['portal'] self.portal_url = self.portal.absolute_url() self.browser = Browser(self.app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) ) def _inject_available_languages_field(self, value): """The in-and-out widget does not work without javascript, therefore we have to inject some values in order to make saving the form work. """ form = self.browser.getForm(id='LanguageControlPanel') form.mech_form.new_control( type='hidden', name='form.widgets.available_languages:list', attrs=dict(value=value) ) self.browser.getControl('Save').click() def test_language_control_panel_link(self): self.browser.open( "%s/plone_control_panel" % self.portal_url) self.browser.getLink('Language').click() self.assertTrue("Language Settings" in self.browser.contents) def test_language_control_panel_backlink(self): self.browser.open( "%s/@@language-controlpanel" % self.portal_url) self.assertTrue("Plone Configuration" in self.browser.contents) def test_language_control_panel_sidebar(self): self.browser.open( "%s/@@language-controlpanel" % self.portal_url) self.browser.getLink('Site Setup').click() self.assertEqual( self.browser.url, 'http://nohost/plone/@@overview-controlpanel') def test_language_controlpanel_view(self): view = getMultiAdapter((self.portal, self.portal.REQUEST), name="language-controlpanel") view = view.__of__(self.portal) self.assertTrue(view()) def test_default_language(self): registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open( "%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.default_language, 'en') self.assertEqual( self.browser.getControl( 'Site language' ).value, ['en'] ) self.browser.getControl( 'Site language' ).value = ['de'] self._inject_available_languages_field('en') self._inject_available_languages_field('de') self.browser.getControl(name='form.buttons.save').click() self.assertEqual(settings.default_language, 'de') # def test_available_languages(self): # registry = getUtility(IRegistry) # settings = registry.forInterface(ILanguageSchema, prefix='plone') # self.browser.open( # "%s/@@language-controlpanel" % self.portal_url) # self.assertEqual(settings.available_languages, ['en']) # self.assertEqual( # self.browser.getControl( # name='form.widgets.available_languages.to' # ).options, # ['en'] # ) # control = self.browser.getForm(index=1) # self.in_out_select( # control, 'form.widgets.available_languages:list', 'Deutsch') # self.browser.getControl('Save').click() # self.assertEqual(settings.available_languages, ['en', 'de']) def test_use_combined_language_codes(self): registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open( "%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_combined_language_codes, False) self.assertEqual( self.browser.getControl( 'Show country-specific language variants' ).selected, False ) self.browser.getControl( 'Show country-specific language variants' ).selected = True self._inject_available_languages_field('en') self.browser.getControl('Save').click() self.assertEqual(settings.use_combined_language_codes, True) def test_display_flags(self): registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open( "%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.display_flags, False) self.assertEqual( self.browser.getControl( 'Show language flags' ).selected, False ) self.browser.getControl( 'Show language flags' ).selected = True self._inject_available_languages_field('en') self.browser.getControl('Save').click() self.assertEqual(settings.display_flags, True) def test_use_content_negotiation(self): registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open( "%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_content_negotiation, False) self.assertEqual( self.browser.getControl( 'Use the language of the content item' ).selected, False ) self.browser.getControl( 'Use the language of the content item' ).selected = True self._inject_available_languages_field('en') self.browser.getControl('Save').click() self.assertEqual(settings.use_content_negotiation, True) def test_use_path_negotiation(self): registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open( "%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_path_negotiation, False) self.assertEqual( self.browser.getControl( 'Use language codes in URL path for manual override' ).selected, False ) self.browser.getControl( 'Use language codes in URL path for manual override' ).selected = True self._inject_available_languages_field('en') self.browser.getControl('Save').click() self.assertEqual(settings.use_path_negotiation, True) def test_use_cookie_negotiation(self): registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open( "%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_cookie_negotiation, False) self.assertEqual( self.browser.getControl( 'Use cookie for manual override' ).selected, False ) self.browser.getControl( 'Use cookie for manual override' ).selected = True self._inject_available_languages_field('en') self.browser.getControl('Save').click() self.assertEqual(settings.use_cookie_negotiation, True) def test_authenticated_users_only(self): control_label = "Authenticated users only" registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open( "%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.authenticated_users_only, False) self.assertEqual( self.browser.getControl(control_label).selected, False ) self.browser.getControl(control_label).selected = True self._inject_available_languages_field('en') self.browser.getControl('Save').click() self.assertEqual(settings.authenticated_users_only, True) def test_set_cookie_always(self): control_label = "Set the language cookie always" registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open( "%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.set_cookie_always, False) self.assertEqual( self.browser.getControl(control_label).selected, False ) self.browser.getControl(control_label).selected = True # The in-and-out widget does not work without javascript, therefore # we have to inject some values in order to make saving the form work. form = self.browser.getForm(id='LanguageControlPanel') form.mech_form.new_control( type='hidden', name='form.widgets.available_languages:list', attrs=dict(value='en') ) self.browser.getControl('Save').click() self.assertEqual(settings.set_cookie_always, True) def test_use_subdomain_negotiation(self): control_label = "Use subdomain" registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open( "%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_subdomain_negotiation, False) self.assertEqual( self.browser.getControl(control_label).selected, False ) self.browser.getControl(control_label).selected = True # The in-and-out widget does not work without javascript, therefore # we have to inject some values in order to make saving the form work. form = self.browser.getForm(id='LanguageControlPanel') form.mech_form.new_control( type='hidden', name='form.widgets.available_languages:list', attrs=dict(value='en') ) self.browser.getControl('Save').click() self.assertEqual(settings.use_subdomain_negotiation, True) def test_use_cctld_negotiation(self): control_label = "Use top-level domain" registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open( "%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_cctld_negotiation, False) self.assertEqual( self.browser.getControl(control_label).selected, False ) self.browser.getControl(control_label).selected = True # The in-and-out widget does not work without javascript, therefore # we have to inject some values in order to make saving the form work. form = self.browser.getForm(id='LanguageControlPanel') form.mech_form.new_control( type='hidden', name='form.widgets.available_languages:list', attrs=dict(value='en') ) self.browser.getControl('Save').click() self.assertEqual(settings.use_cctld_negotiation, True) def test_use_request_negotiation(self): control_label = "Use browser language request negotiation" registry = getUtility(IRegistry) settings = registry.forInterface(ILanguageSchema, prefix='plone') self.browser.open( "%s/@@language-controlpanel" % self.portal_url) self.assertEqual(settings.use_request_negotiation, False) self.assertEqual( self.browser.getControl(control_label).selected, False ) self.browser.getControl(control_label).selected = True # The in-and-out widget does not work without javascript, therefore # we have to inject some values in order to make saving the form work. form = self.browser.getForm(id='LanguageControlPanel') form.mech_form.new_control( type='hidden', name='form.widgets.available_languages:list', attrs=dict(value='en') ) self.browser.getControl('Save').click() self.assertEqual(settings.use_request_negotiation, True)
class TestSchoolBrowser(unittest.TestCase, CollectiveDataTableBrowserMixin): """ """ layer = COLLECTIVE_DATATABLE_FUNCTIONAL_TESTING def setUp(self): """ :return: """ self.portal = self.layer['portal'] setRoles(self.portal, TEST_USER_ID, ['Manager', ]) self.installer = api.portal.get_tool('portal_quickinstaller') self.browser = Browser(self.layer['app']) def test_adding_by_browser(self): """ :return: """ _resource_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resources') _url = self.portal.absolute_url() + '/++add++' + CONTENT_TYPE_SCHOOL self.browser.open(_url) try: form = self.browser.getForm(id='form') except LookupError as exc: if not self.browser.cookies.get('__ac', None): self.browser_login() form = self.browser.getForm(id='form') else: raise LookupError(exc.message) # Fill the form form.getControl(name='form.widgets.title').value = 'New Test School' form.getControl(name='form.widgets.description').value = "<b>Test description for this school</b>" form.getControl(name='form.widgets.IShortName.id').value = "test-school-url" form.getControl(name='form.widgets.IExcludeFromNavigation.exclude_from_nav:list').value = 1 form.getControl(name='form.widgets.INextPreviousToggle.nextPreviousEnabled:list').value = 1 image_control = form.getControl(name='form.widgets.feature_photo') image_control.add_file(open(os.path.join(_resource_path, 'school-building.png'), 'rb'), 'image/png', 'school-building.png') form.submit(form.getControl(name='form.buttons.save').value) self.assertEqual(self.portal.absolute_url() + '/test-school-url/view', self.browser.url, 'Current URL should be default view for newly created school') school = self.portal.portal_catalog.searchResults(portal_type=CONTENT_TYPE_SCHOOL, id='test-school-url') school = school[0] self.assertEqual(school.Title, 'New Test School') self.assertEqual(school.getObject().feature_photo.filename, 'school-building.png') def test_form_validation(self): """ :return: """ _url = self.portal.absolute_url() + '/++add++' + CONTENT_TYPE_SCHOOL self.browser.open(_url) try: form = self.browser.getForm(id='form') except LookupError as exc: if not self.browser.cookies.get('__ac', None): self.browser_login() form = self.browser.getForm(id='form') else: raise LookupError(exc.message) # Fill the form # form.getControl(name='form.widgets.title').value = 'New Test School' # form.getControl(name='form.widgets.description').value = "<b>Test description for this school</b>" form.getControl(name='form.widgets.title').value = '' form.getControl(name='form.widgets.description').value = '' form.submit(form.getControl(name='form.buttons.save').value) self.assertEqual(_url, self.browser.url, 'Current URL should be as school creation url') school = self.portal.portal_catalog.searchResults(portal_type=CONTENT_TYPE_SCHOOL) self.assertEqual(0, len(school)) form = self.browser.getForm(id='form') form.getControl(name='form.widgets.title').value = '' form.getControl(name='form.widgets.description').value = '<b>Test description for this school</b' form.submit(form.getControl(name='form.buttons.save').value) self.assertEqual(_url, self.browser.url, 'Current URL should be as school creation url') school = self.portal.portal_catalog.searchResults(portal_type=CONTENT_TYPE_SCHOOL) self.assertEqual(0, len(school)) def tearDown(self): """ :return: """ error_log = getToolByName(self.portal, 'error_log') if len(error_log.getLogEntries()): print error_log.getLogEntries()[-1]['tb_text'] super(TestSchoolBrowser, self).tearDown()