diff --git a/news/1302.bugfix b/news/1302.bugfix new file mode 100644 index 0000000000..bd20ae275f --- /dev/null +++ b/news/1302.bugfix @@ -0,0 +1,3 @@ +Resolve the bulk of deprecation and resource leak warnings when running the full test +suite. +[rpatterson] diff --git a/src/plone/restapi/testing.py b/src/plone/restapi/testing.py index 4466101467..303eed97cc 100644 --- a/src/plone/restapi/testing.py +++ b/src/plone/restapi/testing.py @@ -253,12 +253,29 @@ class RelativeSession(requests.Session): base if their URL is relative (doesn't begin with a HTTP[S] scheme). """ - def __init__(self, base_url): + def __init__(self, base_url, test=None): + """ + Capture the base URL. Optionally also capture a test case for cleanup. + + Apparently, network sockets created by the `requests` library can remain open + even after the full body of the response has been read, despite [the + docs](https://docs.python-requests.org/en/latest/user/advanced/#body-content-workflow). In + particular, this results in `ResourceWarning: unclosed ` leak + warnings when running the tests. If the `test` kwarg is passed, it will be used + to register future cleanup calls to close this session and thus also the + sockets. If passed, it must be an object with a `addCleanup(func)` callable + attribute, such as instances of `unittest.TestCase`. + """ super().__init__() + if not base_url.endswith("/"): base_url += "/" self.__base_url = base_url + if hasattr(test, "addCleanup"): + # Avoid `ResourceWarning: unclosed ` + test.addCleanup(self.close) + def request(self, method, url, **kwargs): if urlparse(url).scheme not in ("http", "https"): url = url.lstrip("/") diff --git a/src/plone/restapi/tests/test_addons.py b/src/plone/restapi/tests/test_addons.py index 47149a4911..9fd449e7ee 100644 --- a/src/plone/restapi/tests/test_addons.py +++ b/src/plone/restapi/tests/test_addons.py @@ -22,7 +22,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_batching.py b/src/plone/restapi/tests/test_batching.py index 27c842238c..810846298c 100644 --- a/src/plone/restapi/tests/test_batching.py +++ b/src/plone/restapi/tests/test_batching.py @@ -24,7 +24,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() self.request = self.portal.REQUEST - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_blocks_searchable_text.py b/src/plone/restapi/tests/test_blocks_searchable_text.py index 9867a371c5..e979dce99c 100644 --- a/src/plone/restapi/tests/test_blocks_searchable_text.py +++ b/src/plone/restapi/tests/test_blocks_searchable_text.py @@ -29,7 +29,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_content_blocks.py b/src/plone/restapi/tests/test_content_blocks.py index e8915ad4bd..0dbf2e2359 100644 --- a/src/plone/restapi/tests/test_content_blocks.py +++ b/src/plone/restapi/tests/test_content_blocks.py @@ -22,7 +22,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_copymove.py b/src/plone/restapi/tests/test_copymove.py index 07edcb86c8..0748c8be27 100644 --- a/src/plone/restapi/tests/test_copymove.py +++ b/src/plone/restapi/tests/test_copymove.py @@ -82,7 +82,7 @@ def setUp(self): email="memberuser@example.com", username="memberuser", password="secret" ) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_documentation.py b/src/plone/restapi/tests/test_documentation.py index f98578ff84..fe6d391de1 100644 --- a/src/plone/restapi/tests/test_documentation.py +++ b/src/plone/restapi/tests/test_documentation.py @@ -178,7 +178,7 @@ def setUp(self): pushGlobalRegistry(getSite()) register_static_uuid_utility(prefix="SomeUUID") - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) @@ -794,7 +794,7 @@ def test_documentation_users(self): save_request_and_response_for_docs("users", response) def test_documentation_users_as_anonymous(self): - logged_out_api_session = RelativeSession(self.portal_url) + logged_out_api_session = RelativeSession(self.portal_url, test=self) logged_out_api_session.headers.update({"Accept": "application/json"}) response = logged_out_api_session.get("@users") @@ -819,7 +819,7 @@ def test_documentations_users_as_unauthorized_user(self): ) transaction.commit() - standard_api_session = RelativeSession(self.portal_url) + standard_api_session = RelativeSession(self.portal_url, test=self) standard_api_session.headers.update({"Accept": "application/json"}) standard_api_session.auth = ("noam", "password") @@ -858,7 +858,7 @@ def test_documentation_users_anonymous_get(self): ) transaction.commit() - logged_out_api_session = RelativeSession(self.portal_url) + logged_out_api_session = RelativeSession(self.portal_url, test=self) logged_out_api_session.headers.update({"Accept": "application/json"}) response = logged_out_api_session.get("@users/noam") @@ -890,7 +890,7 @@ def test_documentation_users_unauthorized_get(self): transaction.commit() - logged_out_api_session = RelativeSession(self.portal_url) + logged_out_api_session = RelativeSession(self.portal_url, test=self) logged_out_api_session.headers.update({"Accept": "application/json"}) logged_out_api_session.auth = ("noam-fake", "secret") @@ -915,7 +915,7 @@ def test_documentation_users_authorized_get(self): ) transaction.commit() - logged_out_api_session = RelativeSession(self.portal_url) + logged_out_api_session = RelativeSession(self.portal_url, test=self) logged_out_api_session.headers.update({"Accept": "application/json"}) logged_out_api_session.auth = ("noam", "secret") response = logged_out_api_session.get("@users/noam") diff --git a/src/plone/restapi/tests/test_error_handling.py b/src/plone/restapi/tests/test_error_handling.py index ee6fd80dd8..58e837bed8 100644 --- a/src/plone/restapi/tests/test_error_handling.py +++ b/src/plone/restapi/tests/test_error_handling.py @@ -37,7 +37,7 @@ def setUp(self): self.portal = self.layer["portal"] self.portal_url = self.portal.absolute_url() - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_expansion.py b/src/plone/restapi/tests/test_expansion.py index a7bb8b7c7f..c6daef78a4 100644 --- a/src/plone/restapi/tests/test_expansion.py +++ b/src/plone/restapi/tests/test_expansion.py @@ -115,7 +115,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) @@ -421,7 +421,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_functional_auth.py b/src/plone/restapi/tests/test_functional_auth.py index e1b0a4d99c..59b8b31dec 100644 --- a/src/plone/restapi/tests/test_functional_auth.py +++ b/src/plone/restapi/tests/test_functional_auth.py @@ -68,6 +68,7 @@ def test_api_login_grants_zmi(self): Logging in via the API also grants access to the Zope root ZMI. """ session = requests.Session() + self.addCleanup(session.close) login_resp = session.post( self.portal_url + "/@login", headers={"Accept": "application/json"}, @@ -112,6 +113,7 @@ def test_zmi_login_grants_api(self): Logging in via the Zope root ZMI also grants access to the API. """ session = requests.Session() + self.addCleanup(session.close) basic_auth_headers = { "Authorization": "Basic {}".format( base64.b64encode( @@ -161,6 +163,7 @@ def test_cookie_login_grants_api(self): Logging in via the Plone login form also grants access to the API. """ session = requests.Session() + self.addCleanup(session.close) challenge_resp = session.get(self.private_document_url) self.assertEqual( challenge_resp.status_code, diff --git a/src/plone/restapi/tests/test_locking.py b/src/plone/restapi/tests/test_locking.py index ed18cc8d45..191b4d6bd8 100644 --- a/src/plone/restapi/tests/test_locking.py +++ b/src/plone/restapi/tests/test_locking.py @@ -25,7 +25,7 @@ def setUp(self): ] alsoProvides(self.doc, ITTWLockable) - self.api_session = RelativeSession(self.doc.absolute_url()) + self.api_session = RelativeSession(self.doc.absolute_url(), test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_permissions.py b/src/plone/restapi/tests/test_permissions.py index cbeddfaedd..917ab4a588 100644 --- a/src/plone/restapi/tests/test_permissions.py +++ b/src/plone/restapi/tests/test_permissions.py @@ -19,7 +19,7 @@ def setUp(self): self.portal = self.layer["portal"] self.portal_url = self.portal.absolute_url() - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (TEST_USER_NAME, TEST_USER_PASSWORD) diff --git a/src/plone/restapi/tests/test_registry.py b/src/plone/restapi/tests/test_registry.py index 90461ce9df..d66936ba6e 100644 --- a/src/plone/restapi/tests/test_registry.py +++ b/src/plone/restapi/tests/test_registry.py @@ -23,7 +23,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_roles.py b/src/plone/restapi/tests/test_roles.py index eaeb6d272c..8946e1d134 100644 --- a/src/plone/restapi/tests/test_roles.py +++ b/src/plone/restapi/tests/test_roles.py @@ -14,7 +14,7 @@ def setUp(self): self.portal = self.layer["portal"] self.portal_url = self.portal.absolute_url() - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_search.py b/src/plone/restapi/tests/test_search.py index 49c08c5d19..5283302128 100644 --- a/src/plone/restapi/tests/test_search.py +++ b/src/plone/restapi/tests/test_search.py @@ -39,7 +39,7 @@ def setUp(self): self.request = self.portal.REQUEST self.catalog = getToolByName(self.portal, "portal_catalog") - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services.py b/src/plone/restapi/tests/test_services.py index 6ef7c67d46..8e009f0354 100644 --- a/src/plone/restapi/tests/test_services.py +++ b/src/plone/restapi/tests/test_services.py @@ -28,7 +28,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_actions.py b/src/plone/restapi/tests/test_services_actions.py index de643e0f2e..87eb9c9d37 100644 --- a/src/plone/restapi/tests/test_services_actions.py +++ b/src/plone/restapi/tests/test_services_actions.py @@ -46,11 +46,11 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) - self.anon_api_session = RelativeSession(self.portal_url) + self.anon_api_session = RelativeSession(self.portal_url, test=self) self.anon_api_session.headers.update({"Accept": "application/json"}) self.portal_actions = api.portal.get_tool(name="portal_actions") diff --git a/src/plone/restapi/tests/test_services_breadcrumbs.py b/src/plone/restapi/tests/test_services_breadcrumbs.py index 8d775f8b45..54e7471bc0 100644 --- a/src/plone/restapi/tests/test_services_breadcrumbs.py +++ b/src/plone/restapi/tests/test_services_breadcrumbs.py @@ -26,7 +26,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) @@ -71,7 +71,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() self.request = self.layer["request"] - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_comments.py b/src/plone/restapi/tests/test_services_comments.py index dbdffc0c0f..9422b4dbda 100644 --- a/src/plone/restapi/tests/test_services_comments.py +++ b/src/plone/restapi/tests/test_services_comments.py @@ -41,12 +41,12 @@ def setUp(self): api.user.create(username="jos", password="josjos", email="jos@plone.org") # Admin session - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) # User session - self.user_session = RelativeSession(self.portal_url) + self.user_session = RelativeSession(self.portal_url, test=self) self.user_session.headers.update({"Accept": "application/json"}) self.user_session.auth = ("jos", "jos") diff --git a/src/plone/restapi/tests/test_services_content.py b/src/plone/restapi/tests/test_services_content.py index 8b210115de..bf6377b369 100644 --- a/src/plone/restapi/tests/test_services_content.py +++ b/src/plone/restapi/tests/test_services_content.py @@ -19,7 +19,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_contextnavigation.py b/src/plone/restapi/tests/test_services_contextnavigation.py index d016131af0..de7341a212 100644 --- a/src/plone/restapi/tests/test_services_contextnavigation.py +++ b/src/plone/restapi/tests/test_services_contextnavigation.py @@ -36,7 +36,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_controlpanel_dexterity_types.py b/src/plone/restapi/tests/test_services_controlpanel_dexterity_types.py index 4e2ca1a05a..92eda72f87 100644 --- a/src/plone/restapi/tests/test_services_controlpanel_dexterity_types.py +++ b/src/plone/restapi/tests/test_services_controlpanel_dexterity_types.py @@ -18,7 +18,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_controlpanels.py b/src/plone/restapi/tests/test_services_controlpanels.py index 8b5411b9f2..1387bb0aec 100644 --- a/src/plone/restapi/tests/test_services_controlpanels.py +++ b/src/plone/restapi/tests/test_services_controlpanels.py @@ -19,7 +19,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_database.py b/src/plone/restapi/tests/test_services_database.py index eab79a8f7e..1cd45ce06c 100644 --- a/src/plone/restapi/tests/test_services_database.py +++ b/src/plone/restapi/tests/test_services_database.py @@ -18,7 +18,7 @@ def setUp(self): self.request = self.portal.REQUEST self.catalog = getToolByName(self.portal, "portal_catalog") - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_email_notification.py b/src/plone/restapi/tests/test_services_email_notification.py index 879837cc89..f3979c6924 100644 --- a/src/plone/restapi/tests/test_services_email_notification.py +++ b/src/plone/restapi/tests/test_services_email_notification.py @@ -28,10 +28,10 @@ def setUp(self): registry["plone.email_from_address"] = "info@plone.org" registry["plone.email_from_name"] = "Plone test site" - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) - self.anon_api_session = RelativeSession(self.portal_url) + self.anon_api_session = RelativeSession(self.portal_url, test=self) self.anon_api_session.headers.update({"Accept": "application/json"}) transaction.commit() diff --git a/src/plone/restapi/tests/test_services_email_send.py b/src/plone/restapi/tests/test_services_email_send.py index 7c8706f9af..7d24d65fb9 100644 --- a/src/plone/restapi/tests/test_services_email_send.py +++ b/src/plone/restapi/tests/test_services_email_send.py @@ -28,10 +28,10 @@ def setUp(self): registry["plone.email_from_address"] = "info@plone.org" registry["plone.email_from_name"] = "Plone test site" - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) - self.anon_api_session = RelativeSession(self.portal_url) + self.anon_api_session = RelativeSession(self.portal_url, test=self) self.anon_api_session.headers.update({"Accept": "application/json"}) transaction.commit() diff --git a/src/plone/restapi/tests/test_services_groups.py b/src/plone/restapi/tests/test_services_groups.py index d7108ed19a..21e278b9a4 100644 --- a/src/plone/restapi/tests/test_services_groups.py +++ b/src/plone/restapi/tests/test_services_groups.py @@ -21,7 +21,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_history.py b/src/plone/restapi/tests/test_services_history.py index 50d36e076f..a75eb1c58e 100644 --- a/src/plone/restapi/tests/test_services_history.py +++ b/src/plone/restapi/tests/test_services_history.py @@ -23,7 +23,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) @@ -153,7 +153,7 @@ def setUp(self): api.content.transition(self.doc, "publish") self.endpoint_url = f"{self.doc.absolute_url()}/@history" - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (TEST_USER_NAME, TEST_USER_PASSWORD) # forbid access to `workflowHistory` @@ -178,7 +178,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.headers.update({"Accept-Language": "es"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_navigation.py b/src/plone/restapi/tests/test_services_navigation.py index 95ee1c9b2c..3a3c0bfad7 100644 --- a/src/plone/restapi/tests/test_services_navigation.py +++ b/src/plone/restapi/tests/test_services_navigation.py @@ -23,7 +23,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_principals.py b/src/plone/restapi/tests/test_services_principals.py index 17f41f67f5..558bd50b85 100644 --- a/src/plone/restapi/tests/test_services_principals.py +++ b/src/plone/restapi/tests/test_services_principals.py @@ -21,7 +21,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_querysources.py b/src/plone/restapi/tests/test_services_querysources.py index 7d7f8ebf97..a08f677a88 100644 --- a/src/plone/restapi/tests/test_services_querysources.py +++ b/src/plone/restapi/tests/test_services_querysources.py @@ -22,7 +22,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_querystring.py b/src/plone/restapi/tests/test_services_querystring.py index 3135438e1b..36289edef2 100644 --- a/src/plone/restapi/tests/test_services_querystring.py +++ b/src/plone/restapi/tests/test_services_querystring.py @@ -18,7 +18,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_querystringsearch.py b/src/plone/restapi/tests/test_services_querystringsearch.py index 22c7ae07c4..8dd77f7dc6 100644 --- a/src/plone/restapi/tests/test_services_querystringsearch.py +++ b/src/plone/restapi/tests/test_services_querystringsearch.py @@ -19,7 +19,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_sources.py b/src/plone/restapi/tests/test_services_sources.py index 2a55e20583..57d40b1623 100644 --- a/src/plone/restapi/tests/test_services_sources.py +++ b/src/plone/restapi/tests/test_services_sources.py @@ -22,7 +22,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_tiles.py b/src/plone/restapi/tests/test_services_tiles.py index bd37771080..eda99cc444 100644 --- a/src/plone/restapi/tests/test_services_tiles.py +++ b/src/plone/restapi/tests/test_services_tiles.py @@ -41,7 +41,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_types.py b/src/plone/restapi/tests/test_services_types.py index ab4b7a7fdd..09ba831d1b 100644 --- a/src/plone/restapi/tests/test_services_types.py +++ b/src/plone/restapi/tests/test_services_types.py @@ -22,7 +22,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) @@ -576,7 +576,7 @@ def setUp(self): self.portal = self.layer["portal"] self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.headers.update({"Accept-Language": "es"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_services_users.py b/src/plone/restapi/tests/test_services_users.py index 55d9edd343..48461d6789 100644 --- a/src/plone/restapi/tests/test_services_users.py +++ b/src/plone/restapi/tests/test_services_users.py @@ -28,10 +28,10 @@ def setUp(self): self.mailhost = getUtility(IMailHost) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) - self.anon_api_session = RelativeSession(self.portal_url) + self.anon_api_session = RelativeSession(self.portal_url, test=self) self.anon_api_session.headers.update({"Accept": "application/json"}) properties = { @@ -84,7 +84,7 @@ def test_list_users(self): self.assertEqual("Cambridge, MA", noam.get("location")) def test_list_users_without_being_manager(self): - noam_api_session = RelativeSession(self.portal_url) + noam_api_session = RelativeSession(self.portal_url, test=self) noam_api_session.headers.update({"Accept": "application/json"}) noam_api_session.auth = ("noam", "password") @@ -307,7 +307,7 @@ def test_get_user_as_anonymous(self): self.assertEqual(response.status_code, 401) def test_get_other_user_info_when_logged_in(self): - noam_api_session = RelativeSession(self.portal_url) + noam_api_session = RelativeSession(self.portal_url, test=self) noam_api_session.headers.update({"Accept": "application/json"}) noam_api_session.auth = ("noam", "password") @@ -366,7 +366,7 @@ def test_get_search_user_with_filter_as_unauthorized_user(self): }, ) transaction.commit() - noam_api_session = RelativeSession(self.portal_url) + noam_api_session = RelativeSession(self.portal_url, test=self) noam_api_session.headers.update({"Accept": "application/json"}) noam_api_session.auth = ("noam", "password") diff --git a/src/plone/restapi/tests/test_services_vocabularies.py b/src/plone/restapi/tests/test_services_vocabularies.py index 8fa0f154e1..cb0774c3fe 100644 --- a/src/plone/restapi/tests/test_services_vocabularies.py +++ b/src/plone/restapi/tests/test_services_vocabularies.py @@ -75,7 +75,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) provideUtility( diff --git a/src/plone/restapi/tests/test_services_workingcopy.py b/src/plone/restapi/tests/test_services_workingcopy.py index e579046b45..2be0ee93ae 100644 --- a/src/plone/restapi/tests/test_services_workingcopy.py +++ b/src/plone/restapi/tests/test_services_workingcopy.py @@ -19,7 +19,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) diff --git a/src/plone/restapi/tests/test_site_serializer.py b/src/plone/restapi/tests/test_site_serializer.py index b4ee978454..ff3628fb30 100644 --- a/src/plone/restapi/tests/test_site_serializer.py +++ b/src/plone/restapi/tests/test_site_serializer.py @@ -69,7 +69,7 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) - self.api_session = RelativeSession(f"{self.portal_url}/++api++") + self.api_session = RelativeSession(f"{self.portal_url}/++api++", test=self) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) def tearDown(self): diff --git a/src/plone/restapi/tests/test_system.py b/src/plone/restapi/tests/test_system.py index cf213c02b3..2f7d686b93 100644 --- a/src/plone/restapi/tests/test_system.py +++ b/src/plone/restapi/tests/test_system.py @@ -23,7 +23,7 @@ def setUp(self): self.request = self.portal.REQUEST self.catalog = getToolByName(self.portal, "portal_catalog") - self.api_session = RelativeSession(self.portal_url) + self.api_session = RelativeSession(self.portal_url, test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) overview_control_panel = OverviewControlPanel(self.portal, self.request) diff --git a/src/plone/restapi/tests/test_tus.py b/src/plone/restapi/tests/test_tus.py index 3ecfe07a50..bece6c679b 100644 --- a/src/plone/restapi/tests/test_tus.py +++ b/src/plone/restapi/tests/test_tus.py @@ -65,7 +65,7 @@ def setUp(self): self.upload_url = f"{self.folder.absolute_url()}/@tus-upload" transaction.commit() - self.api_session = RelativeSession(self.portal.absolute_url()) + self.api_session = RelativeSession(self.portal.absolute_url(), test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) @@ -576,7 +576,7 @@ def setUp(self): CORSTestPolicy, adapts=(Interface, IBrowserRequest), provides=ICORSPolicy ) self.portal = self.layer["portal"] - self.api_session = RelativeSession(self.portal.absolute_url()) + self.api_session = RelativeSession(self.portal.absolute_url(), test=self) self.api_session.headers.update({"Accept": "application/json"}) self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) self.upload_url = f"{self.portal.absolute_url()}/@tus-upload"