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