diff --git a/scratchattach/site/project.py b/scratchattach/site/project.py index 60f28232..b2061edc 100644 --- a/scratchattach/site/project.py +++ b/scratchattach/site/project.py @@ -619,11 +619,12 @@ def share(self): Shares the project. You can only use this function if this object was created using :meth:`scratchattach.session.Session.connect_project` """ self._assert_permission() - requests.put( - f"https://api.scratch.mit.edu/proxy/projects/{self.id}/share/", - headers=self._json_headers, - cookies=self._cookies, - ) + with requests.no_error_handling(): + requests.put( + f"https://api.scratch.mit.edu/proxy/projects/{self.id}/share/", + headers=self._json_headers, + cookies=self._cookies, + ) def unshare(self): """ diff --git a/tests/test_project.py b/tests/test_project.py index 1788ccee..2e47ac66 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -2,6 +2,32 @@ from util import session, credentials_available, allow_before import scratchattach as sa from datetime import datetime +from scratchattach.site.project import Project + + +def test_project_share_disables_response_json_error_handling(monkeypatch): + # Regression for #609: a shared response with a non-JSON body must not trip + # the response checker, so share() should run the PUT with error_handling + # disabled and restore it afterwards. + class FakeSession: + username = "ScratchAttachV2" + + def get_headers(self): + return {"x-token": "token"} + + def get_cookies(self): + return {"scratchsessionsid": "session"} + + flag_during = [] + + def fake_put(*args, **kwargs): + flag_during.append(sa.utils.requests.requests.error_handling) + + monkeypatch.setattr(sa.utils.requests.requests, "put", fake_put) + Project(id=123, author_name="ScratchAttachV2", _session=FakeSession()).share() + + assert flag_during == [False] # disabled during the PUT + assert sa.utils.requests.requests.error_handling is True # restored after def test_project():