diff --git a/edx_sga/tests/test_sga.py b/edx_sga/tests/test_sga.py index 03bfb94a..52b1aebb 100644 --- a/edx_sga/tests/test_sga.py +++ b/edx_sga/tests/test_sga.py @@ -197,7 +197,7 @@ def test_student_view(self, fragment, render_template): """ block = self.make_xblock("Custom name") - with mock.patch( + with (mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.get_submission", return_value={} ), mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.student_state", @@ -208,7 +208,7 @@ def test_student_view(self, fragment, render_template): "max_score": 100, "graded": None, }, - ): + )): fragment = block.student_view() assert render_template.called is True template_arg = render_template.call_args[0][0] @@ -247,18 +247,18 @@ def test_student_view_with_score( block.comment = "ok" with self.dummy_upload("foo.txt") as (upload, _): - with mock.patch( + with (mock.patch( "submissions.api.create_submission", ) as mocked_create_submission, mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.student_state", return_value={} ), mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.get_or_create_student_module", return_value=fake_student_module(), - ): + )): block.upload_assignment(mock.Mock(params={"assignment": upload})) assert mocked_create_submission.called is True - with mock.patch( + with (mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.get_submission", return_value=fake_upload_submission(upload), ), mock.patch( @@ -268,7 +268,7 @@ def test_student_view_with_score( "uploaded": {"filename": "foo.txt"}, "max_score": 100, }, - ): + )): fragment = block.student_view() assert render_template.called is True template_arg = render_template.call_args[0][0] @@ -414,23 +414,23 @@ def test_upload_download_assignment( assert mocked_create_submission.called is True assert mocked_create_student_module.called is True - with mock.patch( + with (mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.get_submission", return_value=fake_upload_submission(upload), ), mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.file_storage_path", return_value=block.file_storage_path(SHA1, file_name), - ): + )): response = block.download_assignment(None) assert response.body == expected - with mock.patch( + with (mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.file_storage_path", return_value=block.file_storage_path("", "test_notfound.txt"), ), mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.get_submission", return_value=fake_upload_submission(upload), - ): + )): response = block.download_assignment(None) assert response.status_code == 404 @@ -463,14 +463,14 @@ def test_finalize_uploaded_assignment( answer=fake_submission_data["answer"], ) - with mock.patch( + with (mock.patch( "edx_sga.sga.Submission.objects.get", return_value=fake_submission_object ), mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.get_submission", return_value=fake_submission_data, ), mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.student_state", return_value={} - ): + )): block.finalize_uploaded_assignment(mock.Mock()) assert fake_submission_object.answer["finalized"] is True @@ -494,10 +494,10 @@ def test_staff_upload_download_annotated( file_name = "test.txt" block = self.make_xblock() - with self.dummy_upload(file_name) as (upload, expected), mock.patch( + with (self.dummy_upload(file_name) as (upload, expected), mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.staff_grading_data", return_value={}, - ) as staff_grading_data: + ) as staff_grading_data): block.staff_upload_annotated( mock.Mock(params={"annotated": upload, "module_id": 1}) ) @@ -575,14 +575,14 @@ def test_staff_download( get_sha1.return_value = SHA1 block = self.make_xblock() - with self.dummy_upload("test.txt") as (upload, expected), mock.patch( + with (self.dummy_upload("test.txt") as (upload, expected), mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.student_state", return_value={} ), mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.get_or_create_student_module", return_value=fake_student_module(), ), mock.patch( "submissions.api.create_submission" - ) as mocked_create_submission: + ) as mocked_create_submission): block.upload_assignment(mock.Mock(params={"assignment": upload})) assert mocked_create_submission.called is True self.personalize_upload(block, upload) @@ -594,13 +594,13 @@ def test_staff_download( response = block.staff_download(mock.Mock(params={"student_id": 1})) assert response.body == expected - with mock.patch( + with (mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.file_storage_path", return_value=block.file_storage_path("", "test_notfound.txt"), ), mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.get_submission", return_value=fake_upload_submission(upload), - ): + )): response = block.staff_download(mock.Mock(params={"student_id": 1})) assert response.status_code == 404 @@ -638,13 +638,13 @@ def test_upload_allowed( Tests that upload_allowed returns the right value under certain conditions """ block = self.make_xblock() - with mock.patch( + with (mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.past_due", return_value=past_due ), mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.get_score", return_value=score ), mock.patch( "edx_sga.sga.is_finalized_submission", return_value=is_finalized_submission - ): + )): assert block.upload_allowed(submission_data={}) is expected_value @mock.patch("edx_sga.sga.StaffGradedAssignmentXBlock.count_archive_files") @@ -674,7 +674,7 @@ def test_prepare_download_submissions( for __ in range(2) ] zip_student_submissions.delay = mock.Mock() - with mock.patch( + with (mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.is_zip_file_available", return_value=is_zip_file_available, ), mock.patch( @@ -683,7 +683,7 @@ def test_prepare_download_submissions( ), mock.patch( "edx_sga.utils.default_storage.get_modified_time", return_value=datetime.datetime.now(), - ): + )): response = block.prepare_download_submissions(None) response_body = json.loads(response.body.decode("utf-8")) assert response_body["downloadable"] is downloadable @@ -720,7 +720,7 @@ def test_prepare_download_submissions_when_student_score_reset( ] get_file_modified_time_utc.return_value = now zip_student_submissions.delay = mock.Mock() - with mock.patch( + with (mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.is_zip_file_available", return_value=True, ), mock.patch( @@ -729,7 +729,7 @@ def test_prepare_download_submissions_when_student_score_reset( ), mock.patch( "edx_sga.utils.default_storage.get_modified_time", return_value=datetime.datetime.now(), - ): + )): response = block.prepare_download_submissions(None) response_body = json.loads(response.body.decode("utf-8")) assert response_body["downloadable"] is downloadable @@ -753,7 +753,7 @@ def test_prepare_download_submissions_task_called( for __ in range(2) ] zip_student_submissions.delay = mock.Mock() - with mock.patch( + with (mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.is_zip_file_available", return_value=False, ), mock.patch( @@ -762,7 +762,7 @@ def test_prepare_download_submissions_task_called( ), mock.patch( "edx_sga.sga.default_storage.get_modified_time", return_value=datetime.datetime.now(), - ): + )): response = block.prepare_download_submissions(None) response_body = json.loads(response.body.decode("utf-8")) assert response_body["downloadable"] is False @@ -799,10 +799,10 @@ def test_download_submissions(self, is_course_staff): with open(path, "wb") as temp_file: temp_file.write(expected) - with mock.patch("edx_sga.sga.get_zip_file_path", return_value=path), mock.patch( + with (mock.patch("edx_sga.sga.get_zip_file_path", return_value=path), mock.patch( "edx_sga.sga.StaffGradedAssignmentXBlock.get_real_user", return_value=self.staff, - ), mock.patch("edx_sga.sga.get_zip_file_name", return_value=filename): + ), mock.patch("edx_sga.sga.get_zip_file_name", return_value=filename)): response = block.download_submissions(None) assert response.status_code == 200 assert response.body == expected @@ -815,12 +815,12 @@ def test_clear_student_state(self): uploaded_file_path = block.file_storage_path(SHA1, orig_file_name) with self.dummy_file_in_storage(uploaded_file_path) as file_path: - with mock.patch( + with (mock.patch( "edx_sga.sga.submissions_api.get_submissions", return_value=[fake_submission], ) as mocked_get_submissions, mock.patch( "edx_sga.sga.submissions_api.reset_score" - ) as mocked_reset_score: + ) as mocked_reset_score): assert self.default_storage.exists(file_path) is True block.clear_student_state(user_id=123) assert mocked_get_submissions.called is True