def setUp(self): super().setUp() for username in [ USERNAME_1, USERNAME_2, STAFF_USER_1, STAFF_USER_2, SUPERUSER_USERNAME ]: UserFactory.create(username=username) self.mock_block = Mock(**MOCK_BLOCK_KWARGS) def mock_anonymous_id_for_user(user, course_id): # pylint: disable=unused-argument return anonymous_user_id(user.username) read_config_patcher = patch.object(Command, 'read_config_file', return_value=CONFIG_1) anonymous_id_for_user_patcher = patch( 'openassessment.management.commands.create_oa_submissions_from_file.anonymous_id_for_user', side_effect=mock_anonymous_id_for_user) self.mock_store = Mock() self.mock_store.get_items.return_value = [self.mock_block] modulestore_patcher = patch( 'openassessment.management.commands.create_oa_submissions_from_file.modulestore', return_value=self.mock_store) call_command_patcher = patch( 'openassessment.management.commands.create_oa_submissions_from_file.call_command' ) self.patchers = [ read_config_patcher, anonymous_id_for_user_patcher, modulestore_patcher, call_command_patcher ] self.read_config_mock = read_config_patcher.start() self.anonymous_id_for_user_mock = anonymous_id_for_user_patcher.start() self.modulestore_mock = modulestore_patcher.start() self.call_command_mock = call_command_patcher.start()
def _setup_xblock_and_create_team_submission(self, xblock): """ A shortcut method to setup ORA xblock and add a user submission or a team submission to the block. """ xblock.xmodule_runtime = self._create_mock_runtime( xblock.scope_ids.usage_id, True, False, 'Bob') # pylint: disable=protected-access xblock.runtime._services['user'] = NullUserService() xblock.runtime._services['user_state'] = UserStateService() xblock.runtime._services['teams'] = MockTeamsService(True) usage_id = xblock.scope_ids.usage_id xblock.location = usage_id xblock.user_state_upload_data_enabled = Mock(return_value=True) student_item = STUDENT_ITEM.copy() student_item["item_id"] = usage_id xblock.is_team_assignment = Mock(return_value=True) anonymous_user_ids_for_team = ['Bob', 'Alice', 'Chris'] xblock.get_anonymous_user_ids_for_team = Mock( return_value=anonymous_user_ids_for_team) arbitrary_test_user = UserFactory.create() return self._create_team_submission( STUDENT_ITEM['course_id'], usage_id, MOCK_TEAM_ID, arbitrary_test_user.id, anonymous_user_ids_for_team, "this is an answer to a team assignment", )
def test_load_anonymous_user_ids__missing(self): """ Test for when we are unable to find an anonymous_user_id for a username """ def mock_anonymous_id_for_user(user, course_id): # pylint: disable=unused-argument return user.username + "_anonymous" for username in [ USERNAME_1, USERNAME_2, STAFF_USER_1, STAFF_USER_2, SUPERUSER_USERNAME ]: UserFactory.create(username=username) expected_error = 'Unable to load anonymous id for user(s) user_not_found' with patch( 'openassessment.management.commands.create_oa_submissions_from_file.anonymous_id_for_user', return_value=mock_anonymous_id_for_user): with self.assertRaisesMessage(CommandError, expected_error): self.cmd.load_anonymous_user_ids( COURSE_ID, {USERNAME_1, USERNAME_2, 'user_not_found'})
def setUpClass(cls): super().setUpClass() # Set up users that will be used (and unmodified) across tests cls.staff_user = UserFactory.create() cls.staff_user.is_staff = True cls.staff_user.save() cls.other_staff_user = UserFactory.create() cls.other_staff_user.is_staff = True cls.other_staff_user.save() cls.non_staff_user = UserFactory.create() cls.non_staff_user.is_staff = False cls.non_staff_user.save() # Authenticate users - Fun fact, that's a Django typo :shrug: cls.staff_user.is_athenticated = True cls.other_staff_user.is_athenticated = True cls.non_staff_user.is_athenticated = True
def setUpTestData(cls): super().setUpTestData() # Users for testing staff_user = UserFactory.create() staff_user.is_staff = True staff_user.save() cls.staff_user_id = staff_user.id cls.submitting_user_id = UserFactory.create().id team_member_1_id = UserFactory.create().id team_member_2_id = UserFactory.create().id user_ids = [cls.submitting_user_id, team_member_1_id, team_member_2_id] cls.team_member_ids = ['anon_id_for_{}'.format(user_id) for user_id in user_ids] cls.default_assessment = ( cls.staff_user_id, # scorer_id OPTIONS_SELECTED_DICT["few"]["options"], # options_selected dict(), # critereon_feedback '', # overall_feedback RUBRIC # rubric_dict )
def _create_submission(self): """ Create a test team submission through the submissions api """ self.users = [UserFactory.create() for _ in range(5)] self.team_submission_dict = sub_team_api.create_submission_for_team( self.course_id, self.item_id, 'team-rocket', self.users[0].id, [user.id for user in self.users], 'this-is-my-answer', ) self.team_submission_uuid = self.team_submission_dict['team_submission_uuid'] self.submission_uuids = self.team_submission_dict['submission_uuids']