From 063e4e084ba8e4e75bb82c727ed36e24966bb532 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Mon, 9 Oct 2023 23:39:41 +0200 Subject: [PATCH 1/2] Fix regex asserts (#1719) * fix(py3.12): deprecated methods I used the approach suggested on https://stackoverflow.com/questions/20050913 This makes plone.restapi tests pass on Python 3.12. * Add news entry * Apply suggestions from code review --------- Co-authored-by: David Glick --- news/1.bugfix | 2 + src/plone/restapi/tests/test_batching.py | 8 +-- src/plone/restapi/tests/test_permissions.py | 10 ++- src/plone/restapi/tests/test_search.py | 14 ++-- .../restapi/tests/test_serializer_catalog.py | 72 +++++++++---------- src/plone/restapi/tests/test_services.py | 6 +- .../tests/test_services_querystring.py | 43 +++++------ 7 files changed, 69 insertions(+), 86 deletions(-) create mode 100644 news/1.bugfix diff --git a/news/1.bugfix b/news/1.bugfix new file mode 100644 index 0000000000..1494e057ff --- /dev/null +++ b/news/1.bugfix @@ -0,0 +1,2 @@ +Replace deprecated assert methods. +[gforcada] diff --git a/src/plone/restapi/tests/test_batching.py b/src/plone/restapi/tests/test_batching.py index 810846298c..3e809ebabc 100644 --- a/src/plone/restapi/tests/test_batching.py +++ b/src/plone/restapi/tests/test_batching.py @@ -455,7 +455,7 @@ def test_first_link_contained(self): self.request.form["b_size"] = 10 batch = HypermediaBatch(self.request, items) - self.assertDictContainsSubset({"first": "http://nohost?b_start=0"}, batch.links) + self.assertEqual(batch.links["first"], "http://nohost?b_start=0") def test_first_link_preserves_list_like_querystring_params(self): items = list(range(1, 26)) @@ -478,14 +478,14 @@ def test_last_link_contained(self): self.request.form["b_size"] = 10 batch = HypermediaBatch(self.request, items) - self.assertDictContainsSubset({"last": "http://nohost?b_start=20"}, batch.links) + self.assertEqual(batch.links["last"], "http://nohost?b_start=20") def test_next_link_contained_if_necessary(self): items = list(range(1, 26)) self.request.form["b_size"] = 10 batch = HypermediaBatch(self.request, items) - self.assertDictContainsSubset({"next": "http://nohost?b_start=10"}, batch.links) + self.assertEqual(batch.links["next"], "http://nohost?b_start=10") def test_next_link_omitted_on_last_page(self): items = list(range(1, 26)) @@ -503,7 +503,7 @@ def test_prev_link_contained_if_necessary(self): self.request.form["b_size"] = 10 self.request.form["b_start"] = 20 batch = HypermediaBatch(self.request, items) - self.assertDictContainsSubset({"prev": "http://nohost?b_start=10"}, batch.links) + self.assertEqual(batch.links["prev"], "http://nohost?b_start=10") def test_prev_link_omitted_on_first_page(self): items = list(range(1, 26)) diff --git a/src/plone/restapi/tests/test_permissions.py b/src/plone/restapi/tests/test_permissions.py index 917ab4a588..bcd5bfd8e7 100644 --- a/src/plone/restapi/tests/test_permissions.py +++ b/src/plone/restapi/tests/test_permissions.py @@ -55,10 +55,8 @@ def test_unauthorized_if_missing_permission(self): response = self.api_session.get(self.portal_url) self.assertEqual(response.status_code, 401) - self.assertDictContainsSubset( - { - "type": "Unauthorized", - "message": "Missing 'plone.restapi: Use REST API' permission", - }, - response.json(), + data = response.json() + self.assertEqual(data["type"], "Unauthorized") + self.assertEqual( + data["message"], "Missing 'plone.restapi: Use REST API' permission" ) diff --git a/src/plone/restapi/tests/test_search.py b/src/plone/restapi/tests/test_search.py index 2f66ecdba9..e4ddb4c38d 100644 --- a/src/plone/restapi/tests/test_search.py +++ b/src/plone/restapi/tests/test_search.py @@ -247,15 +247,11 @@ def test_partial_metadata_retrieval(self): } response = self.api_session.get("/@search", params=query) - self.assertDictContainsSubset( - { - "@id": self.portal_url + "/folder/doc", - "title": "Lorem Ipsum", - "portal_type": "DXTestDocument", - "review_state": "private", - }, - response.json()["items"][0], - ) + item = response.json()["items"][0] + self.assertEqual(item["@id"], self.portal_url + "/folder/doc") + self.assertEqual(item["title"], "Lorem Ipsum") + self.assertEqual(item["portal_type"], "DXTestDocument") + self.assertEqual(item["review_state"], "private") def test_full_metadata_retrieval(self): query = {"SearchableText": "lorem", "metadata_fields": "_all"} diff --git a/src/plone/restapi/tests/test_serializer_catalog.py b/src/plone/restapi/tests/test_serializer_catalog.py index 453680f02c..67b0604aea 100644 --- a/src/plone/restapi/tests/test_serializer_catalog.py +++ b/src/plone/restapi/tests/test_serializer_catalog.py @@ -55,8 +55,8 @@ def test_lazy_map_serialization(self): lazy_map = self.catalog() results = getMultiAdapter((lazy_map, self.request), ISerializeToJson)() - self.assertDictContainsSubset({"@id": "http://nohost"}, results) - self.assertDictContainsSubset({"items_total": 3}, results) + self.assertEqual(results["@id"], "http://nohost") + self.assertEqual(results["items_total"], 3) self.assertEqual(3, len(results["items"])) @unittest.skipIf(HAS_PLONE_6, "... before it was not") @@ -65,8 +65,8 @@ def test_lazy_map_serialization_plone5(self): lazy_map = self.catalog() results = getMultiAdapter((lazy_map, self.request), ISerializeToJson)() - self.assertDictContainsSubset({"@id": "http://nohost"}, results) - self.assertDictContainsSubset({"items_total": 2}, results) + self.assertEqual(results["@id"], "http://nohost") + self.assertEqual(results["items_total"], 2) self.assertEqual(2, len(results["items"])) def test_lazy_map_serialization_with_fullobjects(self): @@ -76,45 +76,43 @@ def test_lazy_map_serialization_with_fullobjects(self): fullobjects=True ) - self.assertDictContainsSubset({"@id": "http://nohost"}, results) - self.assertDictContainsSubset({"items_total": 1}, results) + self.assertEqual(results["@id"], "http://nohost") + self.assertEqual(results["items_total"], 1) self.assertEqual(1, len(results["items"])) result_item = results["items"][0] - self.assertDictContainsSubset( - { - "@id": "http://nohost/plone/my-folder/my-document", - "@type": "Document", - "changeNote": "", - "contributors": [], - "creators": ["test_user_1_"], + expected = { + "@id": "http://nohost/plone/my-folder/my-document", + "@type": "Document", + "changeNote": "", + "contributors": [], + "creators": ["test_user_1_"], + "description": "", + "effective": None, + "exclude_from_nav": False, + "expires": None, + "id": "my-document", + "is_folderish": False, + "language": "", + "layout": "document_view", + "parent": { + "@id": "http://nohost/plone/my-folder", + "@type": "Folder", + "type_title": "Folder", "description": "", - "effective": None, - "exclude_from_nav": False, - "expires": None, - "id": "my-document", - "is_folderish": False, - "language": "", - "layout": "document_view", - "parent": { - "@id": "http://nohost/plone/my-folder", - "@type": "Folder", - "type_title": "Folder", - "description": "", - "review_state": "private", - "title": "My Folder", - }, - "relatedItems": [], "review_state": "private", - "rights": "", - "subjects": [], - "table_of_contents": None, - "text": None, - "title": "My Document", - "version": "current", + "title": "My Folder", }, - result_item, - ) + "relatedItems": [], + "review_state": "private", + "rights": "", + "subjects": [], + "table_of_contents": None, + "text": None, + "title": "My Document", + "version": "current", + } + self.assertEqual(result_item, {**result_item, **expected}) def test_brain_summary_representation(self): lazy_map = self.catalog(path="/plone/my-folder/my-document") diff --git a/src/plone/restapi/tests/test_services.py b/src/plone/restapi/tests/test_services.py index dac51df7ca..1a0944efd3 100644 --- a/src/plone/restapi/tests/test_services.py +++ b/src/plone/restapi/tests/test_services.py @@ -111,10 +111,8 @@ def test_get_news_item(self): self.assertEqual( "This is an image caption.", response.json()["image_caption"] ) - self.assertDictContainsSubset( - {"download": self.portal_url + f"/news1/@@images/{scale_url_uuid}.png"}, - response.json()["image"], - ) + url = self.portal_url + f"/news1/@@images/{scale_url_uuid}.png" + self.assertEqual(response.json()["image"]["download"], url) def test_get_folder(self): self.portal.invokeFactory("Folder", id="folder1", title="My Folder") diff --git a/src/plone/restapi/tests/test_services_querystring.py b/src/plone/restapi/tests/test_services_querystring.py index 1203ab6336..8ccb0f7ebb 100644 --- a/src/plone/restapi/tests/test_services_querystring.py +++ b/src/plone/restapi/tests/test_services_querystring.py @@ -80,13 +80,8 @@ def test_endpoint_inlines_vocabularies(self): indexes = response.json()["indexes"] idx = indexes["review_state"] - self.assertDictContainsSubset( - { - "title": "Review state", - "vocabulary": "plone.app.vocabularies.WorkflowStates", - }, - idx, - ) + self.assertEqual(idx["title"], "Review state") + self.assertEqual(idx["vocabulary"], "plone.app.vocabularies.WorkflowStates") expected_vocab_values = { "external": {"title": "Externally visible [external]"}, @@ -110,15 +105,13 @@ def test_endpoint_inlines_operators(self): indexes = response.json()["indexes"] idx = indexes["isDefaultPage"] - self.assertDictContainsSubset( - { - "title": "Default Page", - "operations": [ - "plone.app.querystring.operation.boolean.isTrue", - "plone.app.querystring.operation.boolean.isFalse", - ], - }, - idx, + self.assertEqual(idx["title"], "Default Page") + self.assertEqual( + idx["operations"], + [ + "plone.app.querystring.operation.boolean.isTrue", + "plone.app.querystring.operation.boolean.isFalse", + ], ) expected_operators = { @@ -144,16 +137,14 @@ def test_endpoint_includes_widgets_for_operators(self): indexes = response.json()["indexes"] idx = indexes["getObjPositionInParent"] - self.assertDictContainsSubset( - { - "title": "Order in folder", - "operations": [ - "plone.app.querystring.operation.int.is", - "plone.app.querystring.operation.int.lessThan", - "plone.app.querystring.operation.int.largerThan", - ], - }, - idx, + self.assertEqual(idx["title"], "Order in folder") + self.assertEqual( + idx["operations"], + [ + "plone.app.querystring.operation.int.is", + "plone.app.querystring.operation.int.lessThan", + "plone.app.querystring.operation.int.largerThan", + ], ) ops = idx["operators"] From 5298c359021843b48e683d4f7d44b50fa6bb0708 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Sat, 14 Oct 2023 20:51:56 +0200 Subject: [PATCH 2/2] Cleanup robot tests (#1720) * cleanup: remove unused p.a.robotframework * Add news entry * Depend on test extra of plone.app.contenttypes instead of requiring plone.app.robotframework directly --------- Co-authored-by: David Glick --- news/1720.internal | 2 ++ setup.py | 5 ++-- src/plone/restapi/tests/robot/test.robot | 22 ------------------ src/plone/restapi/tests/test_robot.py.txt | 28 ----------------------- 4 files changed, 4 insertions(+), 53 deletions(-) create mode 100644 news/1720.internal delete mode 100644 src/plone/restapi/tests/robot/test.robot delete mode 100644 src/plone/restapi/tests/test_robot.py.txt diff --git a/news/1720.internal b/news/1720.internal new file mode 100644 index 0000000000..1ce1f5bf97 --- /dev/null +++ b/news/1720.internal @@ -0,0 +1,2 @@ +Drop, already unused plone.app.robotframework test. +[gforcada] diff --git a/setup.py b/setup.py index b4351a8074..66854ff2f2 100644 --- a/setup.py +++ b/setup.py @@ -42,9 +42,8 @@ def read(filename): TEST_REQUIRES = [ "collective.MockMailHost", "plone.app.caching", - "plone.app.contenttypes", - "plone.app.robotframework", - "plone.app.testing [robot] >= 4.2.2", # ROBOT_TEST_LEVEL added + "plone.app.contenttypes[test]", + "plone.app.testing", "plone.api", "requests", "mock", diff --git a/src/plone/restapi/tests/robot/test.robot b/src/plone/restapi/tests/robot/test.robot deleted file mode 100644 index 9313a7d5d1..0000000000 --- a/src/plone/restapi/tests/robot/test.robot +++ /dev/null @@ -1,22 +0,0 @@ -*** Settings *** - -Library Selenium2Library timeout=10 implicit_wait=0.5 - -Suite Setup Start browser -Suite Teardown Close All Browsers - -*** Variables *** - -${BROWSER} = firefox - -*** Test Cases *** - -Plone site - [Tags] start - Go to ${PLONE_URL} - Page should contain Plone site - -*** Keywords *** - -Start browser - Open browser ${PLONE_URL} browser=${BROWSER} diff --git a/src/plone/restapi/tests/test_robot.py.txt b/src/plone/restapi/tests/test_robot.py.txt deleted file mode 100644 index ba16dbdef9..0000000000 --- a/src/plone/restapi/tests/test_robot.py.txt +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -from plone.app.testing import ROBOT_TEST_LEVEL -from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING -from plone.testing import layered -import robotsuite -import unittest -import os - - -def test_suite(): - suite = unittest.TestSuite() - current_dir = os.path.abspath(os.path.dirname(__file__)) - robot_dir = os.path.join(current_dir, 'robot') - robot_tests = [ - os.path.join('robot', doc) for doc in - os.listdir(robot_dir) if doc.endswith('.robot') and - doc.startswith('test_') - ] - for robot_test in robot_tests: - robottestsuite = robotsuite.RobotTestSuite(robot_test) - robottestsuite.level = ROBOT_TEST_LEVEL - suite.addTests([ - layered( - robottestsuite, - layer=PLONE_RESTAPI_DX_FUNCTIONAL_TESTING - ), - ]) - return suite