def test_remove_file(self): conn = boto.connect_s3() bucket = conn.create_bucket('mybucket') key = Key(bucket) key.key = "submissions_attachments/foo" key.set_contents_from_string("Test") result = api.remove_file("foo") self.assertTrue(result) result = api.remove_file("foo") self.assertFalse(result)
def test_remove_file(self): conn = boto.connect_s3() bucket = conn.create_bucket('mybucket') key = Key(bucket) key.key = "submissions_attachments/foo" key.set_contents_from_string("Test") result = api.remove_file("foo") self.assertTrue(result) result = api.remove_file("foo") self.assertFalse(result)
def test_remove_file(self): conn = boto3.client("s3") conn.create_bucket(Bucket="mybucket") conn.put_object(Bucket="mybucket", Key="submissions_attachments/foo", Body=b"Test") result = api.remove_file("foo") self.assertTrue(result) result = api.remove_file("foo") self.assertFalse(result)
def clear_student_state(self, user_id, course_id, item_id, requesting_user_id): """ This xblock method is called (from our LMS runtime, which defines this method signature) to clear student state for a given problem. It will cancel the workflow using traditional methods to remove it from the grading pools, and pass through to the submissions API to orphan the submission so that the user can create a new one. """ # Import is placed here to avoid model import at project startup. from submissions import api as submission_api # Note that student_item cannot be constructed using get_student_item_dict, since we're in a staff context student_item = { 'course_id': course_id, 'student_id': user_id, 'item_id': item_id, 'item_type': 'openassessment', } submissions = submission_api.get_submissions(student_item) if self.is_team_assignment(): self.clear_team_state(user_id, course_id, item_id, requesting_user_id, submissions) else: # There *should* only be one submission, but the logic is easy to extend for multiples so we may as well for sub in submissions: # Remove the submission from grading pools self._cancel_workflow(sub['uuid'], "Student state cleared", requesting_user_id=requesting_user_id) # Delete files from the backend if 'file_keys' in sub['answer']: for key in sub['answer']['file_keys']: remove_file(key) # Tell the submissions API to orphan the submission to prevent it from being accessed submission_api.reset_score(user_id, course_id, item_id, clear_state=True)
def remove_all_uploaded_files(self, data, suffix=''): # pylint: disable=unused-argument """ Removes all uploaded user files. """ removed_num = 0 for i in range(self.MAX_FILES_COUNT): removed = file_upload_api.remove_file(self._get_student_item_key(i)) if removed: removed_num += 1 else: break return {'success': True, 'removed_num': removed_num}
def remove_all_uploaded_files(self, data, suffix=''): # pylint: disable=unused-argument """ Removes all uploaded user files. """ removed_num = 0 for i in range(self.MAX_FILES_COUNT): removed = file_upload_api.remove_file(self._get_student_item_key(i)) if removed: removed_num += 1 else: break return {'success': True, 'removed_num': removed_num}