def test_mails_review(self, mock_mail): # Reviewing a submitted questionnaire sends an email to all publishers, # as well as to the compiler. detail_page = SampleDetailPage(self) detail_page.route_kwargs = { 'identifier': self.questionnaire_submitted.code } detail_page.open(login=True, user=self.user_reviewer_group) detail_page.review_questionnaire() call_command('send_notification_mails') self.check_mails(mock_mail, [ { 'to': self.user_compiler, 'mail': 'reviewed' }, { 'to': self.user_editor_assigned, 'mail': 'reviewed' }, { 'to': self.user_publisher_assigned, 'mail': 'reviewed', }, { 'to': self.user_wocat_mailbox, 'mail': 'reviewed' }, ])
def test_mails_review_message(self, mock_mail): # The message written when reviewing the questionnaire is in the mail. review_message = 'Message for the publisher' detail_page = SampleDetailPage(self) detail_page.route_kwargs = { 'identifier': self.questionnaire_submitted.code } detail_page.open(login=True, user=self.user_reviewer_group) detail_page.review_questionnaire(message=review_message) call_command('send_notification_mails') self.check_mails(mock_mail, [ { 'to': self.user_compiler, 'mail': 'reviewed', 'message': review_message }, { 'to': self.user_editor_assigned, 'mail': 'reviewed', 'message': review_message }, { 'to': self.user_publisher_assigned, 'mail': 'reviewed', 'message': review_message }, { 'to': self.user_wocat_mailbox, 'mail': 'reviewed', 'message': review_message }, ])
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_mails_delete(self, mock_mail): # Deleting a questionnaire sends an email to the compiler. detail_page = SampleDetailPage(self) detail_page.route_kwargs = { 'identifier': self.questionnaire_reviewed.code } detail_page.open(login=True, user=self.user_secretariat) detail_page.delete_questionnaire() call_command('send_notification_mails') self.check_mails(mock_mail, [ { 'to': self.user_compiler, 'mail': 'deleted' }, { 'to': self.user_editor_assigned, 'mail': 'deleted' }, { 'to': self.user_reviewer_assigned, 'mail': 'deleted' }, { 'to': self.user_publisher_assigned, 'mail': 'deleted' }, { 'to': self.user_wocat_mailbox, 'mail': 'deleted' }, ])
def test_mails_compiler_added_keep_as_editor( self, mock_user_information, mock_search_users, mock_mail): # Changing the compiler sends a mail to the previous compiler and to the # new one. If the previous compiler is now an editor, another mail is # sent (also to the new compiler). mock_search_users.side_effect = self.get_mock_remote_user_client_search mock_user_information.side_effect = self.get_mock_remote_user_client_user_information detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': self.questionnaire_draft.code} detail_page.open(login=True, user=self.user_secretariat) detail_page.change_compiler( self.user_bob.firstname, keep_as_editor=True) call_command('send_notification_mails') self.check_mails(mock_mail, [ { 'to': self.user_compiler, 'mail': 'compiler_removed' }, { 'to': self.user_bob, 'mail': 'compiler_added' }, { 'to': self.user_compiler, 'mail': 'editor_added' }, ])
def test_mails_rejected_reviewed(self, mock_mail): # Rejecting a reviewed questionnaire sends an email to the compiler. reject_message = 'Rejected because it is incomplete.' 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.reject_questionnaire(reject_message) call_command('send_notification_mails') self.check_mails(mock_mail, [ { 'to': self.user_compiler, 'mail': 'rejected_reviewed', 'message': reject_message, }, { 'to': self.user_editor_assigned, 'mail': 'rejected_reviewed', 'message': reject_message, }, { 'to': self.user_reviewer_assigned, 'mail': 'rejected_reviewed', 'message': reject_message, }, { 'to': self.user_wocat_mailbox, 'mail': 'rejected_reviewed', 'message': reject_message, }, ])
def test_delete_with_lock_by_own_user(self): # The compiler (!) logs in and starts editing, this creates a lock. detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': self.questionnaire.code} detail_page.open(login=True, user=self.jay) detail_page.edit_questionnaire() edit_page = SampleEditPage(self) edit_page.click_edit_category('cat_1') # The compiler opens the detail page (= back without saving) and wants # to delete the questionnaire while his own lock is still active. This # works because his own lock is released when deleting the # questionnaire. detail_page.open() detail_page.delete_questionnaire(check_success=True) assert Questionnaire.objects.get( code=self.questionnaire.code).is_deleted is True
def test_mails_editor_added( self, mock_user_information, mock_search_users, mock_mail): # Inviting an editor sends a mail to this editor. mock_search_users.side_effect = self.get_mock_remote_user_client_search mock_user_information.side_effect = self.get_mock_remote_user_client_user_information detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': self.questionnaire_draft.code} detail_page.open(login=True, user=self.user_compiler) detail_page.assign_user(self.user_bob.firstname) call_command('send_notification_mails') self.check_mails(mock_mail, [ { 'to': self.user_bob, 'mail': 'editor_added', } ])
def test_mails_edit(self, mock_mail): # Notifying about having finished editing a draft questionnaire sends an # email to the compiler. self.questionnaire_draft.add_user(self.user_alice, 'editor') # Reviewer should not receive an email self.questionnaire_draft.add_user(self.user_bob, 'reviewer') detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': self.questionnaire_draft.code} detail_page.open(login=True, user=self.user_alice) detail_page.finish_editing() call_command('send_notification_mails') self.check_mails(mock_mail, [ { 'to': self.user_compiler, 'mail': 'edited' } ])
def test_mails_submit(self, mock_mail): # Submitting a draft questionnaire sends an email to all reviewers. detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': self.questionnaire_draft.code} detail_page.open(login=True, user=self.user_compiler) detail_page.submit_questionnaire() call_command('send_notification_mails') self.check_mails(mock_mail, [ { 'to': self.user_reviewer_assigned, 'mail': 'submitted' }, { 'to': self.user_wocat_mailbox, 'mail': 'submitted' }, ]) # In order to always access the same mail, do some ordering first mock_mail_call_args = [call[1] for call in mock_mail.call_args_list] mock_alt_mail_call_args = [ call[1] for call in mock_mail.return_value.attach_alternative.call_args_list] merged_calls = zip(mock_mail_call_args, mock_alt_mail_call_args) sorted_calls = sorted( merged_calls, key=lambda c: (c[0]['to'], c[0]['subject'])) sorted_mock_mail_calls, sorted_mock_alt_mail_calls = zip( *sorted_calls) mail_body_plain = sorted_mock_mail_calls[1]['body'] mail_body_html = sorted_mock_alt_mail_calls[1]['content'] for mail_body in [mail_body_plain, mail_body_html]: assert self.questionnaire_draft.get_absolute_url() in mail_body assert self.user_wocat_mailbox.get_display_name() in mail_body assert self.user_compiler.get_display_name() in mail_body assert str(settings.BASE_URL) in mail_body assert str(self.user_wocat_mailbox.mailpreferences.get_signed_url()) in \ mail_body
def test_mails_publisher_added( self, mock_user_information, mock_search_users, mock_mail): # Inviting a publisher sends a mail to this publisher and to the # compiler. mock_search_users.side_effect = self.get_mock_remote_user_client_search mock_user_information.side_effect = self.get_mock_remote_user_client_user_information detail_page = SampleDetailPage(self) detail_page.route_kwargs = { 'identifier': self.questionnaire_reviewed.code } detail_page.open(login=True, user=self.user_secretariat) detail_page.assign_user(self.user_bob.firstname) call_command('send_notification_mails') self.check_mails(mock_mail, [ { 'to': self.user_bob, 'mail': 'publisher_added' }, ])
def test_mails_submit_message(self, mock_mail): # Submitting a draft questionnaire sends an email to all reviewers which # includes the message entered upon submission submit_message = 'Message for the reviewer' detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': self.questionnaire_draft.code} detail_page.open(login=True, user=self.user_compiler) detail_page.submit_questionnaire(message=submit_message) call_command('send_notification_mails') self.check_mails(mock_mail, [ { 'to': self.user_wocat_mailbox, 'mail': 'submitted', 'message': submit_message }, { 'to': self.user_reviewer_assigned, 'mail': 'submitted', 'message': submit_message } ])
def test_review_locked_questionnaire(self): # Secretariat user logs in and goes to the details of a SUBMITTED # questionnaire detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': 'sample_2'} detail_page.open(login=True, user=self.user_secretariat) assert detail_page.has_text(self.sample_2_text) # User starts to edit the first section (this sets a lock on the # questionnaire) detail_page.edit_questionnaire() edit_page = SampleEditPage(self) edit_page.click_edit_category(edit_page.CATEGORIES[0][0]) # User goes back to the details (without saving!) detail_page.open() # User reviews the questionnaire and sees there is no exception thrown detail_page.review_questionnaire() # He sees the questionnaire is now reviewed detail_page.check_status('reviewed')
def test_do_not_show_deleted_links_in_form(self): user = User.objects.get(pk=101) samplemulti_link = 'This is key 1a' sample_link = 'This is the first key.' # User goes to the SAMPLE questionnaire and sees the link detail_page_sample = SampleDetailPage(self) detail_page_sample.route_kwargs = {'identifier': 'sample_1'} detail_page_sample.open(login=True, user=user) assert detail_page_sample.has_text(samplemulti_link) # User starts editing the questionnaire detail_page_sample.create_new_version() edit_page = SampleEditPage(self) assert edit_page.has_text(samplemulti_link) # User opens the step with the link and sees the link is there edit_page.click_edit_category('cat_5') step_page = QuestionnaireStepPage(self) assert step_page.check_links([samplemulti_link]) # User opens the details page of the SAMPLEMULTI questionnaire detail_page_multi = SampleMultiDetailPage(self) detail_page_multi.route_kwargs = {'identifier': 'samplemulti_1'} detail_page_multi.open() assert detail_page_multi.has_text(sample_link) # User deletes the questionnaire detail_page_multi.delete_questionnaire() # User opens the detail page of the SAMPLE questionnaire again. The link # is not there anymore. detail_page_sample.open() assert not detail_page_sample.has_text(samplemulti_link) # The link is not on the edit page either detail_page_sample.edit_questionnaire() assert not detail_page_sample.has_text(samplemulti_link) # Also on the step edit page, no link edit_page.click_edit_category('cat_5') assert step_page.check_links([]) # The step can be submitted without an error step_page.submit_step()
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_edit_public(self): code = 'sample_3' user = User.objects.get(pk=101) old_text = 'Faz 3' new_text = 'asdf' # User logs in and goes to the detail page of a "public" Questionnaire detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': code} detail_page.open(login=True, user=user) assert code in self.browser.current_url assert detail_page.has_text(old_text) assert not detail_page.has_text(new_text) # There is only one version of this questionnaire in the db assert Questionnaire.objects.filter(code=code).count() == 1 # User uses the direct link to go to the edit page of the questionnaire # and sees no new version of the questionnaire is created in the DB. # This prevents the issue when new versions were created upon GET of the # edit page, which should be fixed now. edit_page = SampleEditPage(self) edit_page.route_kwargs = {'identifier': code} edit_page.open() assert Questionnaire.objects.filter(code=code).count() == 1 # User edits the Questionnaire (creates a new version) and sees that # the URL contains the code of the Questionnaire detail_page.open() detail_page.create_new_version() assert code in self.browser.current_url # User edits a category and sees that the URL still contains the # code of the Questionnaire edit_page.click_edit_category('cat_2') assert code in self.browser.current_url # User makes some changes and submits the category step_page = SampleStepPage(self) step_page.enter_text( step_page.LOC_FORM_INPUT_KEY_5, new_text, clear=True) step_page.submit_step() # User is back on the overview page and sees that the URL still # contains the code of the Questionnaire assert code in self.browser.current_url assert edit_page.has_text(code) # She sees that the value of Key 1 was updated assert not edit_page.has_text(old_text) assert edit_page.has_text(new_text) # Also there was an additional version created in the database assert Questionnaire.objects.count() == 11 # The newly created version has the same code assert Questionnaire.objects.filter(code=code).count() == 2 # She goes to see her own questionnaire and sees sample_3 appears only # once my_page = MyDataPage(self) my_page.open() my_page.wait_for_lists() expected_list = [ { 'description': new_text, }, { # Just to check that description is there ... 'description': 'Faz 1' }, # ... the rest does not really matter ] assert my_page.count_list_results() == 6 my_page.check_list_results(expected_list, count=False) # She clicks the first entry and sees that she is taken to the # details page of the latest (pending) version. my_page.click_list_entry(index=0) assert detail_page.has_text(new_text)
def test_show_only_one_linked_version(self): sample_title = 'This is the first key.' samplemulti_title = 'This is key 1a' samplemulti_changed_text = ' (changed)' samplemulti_title_changed = samplemulti_title + samplemulti_changed_text # Alice logs in # She goes to the SAMPLE questionnaire and sees the link user_1 = User.objects.get(pk=101) sample_detail_page = SampleDetailPage(self) sample_detail_page.route_kwargs = {'identifier': 'sample_1'} sample_detail_page.open(login=True, user=user_1) sample_detail_page.expand_details() expected_samplemulti_links = [ { 'title': samplemulti_title, 'configuration': 'samplemulti', } ] sample_detail_page.check_linked_questionnaires( expected=expected_samplemulti_links) # She goes to the MULTISAMPLE questionnaire and sees the link sample_detail_page.click_linked_questionnaire(index=0) samplemulti_detail_page = SampleMultiDetailPage(self) samplemulti_detail_page.expand_details() expected_sample_links = [ { 'title': sample_title, 'configuration': 'sample', } ] samplemulti_detail_page.check_linked_questionnaires( expected=expected_sample_links) # She edits the MULTISAMPLE questionnaire and sees only one # version is linked (still the same) samplemulti_detail_page.create_new_version() samplemulti_edit_page = SampleMultiEditPage(self) samplemulti_edit_page.click_edit_category('mcat_1') samplemulti_step_page = SampleMultiStepPage(self) samplemulti_step_page.enter_text( samplemulti_step_page.LOC_QUESTION_MQG01_MKEY01, samplemulti_changed_text) # She submits the step samplemulti_step_page.submit_step() # She sees that only one questionnaire is linked samplemulti_edit_page.expand_details() samplemulti_edit_page.check_linked_questionnaires( expected=expected_sample_links) # She goes to the SAMPLE questionnaire and sees only one version # is linked (the pending one) samplemulti_edit_page.click_linked_questionnaire(index=0) expected_samplemulti_links_changed = [ { 'title': samplemulti_title_changed, 'configuration': 'samplemulti', } ] sample_detail_page.check_linked_questionnaires( expected=expected_samplemulti_links_changed) # She even creates a new version and opens the form and sees there is # only one version sample_detail_page.create_new_version() sample_edit_page = SampleEditPage(self) sample_edit_page.click_edit_category('cat_5') sample_step_page = SampleStepPage(self) sample_step_page.check_links([samplemulti_title_changed]) sample_step_page.back_without_saving() # She logs out and sees only one questionnaire is linked (the # active one) sample_detail_page.logout() sample_detail_page.open() sample_detail_page.expand_details() sample_detail_page.check_linked_questionnaires( expected=expected_samplemulti_links) # She logs in as a different user and sees only one version is # linked (the active one) user_2 = User.objects.get(pk=102) sample_detail_page.open(login=True, user=user_2) sample_detail_page.expand_details() sample_detail_page.check_linked_questionnaires( expected=expected_samplemulti_links)
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_creation_date_does_not_change(self): # Alice logs in user = User.objects.get(pk=102) # She goes to the details of an existing questionnaire and takes # note of the creation and update dates detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': 'sample_3'} detail_page.open(login=True, user=user) creation_date = detail_page.get_el(detail_page.LOC_CREATION_DATE).text update_date = detail_page.get_el(detail_page.LOC_UPDATE_DATE).text # She creates a new version detail_page.create_new_version() # She notices that the creation date did not change while the # update date changed. creation_date_1 = detail_page.get_el( detail_page.LOC_CREATION_DATE).text update_date_1 = detail_page.get_el(detail_page.LOC_UPDATE_DATE).text assert creation_date == creation_date_1 assert update_date != update_date_1 # Alice logs in as a different user # She also opens a draft version of a questionnaire and takes # note of the creation and update dates user = User.objects.get(pk=101) detail_page.route_kwargs = {'identifier': 'sample_1'} detail_page.open(login=True, user=user) creation_date = detail_page.get_el(detail_page.LOC_CREATION_DATE).text update_date = detail_page.get_el(detail_page.LOC_UPDATE_DATE).text # She makes an edit detail_page.edit_questionnaire() edit_page = SampleEditPage(self) edit_page.click_edit_category('cat_1') step_page = SampleStepPage(self) step_page.enter_text(step_page.LOC_FORM_INPUT_KEY_1, ' (changed)') # She submits the questionnaire step_page.submit_step() # She sees the changes were submitted assert edit_page.has_text(' (changed)') # She notices that the creation date did not change while the # update date changed. creation_date_1 = edit_page.get_el(edit_page.LOC_CREATION_DATE).text update_date_1 = edit_page.get_el(edit_page.LOC_UPDATE_DATE).text assert creation_date == creation_date_1 assert update_date != update_date_1
def test_review_locked_questionnaire_blocked_by_other(self): # Reviewer logs in and goes to the details of a SUBMITTED questionnaire detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': 'sample_2'} detail_page.open(login=True, user=self.user_reviewer) assert detail_page.has_text('Foo 2') # He starts to edit the first section (this sets a lock on the # questionnaire) detail_page.edit_questionnaire() edit_page = SampleEditPage(self) edit_page.click_edit_category('cat_1') # Secretariat user logs in and goes to the details of the same # questionnaire detail_page.open(login=True, user=self.user_secretariat) assert detail_page.has_text('Foo 2') # The user sees a message that the questionnaire is currently locked assert detail_page.is_locked_by(user=self.user_reviewer) # He reviews the questionnaire which is still locked and sees there is # no exception thrown, however she sees a warning. detail_page.review_questionnaire(check_success=False) assert detail_page.is_locked_by(user=self.user_reviewer) # He sees the questionnaire is still submitted detail_page.check_status('submitted')
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_delete_with_lock(self): # The editor logs in and starts editing, this creates a lock. detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': self.questionnaire.code} detail_page.open(login=True, user=self.robin) detail_page.edit_questionnaire() edit_page = SampleEditPage(self) edit_page.click_edit_category('cat_1') # The compiler logs in and wants to delete the questionnaire detail_page.open(login=True, user=self.jay) assert Questionnaire.objects.get( code=self.questionnaire.code).is_deleted is False assert detail_page.has_text(self.questionnaire.code) detail_page.delete_questionnaire(check_success=False) # He receives an error message, the questionnaire was not deleted. assert detail_page.has_warning_message( f'This questionnaire is locked for editing by ' f'{self.robin.get_display_name()}.') assert detail_page.has_text(self.questionnaire.code) assert Questionnaire.objects.get( code=self.questionnaire.code).is_deleted is False # After a while, the lock expires Lock.objects.filter( questionnaire_code=self.questionnaire.code ).update(is_finished=True) # Now the questionnaire can be deleted. detail_page.delete_questionnaire(check_success=True) assert Questionnaire.objects.get( code=self.questionnaire.code).is_deleted is True
def test_creation_date_does_not_change(self): # Alice logs in user = User.objects.get(pk=102) # She goes to the details of an existing questionnaire and takes # note of the creation and update dates detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': 'sample_3'} detail_page.open(login=True, user=user) creation_date = detail_page.get_el(detail_page.LOC_CREATION_DATE).text update_date = detail_page.get_el(detail_page.LOC_UPDATE_DATE).text # She creates a new version detail_page.create_new_version() # She notices that the creation date did not change while the # update date changed. creation_date_1 = detail_page.get_el(detail_page.LOC_CREATION_DATE).text update_date_1 = detail_page.get_el(detail_page.LOC_UPDATE_DATE).text assert creation_date == creation_date_1 assert update_date != update_date_1 # Alice logs in as a different user # She also opens a draft version of a questionnaire and takes # note of the creation and update dates user = User.objects.get(pk=101) detail_page.route_kwargs = {'identifier': 'sample_1'} detail_page.open(login=True, user=user) creation_date = detail_page.get_el(detail_page.LOC_CREATION_DATE).text update_date = detail_page.get_el(detail_page.LOC_UPDATE_DATE).text # She makes an edit detail_page.edit_questionnaire() edit_page = SampleEditPage(self) edit_page.click_edit_category('cat_1') step_page = SampleStepPage(self) step_page.enter_text(step_page.LOC_FORM_INPUT_KEY_1, ' (changed)') # She submits the questionnaire step_page.submit_step() # She sees the changes were submitted assert edit_page.has_text(' (changed)') # She notices that the creation date did not change while the # update date changed. creation_date_1 = edit_page.get_el(edit_page.LOC_CREATION_DATE).text update_date_1 = edit_page.get_el(edit_page.LOC_UPDATE_DATE).text assert creation_date == creation_date_1 assert update_date != update_date_1
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_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_delete_with_lock(self): # The editor logs in and starts editing, this creates a lock. detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': self.questionnaire.code} detail_page.open(login=True, user=self.robin) detail_page.edit_questionnaire() edit_page = SampleEditPage(self) edit_page.click_edit_category('cat_1') # The compiler logs in and wants to delete the questionnaire detail_page.open(login=True, user=self.jay) assert Questionnaire.objects.get( code=self.questionnaire.code).is_deleted is False assert detail_page.has_text(self.questionnaire.code) detail_page.delete_questionnaire(check_success=False) # He receives an error message, the questionnaire was not deleted. assert detail_page.has_warning_message( f'This questionnaire is locked for editing by ' f'{self.robin.get_display_name()}.') assert detail_page.has_text(self.questionnaire.code) assert Questionnaire.objects.get( code=self.questionnaire.code).is_deleted is False # After a while, the lock expires Lock.objects.filter(questionnaire_code=self.questionnaire.code).update( is_finished=True) # Now the questionnaire can be deleted. detail_page.delete_questionnaire(check_success=True) assert Questionnaire.objects.get( code=self.questionnaire.code).is_deleted is True
def test_edit_public_new_config_edition(self, mock_choices): mock_choices.return_value = CODE_CHOICES + [ ('sample', 'sample'), ] code = 'sample_3' old_version = Questionnaire.objects.get(code=code) # A user logs in and goes to the detail page of a public questionnaire # where he is the compiler detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': code} detail_page.open(login=True, user=self.user) # The user sees a hint about a new edition on the detail page detail_page.close_edition_modal() assert detail_page.has_new_edition() # The user creates a new version detail_page.create_new_version() # The new version is in the new edition new_version = Questionnaire.objects.latest('updated') assert new_version.configuration.edition == '2018' # The data of the old version was cleaned up assert old_version.data['qg_2'][0]['key_2'] is not None assert new_version.data['qg_2'][0]['key_2'] is None assert old_version.data['qg_2'][0]['key_3'] \ == new_version.data['qg_2'][0]['key_3'] assert 'qg_5' in old_version.data assert 'qg_5' not in new_version.data # The old values are still there edit_page = SampleEditPage(self) assert edit_page.has_text('Foo 3') # New questions are available and can be entered edit_page.click_edit_category('cat_4') step_page = SampleStepPage(self) step_page.enter_text(step_page.LOC_FORM_INPUT_KEY_68, 'New key for edition 2018') step_page.submit_step() assert edit_page.has_text('New key for edition 2018') # The old values are still there assert edit_page.has_text('Foo 3') # Questions also have updated labels edit_page.click_edit_category('cat_1') assert step_page.has_text('Key 1 (edition 2018):') step_page.submit_step() # The old values are still there assert edit_page.has_text('Foo 3') # The user submits the version edit_page.submit_questionnaire() # The version is reviewed (in DB) new_version.status = settings.QUESTIONNAIRE_PUBLIC new_version.save() # The new public version does not have a hint about new editions detail_page.open() assert not detail_page.has_new_edition()
def test_secretariat_can_assign_reviewer_2( self, mock_member_change, mock_search_users, mock_user_information): mock_search_users.side_effect = self.get_mock_remote_user_client_search mock_user_information.side_effect = self.get_mock_remote_user_client_user_information identifier = 'sample_3' editor = User.objects.get(pk=102) old_compiler = User.objects.get(pk=101) new_compiler_1 = self.create_new_user( email='*****@*****.**', last_name='wocat', first_name='test2' ) new_compiler_2 = self.create_new_user( email='*****@*****.**', last_name='wocat', first_name='test3' ) # User (publisher) opens the details of a public questionnaire detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': identifier} detail_page.open(login=True, user=self.user_publisher) # User (publisher) sees he can neither edit nor change compiler assert not detail_page.can_create_new_version() assert not detail_page.can_change_compiler() assert not detail_page.can_delete_questionnaire() # User (secretariat) opens the details of a public questionnaire detail_page.route_kwargs = {'identifier': identifier} detail_page.open(login=True, user=self.user_secretariat) # User (secretariat) can edit and review and assign users assert detail_page.can_create_new_version() assert detail_page.can_change_compiler() assert detail_page.can_delete_questionnaire() # The compiler and the editors are correct. assert detail_page.get_compiler() == old_compiler.get_display_name() assert detail_page.get_editors() == [editor.get_display_name()] # User goes to the list view and sees the compiler there list_page = SampleListPage(self) list_page.open() list_results = [ { }, { 'title': 'Foo 3', 'compiler': old_compiler } ] list_page.check_list_results(list_results) # User goes back to the questionnaire details detail_page.open() detail_page.hide_notifications() # User changes compiler but does not enter a name detail_page.open_change_compiler_panel() detail_page.click_change_compiler() # No notifications were created self.assertEqual(mock_member_change.call_count, 0) assert detail_page.has_error_message( detail_page.TEXT_MESSAGE_NO_VALID_NEW_COMPILER) detail_page.hide_notifications() # User selects a new compiler detail_page.change_compiler( new_compiler_1.get_display_name(), submit=False ) # The new compiler is listed assert detail_page.get_selected_compilers() == [ new_compiler_1.get_display_name()] # User confirms and sees a success message detail_page.click_change_compiler() assert detail_page.has_success_message( detail_page.TEXT_MESSAGE_COMPILER_CHANGED) # Two notifications were created self.assertEqual(mock_member_change.call_count, 2) mock_member_change.assert_any_call( sender='delete_member', questionnaire=Questionnaire.objects.get(code=identifier), user=self.user_secretariat, affected=old_compiler, role='compiler' ) mock_member_change.assert_any_call( sender='add_member', questionnaire=Questionnaire.objects.get(code=identifier), user=self.user_secretariat, affected=new_compiler_1, role='compiler' ) mock_member_change.reset_mock() # The new compiler is visible in the details, editor did not change assert detail_page.get_compiler() == new_compiler_1.get_display_name() assert detail_page.get_editors() == [editor.get_display_name()] # In the list, the new compiler is visible list_page.open() list_results = [ { }, { 'title': 'Foo 3', 'compiler': new_compiler_1 } ] list_page.check_list_results(list_results) # In the details page, the user changes the compiler and enters the # current compiler once again detail_page.open() detail_page.hide_notifications() detail_page.change_compiler( new_compiler_1.get_display_name(), submit=False ) # The compiler is listed assert detail_page.get_selected_compilers() == [ new_compiler_1.get_display_name()] # User confirms and sees an error message detail_page.click_change_compiler() assert detail_page.has_notice_message( detail_page.TEXT_MESSAGE_USER_ALREADY_COMPILER) # No notifications were created self.assertEqual(mock_member_change.call_count, 0) # User changes the compiler yet again. detail_page.hide_notifications() detail_page.change_compiler( new_compiler_2.get_display_name(), submit=False) assert detail_page.get_selected_compilers() == [ new_compiler_2.get_display_name()] # User sees the search box is now disabled assert not detail_page.can_enter_new_compiler() # User marks the checkbox which keeps the old compiler as editor detail_page.select_keep_compiler_as_editor() detail_page.click_change_compiler() assert detail_page.has_success_message( detail_page.TEXT_MESSAGE_COMPILER_CHANGED) # Three notifications were created self.assertEqual(mock_member_change.call_count, 3) mock_member_change.assert_any_call( sender='delete_member', questionnaire=Questionnaire.objects.get(code=identifier), user=self.user_secretariat, affected=new_compiler_1, role='compiler' ) mock_member_change.assert_any_call( sender='add_member', questionnaire=Questionnaire.objects.get(code=identifier), user=self.user_secretariat, affected=new_compiler_2, role='compiler' ) mock_member_change.assert_any_call( sender='add_member', questionnaire=Questionnaire.objects.get(code=identifier), user=self.user_secretariat, affected=new_compiler_1, role='editor' ) mock_member_change.reset_mock() # The new compiler is visible in the details assert detail_page.get_compiler() == new_compiler_2.get_display_name() # The old compiler is now an editor assert new_compiler_1.get_display_name() in detail_page.get_editors() list_page.open() list_results = [ { }, { 'title': 'Foo 3', 'compiler': new_compiler_2 } ] list_page.check_list_results(list_results)
def test_show_only_one_linked_version(self): sample_title = 'This is the first key.' samplemulti_title = 'This is key 1a' samplemulti_changed_text = ' (changed)' samplemulti_title_changed = samplemulti_title + samplemulti_changed_text # Alice logs in # She goes to the SAMPLE questionnaire and sees the link user_1 = User.objects.get(pk=101) sample_detail_page = SampleDetailPage(self) sample_detail_page.route_kwargs = {'identifier': 'sample_1'} sample_detail_page.open(login=True, user=user_1) sample_detail_page.expand_details() expected_samplemulti_links = [{ 'title': samplemulti_title, 'configuration': 'samplemulti', }] sample_detail_page.check_linked_questionnaires( expected=expected_samplemulti_links) # She goes to the MULTISAMPLE questionnaire and sees the link sample_detail_page.click_linked_questionnaire(index=0) samplemulti_detail_page = SampleMultiDetailPage(self) samplemulti_detail_page.expand_details() expected_sample_links = [{ 'title': sample_title, 'configuration': 'sample', }] samplemulti_detail_page.check_linked_questionnaires( expected=expected_sample_links) # She edits the MULTISAMPLE questionnaire and sees only one # version is linked (still the same) samplemulti_detail_page.create_new_version() samplemulti_edit_page = SampleMultiEditPage(self) samplemulti_edit_page.click_edit_category('mcat_1') samplemulti_step_page = SampleMultiStepPage(self) samplemulti_step_page.enter_text( samplemulti_step_page.LOC_QUESTION_MQG01_MKEY01, samplemulti_changed_text) # She submits the step samplemulti_step_page.submit_step() # She sees that only one questionnaire is linked samplemulti_edit_page.expand_details() samplemulti_edit_page.check_linked_questionnaires( expected=expected_sample_links) # She goes to the SAMPLE questionnaire and sees only one version # is linked (the pending one) samplemulti_edit_page.click_linked_questionnaire(index=0) expected_samplemulti_links_changed = [{ 'title': samplemulti_title_changed, 'configuration': 'samplemulti', }] sample_detail_page.check_linked_questionnaires( expected=expected_samplemulti_links_changed) # She even creates a new version and opens the form and sees there is # only one version sample_detail_page.create_new_version() sample_edit_page = SampleEditPage(self) sample_edit_page.click_edit_category('cat_5') sample_step_page = SampleStepPage(self) sample_step_page.check_links([samplemulti_title_changed]) sample_step_page.back_without_saving() # She logs out and sees only one questionnaire is linked (the # active one) sample_detail_page.logout() sample_detail_page.open() sample_detail_page.expand_details() sample_detail_page.check_linked_questionnaires( expected=expected_samplemulti_links) # She logs in as a different user and sees only one version is # linked (the active one) user_2 = User.objects.get(pk=102) sample_detail_page.open(login=True, user=user_2) sample_detail_page.expand_details() sample_detail_page.check_linked_questionnaires( expected=expected_samplemulti_links)
def test_secretariat_edit(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') # He sees a button to edit the questionnaire, he clicks it detail_page.edit_questionnaire() # In edit mode, he sees that he can edit the first section edit_page = SampleEditPage(self) edit_page.click_edit_category('cat_1') # He saves the step and returns step_page = SampleStepPage(self) step_page.submit_step() # 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 assert Questionnaire.objects.filter(code='sample_3').count() == 1 # He sees a button to edit the questionnaire, he clicks it and creates a # new version detail_page.create_new_version() # In the database, there are now 2 versions assert Questionnaire.objects.filter(code='sample_3').count() == 2
def test_edit_public_new_config_edition(self, mock_choices): mock_choices.return_value = CODE_CHOICES + [('sample', 'sample'), ] code = 'sample_3' old_version = Questionnaire.objects.get(code=code) # A user logs in and goes to the detail page of a public questionnaire # where he is the compiler detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': code} detail_page.open(login=True, user=self.user) # The user sees a hint about a new edition on the detail page detail_page.close_edition_modal() assert detail_page.has_new_edition() # The user creates a new version detail_page.create_new_version() # The new version is in the new edition new_version = Questionnaire.objects.latest('updated') assert new_version.configuration.edition == '2018' # The data of the old version was cleaned up assert old_version.data['qg_2'][0]['key_2'] is not None assert new_version.data['qg_2'][0]['key_2'] is None assert old_version.data['qg_2'][0]['key_3'] \ == new_version.data['qg_2'][0]['key_3'] assert 'qg_5' in old_version.data assert 'qg_5' not in new_version.data # The old values are still there edit_page = SampleEditPage(self) assert edit_page.has_text('Foo 3') # New questions are available and can be entered edit_page.click_edit_category('cat_4') step_page = SampleStepPage(self) step_page.enter_text( step_page.LOC_FORM_INPUT_KEY_68, 'New key for edition 2018') step_page.submit_step() assert edit_page.has_text('New key for edition 2018') # The old values are still there assert edit_page.has_text('Foo 3') # Questions also have updated labels edit_page.click_edit_category('cat_1') assert step_page.has_text('Key 1 (edition 2018):') step_page.submit_step() # The old values are still there assert edit_page.has_text('Foo 3') # The user submits the version edit_page.submit_questionnaire() # The version is reviewed (in DB) new_version.status = settings.QUESTIONNAIRE_PUBLIC new_version.save() # The new public version does not have a hint about new editions detail_page.open() assert not detail_page.has_new_edition()
def test_edit_public(self): code = 'sample_3' user = User.objects.get(pk=101) old_text = 'Faz 3' new_text = 'asdf' # User logs in and goes to the detail page of a "public" Questionnaire detail_page = SampleDetailPage(self) detail_page.route_kwargs = {'identifier': code} detail_page.open(login=True, user=user) assert code in self.browser.current_url assert detail_page.has_text(old_text) assert not detail_page.has_text(new_text) # There is only one version of this questionnaire in the db assert Questionnaire.objects.filter(code=code).count() == 1 # User uses the direct link to go to the edit page of the questionnaire # and sees no new version of the questionnaire is created in the DB. # This prevents the issue when new versions were created upon GET of the # edit page, which should be fixed now. edit_page = SampleEditPage(self) edit_page.route_kwargs = {'identifier': code} edit_page.open() assert Questionnaire.objects.filter(code=code).count() == 1 # User edits the Questionnaire (creates a new version) and sees that # the URL contains the code of the Questionnaire detail_page.open() detail_page.create_new_version() assert code in self.browser.current_url # User edits a category and sees that the URL still contains the # code of the Questionnaire edit_page.click_edit_category('cat_2') assert code in self.browser.current_url # User makes some changes and submits the category step_page = SampleStepPage(self) step_page.enter_text(step_page.LOC_FORM_INPUT_KEY_5, new_text, clear=True) step_page.submit_step() # User is back on the overview page and sees that the URL still # contains the code of the Questionnaire assert code in self.browser.current_url assert edit_page.has_text(code) # She sees that the value of Key 1 was updated assert not edit_page.has_text(old_text) assert edit_page.has_text(new_text) # Also there was an additional version created in the database assert Questionnaire.objects.count() == 11 # The newly created version has the same code assert Questionnaire.objects.filter(code=code).count() == 2 # She goes to see her own questionnaire and sees sample_3 appears only # once my_page = MyDataPage(self) my_page.open() my_page.wait_for_lists() expected_list = [ { 'description': new_text, }, { # Just to check that description is there ... 'description': 'Faz 1' }, # ... the rest does not really matter ] assert my_page.count_list_results() == 6 my_page.check_list_results(expected_list, count=False) # She clicks the first entry and sees that she is taken to the # details page of the latest (pending) version. my_page.click_list_entry(index=0) assert detail_page.has_text(new_text)