Пример #1
0
    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
Пример #2
0
    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
            }
        ])
Пример #3
0
    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()
Пример #4
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