def test_mails_publish_message(self, mock_mail): # Publishing a reviewed questionnaire adds the message to the email. publish_message = 'Success message' detail_page = SampleDetailPage(self) detail_page.route_kwargs = { 'identifier': self.questionnaire_reviewed.code } detail_page.open(login=True, user=self.user_publisher_group) detail_page.publish_questionnaire(message=publish_message) call_command('send_notification_mails') self.check_mails(mock_mail, [ { 'to': self.user_compiler, 'mail': 'published', 'message': publish_message, }, { 'to': self.user_editor_assigned, 'mail': 'published', 'message': publish_message, }, { 'to': self.user_reviewer_assigned, 'mail': 'published', 'message': publish_message, }, { 'to': self.user_wocat_mailbox, 'mail': 'published', 'message': publish_message, }, ])
def test_edit_questionnaire(self): user = self.create_new_user( email='*****@*****.**', groups=['Reviewers', 'Publishers']) # Alice logs in # She enters a Questionnaire new_page = SampleNewPage(self) new_page.open(login=True, user=user) new_page.click_edit_category('cat_1') step_page = SampleStepPage(self) step_page.enter_text(step_page.LOC_FORM_INPUT_KEY_1, 'Foo') step_page.enter_text(step_page.LOC_FORM_INPUT_KEY_3, 'Bar') step_page.submit_step() # The questionnaire is already saved as draft # She submits it for review edit_page = SampleEditPage(self) edit_page.submit_questionnaire() # She reviews it detail_page = SampleDetailPage(self) detail_page.review_questionnaire() # She publishes it detail_page.publish_questionnaire() # She sees it is public and visible assert detail_page.has_text('Foo') assert detail_page.has_text('Bar') url = self.browser.current_url # She creates a new version detail_page.create_new_version() # She edits it edit_page.click_edit_category('cat_1') # She changes some values step_page.enter_text(step_page.LOC_FORM_INPUT_KEY_1, 'asdf', clear=True) step_page.submit_step() # The questionnaire is already saved as draft # She is taken to the overview page where she sees the latest # (pending) changes of the draft edit_page.check_status('draft') assert not edit_page.has_text('Foo') assert edit_page.has_text('asdf') assert edit_page.has_text('Bar') # She sees the edit buttons assert edit_page.exists_el(edit_page.format_locator( edit_page.LOC_BUTTON_EDIT_CATEGORY, keyword='cat_1')) # She sees the possibility to view the questionnaire edit_page.view_questionnaire() self.assertIn(url, self.browser.current_url + '#top') # All the changes are there assert not detail_page.has_text('Foo') assert detail_page.has_text('asdf') assert detail_page.has_text('Bar') # There are no buttons to edit the sections anymore assert not detail_page.exists_el(detail_page.format_locator( edit_page.LOC_BUTTON_EDIT_CATEGORY, keyword='cat_1'))
def test_questionnaire_permissions( self, mock_change_status, mock_create_signal): key_1 = 'Foo' key_3 = 'Bar' user_1 = self.create_new_user(email='*****@*****.**') user_2 = self.create_new_user(email='*****@*****.**') user_moderator = self.create_new_user( email='*****@*****.**', groups=['Reviewers', 'Publishers']) # User 1 logs in and creates a questionnaire new_page = SampleNewPage(self) new_page.open(login=True, user=user_1) new_page.create_new_questionnaire(key_1=key_1, key_3=key_3) # A new notification should be created mock_create_signal.assert_called_once_with( questionnaire=Questionnaire.objects.latest('created'), sender='create_foo', user=user_1 ) # User 1 changes to the view mode new_page.view_questionnaire() # User 1 refreshes the page and sees the questionnaire view_page = SampleDetailPage(self) view_page.route_kwargs = { 'identifier': Questionnaire.objects.latest('pk').code} view_page.open() view_page.has_text(key_1) # User 1 logs out and cannot see the questionnaire view_page.logout() view_page.open() assert new_page.is_not_found_404() # User 2 logs in and cannot see the questionnaire view_page.open(login=True, user=user_2) assert view_page.is_not_found_404() # Moderator logs in and cannot see the questionnaire view_page.open(login=True, user=user_moderator) assert view_page.is_not_found_404() # User 1 submits the questionnaire view_page.open(login=True, user=user_1) view_page.submit_questionnaire() # A notification for the new status is created mock_change_status.assert_called_once_with( message='', questionnaire=Questionnaire.objects.latest('created'), sender='change_foo', user=user_1, previous_status=settings.QUESTIONNAIRE_DRAFT ) # User 1 logs out and cannot see the questionnaire view_page.logout() view_page.open() assert view_page.is_not_found_404() # User 2 logs in and cannot see the questionnaire view_page.open(login=True, user=user_2) assert view_page.is_not_found_404() # Moderator logs in and sees the questionnaire view_page.open(login=True, user=user_moderator) assert view_page.has_text(key_1) # Moderator publishes the questionnaire view_page.review_questionnaire() view_page.publish_questionnaire() # The moderator cannot create a new version assert not view_page.can_create_new_version() # Logged out users can see the questionnaire view_page.logout() view_page.open() assert view_page.has_text(key_1) # Logged out users cannot create a new version assert not view_page.can_create_new_version() # User 2 cannot edit the questionnaire view_page.open(login=True, user=user_2) assert view_page.has_text(key_1) assert not view_page.can_create_new_version() # User 1 can edit the questionnaire view_page.open(login=True, user=user_1) assert view_page.has_text(key_1) assert view_page.can_create_new_version()
def test_review_panel(self): # An Editor logs in and goes to the details page of a questionnaire # which he did not enter detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': 'sample_5'} detail_page.open(login=True, user=self.user_editor) assert detail_page.has_text('Foo 5') # He does see the review panel but no actions are possible detail_page.check_review_actions( create_new=False, edit=False, submit=False, review=False, publish=False, delete=False, change_compiler=False, ) # He goes to the details of a questionnaire where he is editor (only!). detail_page.route_kwargs = {'identifier': 'sample_3'} detail_page.open() assert detail_page.has_text('Foo 3') # He does see the review panel but can only edit detail_page.check_review_actions( create_new=True, edit=False, submit=False, review=False, publish=False, delete=False, change_compiler=False, ) # He creates a new version detail_page.create_new_version() edit_page = SampleEditPage(self) # He makes some changes and saves the questionnaire edit_page.click_edit_category('cat_1') step_page = SampleStepPage(self) step_page.enter_text(step_page.LOC_FORM_INPUT_KEY_1, ' (by Editor)') step_page.submit_step() # He sees a review panel but he does not see the button to # submit the questionnaire for review edit_page.check_review_actions( create_new=False, edit=False, submit=False, review=False, publish=False, delete=False, change_compiler=False, ) # He sees the buttons to edit each section assert edit_page.can_edit_category('cat_1') # User decides to view the questionnaire edit_page.view_questionnaire() # He does not see the button to edit each section anymore assert not edit_page.can_edit_category('cat_1') # Now the compiler logs in and goes to the detail page of the # questionnaire detail_page.open(login=True, user=self.user_compiler) # The compiler does see the button to submit the questionnaire detail_page.check_review_actions( create_new=False, edit=True, submit=True, review=False, publish=False, delete=True, change_compiler=False, ) # On the detail page, the compiler does not see buttons to edit the # categories assert not detail_page.can_edit_category('cat_1') # The compiler goes to the edit page and now sees the category buttons detail_page.edit_questionnaire() assert edit_page.can_edit_category('cat_1') # She submits the questionnaire to review assert edit_page.can_delete_questionnaire() edit_page.submit_questionnaire() # The questionnaire is now pending for review. The review panel # is visible but Compiler cannot do any actions. detail_page.check_review_actions( create_new=False, edit=False, submit=False, review=False, publish=False, delete=False, change_compiler=False, ) # The editor logs in again and opens the same page detail_page.open(login=True, user=self.user_editor) # He goes to the page and he also sees the review panel but no # actions can be taken. detail_page.check_review_actions( create_new=False, edit=False, submit=False, review=False, publish=False, delete=False, change_compiler=False, ) # Reviewer logs in and opens the page detail_page.open(login=True, user=self.user_reviewer) # He goes to the page and sees the review panel. There is a # button to do the review. detail_page.check_review_actions( create_new=False, edit=True, submit=False, review=True, publish=False, delete=False, change_compiler=False, ) # He is on the detail page and does not see the buttons to edit each # section assert not detail_page.can_edit_category('cat_1') # He goes to the edit page and now she sees the buttons detail_page.edit_questionnaire() assert edit_page.can_edit_category('cat_1') # He clicks the button to do the review edit_page.review_questionnaire() # He sees the review panel but no action is possible. detail_page.check_review_actions( create_new=False, edit=False, submit=False, review=False, publish=False, delete=False, change_compiler=False, ) # Compiler logs in and goes to the page, sees the review panel # but no actions possible detail_page.open(login=True, user=self.user_compiler) detail_page.check_review_actions( create_new=False, edit=False, submit=False, review=False, publish=False, delete=False, change_compiler=False, ) # Editor logs in and goes to the page, sees the review panel but # no actions possible. detail_page.open(login=True, user=self.user_editor) detail_page.check_review_actions( create_new=False, edit=False, submit=False, review=False, publish=False, delete=False, change_compiler=False, ) # Publisher logs in and goes to the page. He sees the review # panel with a button to publish. detail_page.open(login=True, user=self.user_publisher) detail_page.check_review_actions( create_new=False, edit=True, submit=False, review=False, publish=True, delete=False, change_compiler=False, ) # He is on the detail page and does not see the buttons to edit each # section assert not detail_page.can_edit_category('cat_1') # He goes to the edit page and now she sees the buttons detail_page.edit_questionnaire() # He clicks the button to publish the questionnaire. detail_page.publish_questionnaire() # The review panel is there but he cannot edit detail_page.check_review_actions( create_new=False, edit=False, submit=False, review=False, publish=False, delete=False, change_compiler=False, )
def test_secretariat_delete(self): # Secretariat user logs in # He goes to the details of a DRAFT questionnaire which he did not enter detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': 'sample_1'} detail_page.open(login=True, user=self.user_secretariat) assert detail_page.has_text('Foo 1') detail_page.check_status('draft') # He deletes the questionnaire. detail_page.delete_questionnaire() # He sees that he has been redirected to the "My SLM Practices" page my_data_page = MyDataPage(self) assert my_data_page.get_url() in self.browser.current_url # He goes to the details of a SUBMITTED questionnaire which he did not # enter detail_page.route_kwargs = {'identifier': 'sample_2'} detail_page.open() assert detail_page.has_text('Foo 2') detail_page.check_status('submitted') # He deletes the questionnaire. detail_page.delete_questionnaire() # He sees that he has been redirected to the "My SLM Practices" page assert my_data_page.get_url() in self.browser.current_url # He goes to the details of a REVIEWED questionnaire which he did not # enter detail_page.route_kwargs = {'identifier': 'sample_7'} detail_page.open() assert detail_page.has_text('Foo 7') detail_page.check_status('reviewed') # He deletes the questionnaire. detail_page.delete_questionnaire() # He sees that he has been redirected to the "My SLM Practices" page assert my_data_page.get_url() in self.browser.current_url # He also opens a PUBLIC questionnaire which he did not enter detail_page.route_kwargs = {'identifier': 'sample_3'} detail_page.open() assert detail_page.has_text('Foo 3') # In the database, there is only 1 version query_sample_3 = Questionnaire.objects.get(code='sample_3') assert query_sample_3.status == settings.QUESTIONNAIRE_PUBLIC assert not query_sample_3.is_deleted # He deletes the questionnaire. detail_page.delete_questionnaire() # He sees that he has been redirected to the "My SLM Practices" page assert my_data_page.get_url() in self.browser.current_url # In the database, there is still only 1 version query_sample_3 = Questionnaire.objects.get(code='sample_3') assert query_sample_3.status == settings.QUESTIONNAIRE_PUBLIC assert query_sample_3.is_deleted # He opens another PUBLIC questionnaire and edits it detail_page.route_kwargs = {'identifier': 'sample_5'} detail_page.open() assert detail_page.has_text('Foo 5') detail_page.create_new_version() # He deletes the newly created draft version detail_page.check_status('draft') detail_page.delete_questionnaire() # He sees that he has been redirected to the PUBLIC version of the # questionnaire, not the "My SLM Practices" page assert detail_page.get_url() in self.browser.current_url # He creates another version by editing it detail_page.create_new_version() # This time, he publishes the new version detail_page.submit_questionnaire() detail_page.review_questionnaire() detail_page.publish_questionnaire() # Now he deletes it detail_page.delete_questionnaire() # He is now redirected to the "My SLM Practices" page as there is no # version to show assert my_data_page.get_url() in self.browser.current_url
def test_edit_questionnaire(self): user = self.create_new_user(email='*****@*****.**', groups=['Reviewers', 'Publishers']) # Alice logs in # She enters a Questionnaire new_page = SampleNewPage(self) new_page.open(login=True, user=user) new_page.click_edit_category('cat_1') step_page = SampleStepPage(self) step_page.enter_text(step_page.LOC_FORM_INPUT_KEY_1, 'Foo') step_page.enter_text(step_page.LOC_FORM_INPUT_KEY_3, 'Bar') step_page.submit_step() # The questionnaire is already saved as draft # She submits it for review edit_page = SampleEditPage(self) edit_page.submit_questionnaire() # She reviews it detail_page = SampleDetailPage(self) detail_page.review_questionnaire() # She publishes it detail_page.publish_questionnaire() # She sees it is public and visible assert detail_page.has_text('Foo') assert detail_page.has_text('Bar') url = self.browser.current_url # She creates a new version detail_page.create_new_version() # She edits it edit_page.click_edit_category('cat_1') # She changes some values step_page.enter_text(step_page.LOC_FORM_INPUT_KEY_1, 'asdf', clear=True) step_page.submit_step() # The questionnaire is already saved as draft # She is taken to the overview page where she sees the latest # (pending) changes of the draft edit_page.check_status('draft') assert not edit_page.has_text('Foo') assert edit_page.has_text('asdf') assert edit_page.has_text('Bar') # She sees the edit buttons assert edit_page.exists_el( edit_page.format_locator(edit_page.LOC_BUTTON_EDIT_CATEGORY, keyword='cat_1')) # She sees the possibility to view the questionnaire edit_page.view_questionnaire() self.assertIn(url, self.browser.current_url + '#top') # All the changes are there assert not detail_page.has_text('Foo') assert detail_page.has_text('asdf') assert detail_page.has_text('Bar') # There are no buttons to edit the sections anymore assert not detail_page.exists_el( detail_page.format_locator(edit_page.LOC_BUTTON_EDIT_CATEGORY, keyword='cat_1'))