Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix random failures on test_services_types #1232

Merged
merged 1 commit into from
Sep 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/plone/restapi/tests/test_services_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,33 @@
from plone.app.testing import SITE_OWNER_PASSWORD
from plone.app.testing import TEST_USER_ID
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING
from plone.restapi.testing import PLONE_VERSION
from plone.restapi.testing import RelativeSession

import six
import time
import transaction
import unittest


PYTHON2_PLONE52 = PLONE_VERSION.base_version >= "5.2" and six.PY2


class TestServicesTypes(unittest.TestCase):

layer = PLONE_RESTAPI_DX_FUNCTIONAL_TESTING

def sleep_python2_plone52(self, seconds=0.2):
"""plone.dexterity 2.10+ now uses the _p_mtime variable in the schema names.
As this variable is related to date/time and the tests are executed very fast,
some schema had the same name, when they shouldn't be. This was causing
problems in the tests. So we introduce sleeps in Plone 5.2 with Python 2,
so that the schemas don't have the same names. In Python 3 we don't have this
problem because the precision of _p_mtime is higher in Python 3.
"""
if PYTHON2_PLONE52:
time.sleep(seconds)

def setUp(self):
self.app = self.layer["app"]
self.portal = self.layer["portal"]
Expand Down Expand Up @@ -60,6 +77,7 @@ def setUp(self):
"description": "Website of the author",
},
)
self.sleep_python2_plone52()

def tearDown(self):
# Remove all custom changed on Document
Expand Down Expand Up @@ -114,6 +132,7 @@ def test_get_types_document_edit(self):
) # noqa

def test_types_document_get_fieldset(self):
self.sleep_python2_plone52()
response = self.api_session.get("/@types/Document/contact_info")

self.assertEqual(response.status_code, 200)
Expand Down Expand Up @@ -253,6 +272,7 @@ def test_types_document_patch_one_field(self):
"required": False,
},
)
self.sleep_python2_plone52()
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@types/Document/author_email")
Expand Down Expand Up @@ -317,6 +337,7 @@ def test_types_document_patch_create_missing(self):
},
},
)
self.sleep_python2_plone52(0.4)
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@types/Document")
Expand Down Expand Up @@ -389,6 +410,7 @@ def test_types_document_put(self):
}

response = self.api_session.put("/@types/Document", json=doc_json)
self.sleep_python2_plone52(0.4)
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@types/Document")
Expand Down Expand Up @@ -429,6 +451,7 @@ def test_types_document_remove_field(self):
response = self.api_session.delete(
"/@types/Document/author_email",
)
self.sleep_python2_plone52(0.4)
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@types/Document")
Expand Down