def statusmessage(): if not browser.css('#globalstatusmessage dl'): return None dl = browser.css('#globalstatusmessage dl').first return {'type': dl.classes[1], 'title': dl.terms[0], 'message': dl.definitions[0]}
def test_result_location_is_shown(self, browser): chapter = create(Builder('chapter') .titled('Chapter') .within(self.book)) subchapter = create(Builder('chapter') .titled('SubChapter') .within(chapter)) create(Builder('book textblock') .within(subchapter) .titled('The Block') .having(text=keywords_html('Foo'), showTitle=True)) browser.login().open(self.book, {'book_keywords': 'Foo'}, view='tabbedview_view-keywords/load') self.assertEquals(['The Book', '1 Chapter', '1.1 SubChapter'], browser.css('.result-location a').text) self.assertEquals( 'http://nohost/plone/the-book/@@book_reader_view', browser.css('.result-location a').first.attrib['href'])
def test_only_search_for_results_in_this_book(self, browser): # Regression: when having the same keyword in multiple books # the keyword tab was broken because of unspecific query (no path). first_book = create(Builder('book').titled('First Book')) first_chapter = create(Builder('chapter').titled('First chapter') .within(first_book)) create(Builder('book textblock').titled('First Block') .within(first_chapter) .having(text=keywords_html('Foo', 'Bar'))) second_book = create(Builder('book').titled('Second Book')) second_chapter = create(Builder('chapter').titled('Second chapter') .within(second_book)) create(Builder('book textblock').titled('Second Block') .within(second_chapter) .having(text=keywords_html('Bar', 'Baz'))) browser.login().visit(first_book, view='tabbedview_view-keywords') self.assertItemsEqual( ['Foo', 'Bar', ''], browser.css('select[name=book_keywords] option').text, 'Only keywords from the current book should be selectable.') browser.login().open(first_book, {'book_keywords': 'Bar'}, view='tabbedview_view-keywords/load') self.assertEquals(1, len(browser.css('.result')), 'Only results from the current book should be' ' found.')
def assert_edit_link(self, context, can_edit): browser.login().visit(context) if can_edit: self.assertTrue( browser.css('#service-navigation a.ModifyServiceNavigation'), 'Modify navigation form link should be available.') else: self.assertFalse( browser.css('#service-navigation a.ModifyServiceNavigation'), 'Modify navigation form link should NOT be available.')
def test_keywords_only_available_when_use_keywords_enabled(self, browser): tab_label = 'Keywords' browser.login().visit(self.book, view='tabbed_view') self.assertNotIn(tab_label, browser.css('.tabbedview-tabs a').text) self.book.setUse_index(True) transaction.commit() browser.login().visit(self.book, view='tabbed_view') self.assertIn(tab_label, browser.css('.tabbedview-tabs a').text)
def test_successfully_add_activity(self, member): create(Builder('ogds_user') .having(userid='hugo.boss')) browser.login('hugo.boss').open(self.dossier, view='++add++opengever.task.task') browser.fill({'Title': 'Test Task', 'Issuer': TEST_USER_ID, 'Responsible': 'inbox:client1', 'Task Type': 'comment'}) browser.css('#form-buttons-save').first.click() self.assertEquals([], warning_messages()) self.assertEquals(['Item created'], info_messages())
def test_successfully_add_activity(self, member): create(Builder('ogds_user').having(userid='hugo.boss')) browser.login('hugo.boss').open(self.dossier, view='++add++opengever.task.task') browser.fill({'Title': 'Test Task', 'Task Type': 'comment'}) form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill('inbox:org-unit-1') form.find_widget('Issuer').fill(TEST_USER_ID) browser.css('#form-buttons-save').first.click() self.assertEquals([], warning_messages()) self.assertEquals(['Item created'], info_messages())
def metadata(**kwargs): """Return the meeting metadata as lists of labels and values. """ return reduce( list.__add__, map(methodcaller('lists', **kwargs), browser.css('table.meeting-metadata')))
def test_role_description_is_not_displayed_when_missing(self, browser): page = create(Builder('page')) browser.login().visit(page, view='lawgiver-sharing-describe-role', data={'role': 'editor'}) self.assertFalse(browser.css('.role-description'), 'Did not expect that "editor" has a role description.')
def test_is_delegate_form(self, browser): task = create(Builder('task').in_state('task-state-in-progress')) self.do_transition(task) self.assert_action('http://nohost/plone/task-1/@@delegate_recipients') self.assertEquals('Delegate task', browser.css('.documentFirstHeading').first.text)
def test_add_watcher_adds_subscription_for_each_actor(self, member): browser.login().open(self.dossier, view='++add++opengever.task.task') browser.fill({'Title': 'Test Task', 'Responsible': 'inbox:client1', 'Task Type': 'comment'}) browser.css('#form-buttons-save').first.click() task = self.dossier.get('task-1') resource = notification_center().fetch_resource(task) subscriptions = resource.subscriptions self.assertItemsEqual( [(u'inbox:client1', u'task_responsible'), (u'test_user_1_', u'task_issuer')], [(sub.watcher.actorid, sub.role) for sub in subscriptions])
def assert_service_links(self, context): browser.login().visit(context) self.assertEquals(2, len(browser.css(self.css_selector)), 'Expect two links') external_link = browser.css(self.css_selector).first self.assertEquals('External Link', external_link.text) self.assertEquals('fa-icon fa-heart', external_link.attrib['class']) self.assertEquals('http://www.4teamwork.ch', external_link.attrib['href']) internal_link = browser.css(self.css_selector)[1] self.assertEquals('Internal Link', internal_link.text) self.assertEquals('fa-icon fa-glass', internal_link.attrib['class']) self.assertEquals(self.folder.absolute_url(), internal_link.attrib['href'])
def test_shows_message_when_error_happen_during_activity_creation(self, member): # Because there exists no OGDS user for the plone user hugo.boss, # the notification creation fails. browser.login('hugo.boss').open(self.dossier, view='++add++opengever.task.task') browser.fill({'Title': 'Test Task', 'Issuer': TEST_USER_ID, 'Responsible': 'inbox:client1', 'Task Type': 'comment'}) browser.css('#form-buttons-save').first.click() self.assertEquals( ['A problem has occurred during the notification creation. ' 'Notification could not or only partially produced.'], warning_messages()) self.assertEquals(['Item created'], info_messages())
def test_message_when_there_are_no_results(self, browser): browser.login().open(self.book, {'book_keywords': 'Foo'}, view='tabbedview_view-keywords/load') self.assertEquals('No results found.', browser.css('.no-results').first.text)
def test_query_info_on_node(self): with browser: browser.open_html('<html><body></body></html>') query_info = (browser.css('body').first, 'xpath', '//div') self.assertEqual( 'Empty result set: <NodeWrapper:body, >.xpath("//div") did not' ' match any nodes.', str(exceptions.NoElementFound(query_info)))
def visit(specification_title): browser.login(SITE_OWNER_NAME) browser.open(view='lawgiver-list-specs') specs = browser.css('dl.specifications').first link = specs.find(specification_title) assert link, 'Spec {!r} not found in {!r}'.format( specification_title, specs.terms) link.click()
def visit(specification_title): browser.login(SITE_OWNER_NAME) browser.open(view='lawgiver-list-specs') specs = browser.css('dl.specifications').first link = specs.find(specification_title) assert link, 'Spec {!r} not found in {!r}'.format(specification_title, specs.terms) link.click()
def test_keywords_are_shown_foreach_result(self, browser): chapter = create(Builder('chapter').within(self.book)) create(Builder('book textblock') .within(chapter) .titled('The Block') .having(text=keywords_html('Foo', 'Bar', 'Baz'), showTitle=True)) browser.login().open(self.book, {'book_keywords': 'Foo'}, view='tabbedview_view-keywords/load') self.assertEquals(['Bar,', 'Baz,', 'Foo'], browser.css('.result-keywords span').text) self.assertEquals(['Foo'], browser.css('.result-keywords b').text)
def test_shows_message_if_dispatchers_raise_an_exception(self, member): create(Builder('ogds_user') .having(userid='hugo.boss', email=None) .in_group(self.org_unit.users_group)) browser.login().open(self.dossier, view='++add++opengever.task.task') browser.fill({'Title': 'Test Task', 'Issuer': TEST_USER_ID, 'Responsible': u'hugo.boss', 'Task Type': 'comment'}) browser.css('#form-buttons-save').first.click() self.assertEquals( ['A problem has occurred during the notification creation. ' 'Notification could not or only partially produced.'], warning_messages()) self.assertEquals(['Item created'], info_messages())
def assert_service_links(self, context): browser.login().visit(context) self.assertEquals( 2, len(browser.css(self.css_selector)), 'Expect two links') external_link = browser.css(self.css_selector).first self.assertEquals('External Link', external_link.text) self.assertEquals('fa-icon fa-heart', external_link.attrib['class']) self.assertEquals('http://www.4teamwork.ch', external_link.attrib['href']) internal_link = browser.css(self.css_selector)[1] self.assertEquals('Internal Link', internal_link.text) self.assertEquals('fa-icon fa-glass', internal_link.attrib['class']) self.assertEquals(self.folder.absolute_url(), internal_link.attrib['href'])
def test_add_watcher_adds_subscription_for_each_actor(self, member): browser.login().open(self.dossier, view='++add++opengever.task.task') browser.fill({'Title': 'Test Task', 'Task Type': 'comment'}) form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill('inbox:org-unit-1') browser.css('#form-buttons-save').first.click() task = self.dossier.get('task-1') resource = notification_center().fetch_resource(task) subscriptions = resource.subscriptions self.assertItemsEqual([(u'inbox:org-unit-1', u'task_responsible'), (u'test_user_1_', u'task_issuer')], [(sub.watcher.actorid, sub.role) for sub in subscriptions])
def test_disable_service_nav_on_subsite(self, browser): subsite = create(Builder('folder').providing(INavigationRoot)) self.set_links(self.portal) self.set_links(subsite, disable=True) browser.login().visit(subsite) self.assertFalse( browser.css(self.css_selector), 'There are no Links, so no service nav should be rendered')
def test_is_modify_deadline_form(self, browser): task = create(Builder('task').in_state('task-state-in-progress')) self.do_transition(task) self.assertEquals('Modify deadline', browser.css('.documentFirstHeading').first.text) self.assert_action( 'http://nohost/plone/task-1/@@modify_deadline?' 'form.widgets.transition=task-transition-modify-deadline')
def test_toc_depth_config(self, browser): book = create(Builder('book').titled('The Book')) chapter = create(Builder('chapter') .titled('First Chapter') .within(book)) subchapter = create(Builder('chapter') .titled('The SubChapter') .within(chapter)) create(Builder('chapter') .titled('The SubSubChapter') .within(subchapter)) browser.login().visit(book) # view shows all subchapters by default self.assertEquals( ['The Book', '1 First Chapter', '1.1 The SubChapter', '1.1.1 The SubSubChapter'], [e.text for e in browser.css('#content-core .navTreeItem a')]) # limit depth to 1 subchapter browser.open(book, view='edit') browser.fill({'Table of contents depth': '1'}).submit() self.assertEquals( ['The Book', '1 First Chapter'], [e.text for e in browser.css('#content-core .navTreeItem a')]) # limit depth to 2 subchapter browser.open(book, view='edit') browser.fill({'Table of contents depth': '2'}).submit() self.assertEquals( ['The Book', '1 First Chapter', '1.1 The SubChapter'], [e.text for e in browser.css('#content-core .navTreeItem a')]) # empty depth means no limit browser.open(book, view='edit') browser.fill({'Table of contents depth': ''}).submit() self.assertEquals( ['The Book', '1 First Chapter', '1.1 The SubChapter', '1.1.1 The SubSubChapter'], [e.text for e in browser.css('#content-core .navTreeItem a')])
def test_no_duplicate_keywords(self, browser): chapter = create(Builder('chapter').within(self.book)) create(Builder('book textblock') .within(chapter) .having(text=keywords_html('Foo', 'bar', 'Foo'))) browser.login().visit(self.book, view='tabbedview_view-keywords') self.assertItemsEqual( ['Foo', 'bar', ''], browser.css('select[name=book_keywords] option').text)
def test_shows_message_when_error_happen_during_activity_creation(self, member): # Because there exists no OGDS user for the plone user hugo.boss, # the notification creation fails. browser.login('hugo.boss').open(self.dossier, view='++add++opengever.task.task') browser.fill({'Title': 'Test Task', 'Task Type': 'comment'}) form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill('inbox:client1') form.find_widget('Issuer').fill(TEST_USER_ID) browser.css('#form-buttons-save').first.click() self.assertEquals( ['A problem has occurred during the notification creation. ' 'Notification could not or only partially produced.'], warning_messages()) self.assertEquals(['Item created'], info_messages())
def test_keywords_are_ordered_case_insensitive(self, browser): chapter = create(Builder('chapter').within(self.book)) create(Builder('book textblock') .within(chapter) .having(text=keywords_html('foo', 'bar', 'Baz'))) browser.login().visit(self.book, view='tabbedview_view-keywords') self.assertEquals( ['', 'bar', 'Baz', 'foo'], browser.css('select[name=book_keywords] option').text)
def test_error_message_when_no_role_Found(self, browser): page = create(Builder('page')) browser.login().visit(page, view='lawgiver-sharing-describe-role', # "Reviewer" is not a spec role and is never displayd # in the sharing view. data={'role': 'Reviewer'}) self.assertEquals('Could not find any information about this role.', browser.css('p.error').first.text)
def test_role_description_is_displayed_when_defined(self, browser): page = create(Builder('page')) browser.login().visit(page, view='lawgiver-sharing-describe-role', data={'role': 'editor-in-chief'}) description = browser.css('.role-description').first.text # This description is set through translations in the Plone domain. self.assertEquals('The editor-in-chief reviews and publishes content.', description)
def test_permissions_are_shown_per_status(self, browser): page = create(Builder('page')) browser.login().visit(page, view='lawgiver-sharing-describe-role', data={'role': 'editor'}) table = browser.css('table').first.dicts() self.assertIn({'Action': 'Edit', 'Private': TICK, 'Pending': '', 'Published': ''}, table)
def test_general_role_inheritance_is_respected(self, browser): page = create(Builder('page')) browser.login().visit(page, view='lawgiver-sharing-describe-role', data={'role': 'editor'}) table = browser.css('table').first.dicts() self.assertIn({'Action': 'View', 'Private': TICK, 'Pending': TICK, 'Published': TICK}, table)
def test_permissions_from_general_statements_are_included(self, browser): page = create(Builder('page')) browser.login().visit(page, view='lawgiver-sharing-describe-role', data={'role': 'editor'}) table = browser.css('table').first.dicts() self.assertIn({'Action': 'Add', 'Private': TICK, 'Pending': TICK, 'Published': TICK}, table)
def test_shows_message_if_dispatchers_raise_an_exception(self, member): create( Builder('ogds_user').having(userid='hugo.boss', email=None).in_group( self.org_unit.users_group)) browser.login().open(self.dossier, view='++add++opengever.task.task') browser.fill({'Title': 'Test Task', 'Task Type': 'comment'}) form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill('hugo.boss') form.find_widget('Issuer').fill(TEST_USER_ID) browser.css('#form-buttons-save').first.click() self.assertEquals([ 'A problem has occurred during the notification creation. ' 'Notification could not or only partially produced.' ], warning_messages()) self.assertEquals(['Item created'], info_messages())
def test_link_to_non_existent_object_is_not_displayed(self, browser): self.set_links(self.portal) self.portal.manage_delObjects(self.portal.get('a-folder').id) transaction.commit() browser.login().visit(self.portal, view='service_navigation_form') browser.find_form_by_fields('Disable service links').submit() self.assertEqual([ item.text for item in browser.css( '#service-navigation ul li a:not(.ModifyServiceNavigation)') ], ['External Link'])
def test_link_to_non_existent_object_is_not_displayed(self, browser): self.set_links(self.portal) self.portal.manage_delObjects(self.portal.get('a-folder').id) transaction.commit() browser.login().visit(self.portal, view='service_navigation_form') browser.find_form_by_fields('Disable service links').submit() self.assertEqual( [item.text for item in browser.css( '#service-navigation ul li a:not(.ModifyServiceNavigation)')], ['External Link'])
def review_category_tree(): category_tree = [] listing_tables = browser.css('.categoryListing')[1:] for table in listing_tables: category_branch = [] for row in table.css('tr'): expand_toggle, checkbox, name, rank = row.css('td') item_title = name.text breadcrumb_title = name.css('a').first.attrib.get('title', '') category_branch.append([item_title, breadcrumb_title]) category_tree.append(category_branch) return category_tree
def fetch_players(team): print "-> Fetch players of", team["Nation"] browser.open(team["Link"]) table = browser.css("#content-core table.listing").first for row in table.css("tbody tr"): link = row.css("td a").first.attrib.get("href") player_id = int(link.split("/")[-1]) player = row.dict() player["Marktwert"] = int(player["Marktwert"].replace("'", "")) player["ID"] = player_id player["Link"] = link yield player
def fetch_players(team): print '-> Fetch players of', team['Nation'] browser.open(team['Link']) table = browser.css('#content-core table.listing').first for row in table.css('tbody tr'): link = row.css('td a').first.attrib.get('href') player_id = int(link.split('/')[-1]) player = row.dict() player['Marktwert'] = int(player['Marktwert'].replace("'", "")) player['ID'] = player_id player['Link'] = link yield player
def test_block_title_is_shown(self, browser): chapter = create(Builder('chapter').within(self.book)) create(Builder('book textblock') .within(chapter) .titled('The Block') .having(text=keywords_html('Foo'), showTitle=True)) browser.login().open(self.book, {'book_keywords': 'Foo'}, view='tabbedview_view-keywords/load') self.assertEquals('1.1 The Block', browser.css('.result .title').first.text)
def test_load_results_by_keyword(self, browser): chapter = create(Builder('chapter').within(self.book)) create(Builder('book textblock') .within(chapter) .having(text=keywords_html('Foo'))) create(Builder('book textblock') .within(chapter) .having(text=keywords_html('Bar'))) browser.login().open(self.book, {'book_keywords': 'Foo'}, view='tabbedview_view-keywords/load') self.assertEquals(1, len(browser.css('.result')), 'Expected exactly one result')
def test_service_navigation_cache(self, browser): self.set_links(self.portal, modified='some_value') self.assert_service_links(self.portal) self.set_links(self.portal, disable=True, modified='some_value') # Cache key has not changed - links are still visible self.assert_service_links(self.portal) self.set_links(self.portal, disable=True, modified='other_value') browser.login().visit(self.portal) self.assertFalse( browser.css(self.css_selector), 'There are no Links, so no service nav should be rendered')