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_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_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_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_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_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_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_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_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_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_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, )