Exemplo n.º 1
0
    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'
            },
        ])
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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