コード例 #1
0
ファイル: test_users.py プロジェクト: baggids/qcat
    def test_add_user(self, 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

        # User logs in and goes to the questionnaire step where he can add a
        # user.
        new_page = SampleNewPage(self)
        new_page.open(login=True, user=self.user_alice)
        new_page.click_edit_category('cat_0')

        # The field to search a user is not visible.
        step_page = SampleStepPage(self)
        search_field = step_page.get_user_search_field(index=1)
        assert not search_field.is_displayed()

        # She clicks the radio to search for an existing user
        step_page.get_el(step_page.LOC_RADIO_SEARCH_USER).click()

        # Now the search field is visible
        assert search_field.is_displayed()

        # There is no loading indicator
        loading_indicator = step_page.get_el(step_page.LOC_LOADING_SEARCH_USER)
        assert not loading_indicator.is_displayed()

        # She enters a name and sees a search is conducted
        search_field.send_keys(self.user_bob.firstname)
        step_page.select_autocomplete(self.user_bob.get_display_name())

        # She sees a loading indicator while the user is updated in the DB
        assert loading_indicator.is_displayed()

        # She waits until the loading indicator disappears
        step_page.wait_for(step_page.LOC_LOADING_SEARCH_USER, visibility=False)

        # She sees that the search field is not visible anymore
        assert not search_field.is_displayed()

        # She sees that a field with the name was added
        assert step_page.has_selected_user(self.user_bob)

        # She sees that the user ID was added to the hidden field
        assert step_page.get_selected_user_id() == str(self.user_bob.pk)

        # She removes the user
        step_page.remove_selected_user(self.user_bob)

        # The user is removed and the search box is visible again
        assert not step_page.has_selected_user(self.user_bob)
        assert search_field.is_displayed()

        # She hidden field does not contain the ID anymore
        assert step_page.get_selected_user_id() == ''

        # She selects the user again
        step_page.select_user(self.user_bob)

        # She submits the step
        step_page.submit_step()

        # She sees the name is in the overview
        edit_page = SampleEditPage(self)
        assert edit_page.has_text(self.user_bob.get_display_name())

        # She goes back to the form
        edit_page.click_edit_category('cat_0')

        # She sees the user is selected, loading and search fields are
        # not visible
        step_page.wait_for(step_page.LOC_LOADING_SEARCH_USER, visibility=False)
        assert step_page.has_selected_user(self.user_bob)
        assert step_page.get_selected_user_id() == str(self.user_bob.pk)

        # She removes the user and selects another one
        step_page.remove_selected_user(self.user_bob)
        step_page.select_user(self.user_chris)

        # She submits the step
        step_page.submit_step()
        assert edit_page.has_text(self.user_chris.get_display_name())

        # She submits the entire questionnaire and sees the name is there
        edit_page.submit_questionnaire()
        assert edit_page.has_text(self.user_chris.get_display_name())

        # She checks the database to make sure the user was added.
        questionnaire = Questionnaire.objects.first()
        questionnaire_users = sorted(questionnaire.get_users(),
                                     key=lambda u: (u[0], u[1].pk))
        assert questionnaire_users == [('compiler', self.user_alice),
                                       ('landuser', self.user_chris)]
コード例 #2
0
ファイル: test_users.py プロジェクト: CDE-UNIBE/qcat
    def test_add_user(self, 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

        # User logs in and goes to the questionnaire step where he can add a
        # user.
        new_page = SampleNewPage(self)
        new_page.open(login=True, user=self.user_alice)
        new_page.click_edit_category('cat_0')

        # The field to search a user is not visible.
        step_page = SampleStepPage(self)
        search_field = step_page.get_user_search_field(index=1)
        assert not search_field.is_displayed()

        # She clicks the radio to search for an existing user
        step_page.get_el(step_page.LOC_RADIO_SEARCH_USER).click()

        # Now the search field is visible
        assert search_field.is_displayed()

        # There is no loading indicator
        loading_indicator = step_page.get_el(step_page.LOC_LOADING_SEARCH_USER)
        assert not loading_indicator.is_displayed()

        # She enters a name and sees a search is conducted
        search_field.send_keys(self.user_bob.firstname)
        step_page.select_autocomplete(self.user_bob.get_display_name())

        # She sees a loading indicator while the user is updated in the DB
        assert loading_indicator.is_displayed()

        # She waits until the loading indicator disappears
        step_page.wait_for(step_page.LOC_LOADING_SEARCH_USER, visibility=False)

        # She sees that the search field is not visible anymore
        assert not search_field.is_displayed()

        # She sees that a field with the name was added
        assert step_page.has_selected_user(self.user_bob)

        # She sees that the user ID was added to the hidden field
        assert step_page.get_selected_user_id() == str(self.user_bob.pk)

        # She removes the user
        step_page.remove_selected_user(self.user_bob)

        # The user is removed and the search box is visible again
        assert not step_page.has_selected_user(self.user_bob)
        assert search_field.is_displayed()

        # She hidden field does not contain the ID anymore
        assert step_page.get_selected_user_id() == ''

        # She selects the user again
        step_page.select_user(self.user_bob)

        # She submits the step
        step_page.submit_step()

        # She sees the name is in the overview
        edit_page = SampleEditPage(self)
        assert edit_page.has_text(self.user_bob.get_display_name())

        # She goes back to the form
        edit_page.click_edit_category('cat_0')

        # She sees the user is selected, loading and search fields are
        # not visible
        step_page.wait_for(step_page.LOC_LOADING_SEARCH_USER, visibility=False)
        assert step_page.has_selected_user(self.user_bob)
        assert step_page.get_selected_user_id() == str(self.user_bob.pk)

        # She removes the user and selects another one
        step_page.remove_selected_user(self.user_bob)
        step_page.select_user(self.user_chris)

        # She submits the step
        step_page.submit_step()
        assert edit_page.has_text(self.user_chris.get_display_name())

        # She submits the entire questionnaire and sees the name is there
        edit_page.submit_questionnaire()
        assert edit_page.has_text(self.user_chris.get_display_name())

        # She checks the database to make sure the user was added.
        questionnaire = Questionnaire.objects.first()
        questionnaire_users = sorted(
            questionnaire.get_users(), key=lambda u: (u[0], u[1].pk))
        assert questionnaire_users == [
            ('compiler', self.user_alice),
            ('landuser', self.user_chris)
        ]
コード例 #3
0
ファイル: test_editions.py プロジェクト: baggids/qcat
    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()
コード例 #4
0
ファイル: test_editions.py プロジェクト: CDE-UNIBE/qcat
    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()
コード例 #5
0
ファイル: test_edit.py プロジェクト: CDE-UNIBE/qcat
    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'))
コード例 #6
0
ファイル: test_moderation.py プロジェクト: CDE-UNIBE/qcat
    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,
        )
コード例 #7
0
    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'))