Skip to content

Commit

Permalink
Add conditional tests for Plone 5
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh committed Aug 24, 2017
1 parent 776ff65 commit 8ee4b32
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions plone-5.0.x.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ extends =
base.cfg
http://dist.plone.org/release/5.0.7/versions.cfg
versions.cfg

parts += omelette

[omelette]
recipe = collective.recipe.omelette
eggs =
${instance:eggs}
${test:eggs}
8 changes: 8 additions & 0 deletions src/plone/restapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
try:
pkg_resources.get_distribution('plone.app.contenttypes')
HAS_PLONE_APP_CONTENTTYPES = True

event_version = pkg_resources.get_distribution('plone.app.event').version
if pkg_resources.parse_version(event_version) > \
pkg_resources.parse_version('1.99'):
HAS_PLONE_APP_EVENT_20 = True
else:
HAS_PLONE_APP_EVENT_20 = False

except pkg_resources.DistributionNotFound: # pragma: no cover
HAS_PLONE_APP_CONTENTTYPES = False

Expand Down
39 changes: 39 additions & 0 deletions src/plone/restapi/tests/test_content_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from plone.app.testing import setRoles
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING
from plone.restapi.testing import PLONE_RESTAPI_AT_FUNCTIONAL_TESTING
from plone.restapi import HAS_PLONE_APP_EVENT_20

import pytz
import requests
Expand Down Expand Up @@ -219,6 +220,7 @@ def setUp(self):
wftool.doActionFor(self.portal.folder1, 'publish')
transaction.commit()

@unittest.skipIf(HAS_PLONE_APP_EVENT_20, 'Valid for p.a.event<2.0 only')
def test_post_to_folder_creates_event_with_correct_TZ(self):
response = requests.post(
self.portal.folder1.absolute_url(),
Expand Down Expand Up @@ -254,6 +256,7 @@ def test_post_to_folder_creates_event_with_correct_TZ(self):
self.assertEqual(
response.json()['start'], u'2013-01-01T10:00:00+01:00')

@unittest.skipIf(HAS_PLONE_APP_EVENT_20, 'Valid for p.a.event<2.0 only')
def test_post_creates_event_with_correct_TZ_using_UTC_offset(self):
response = requests.post(
self.portal.folder1.absolute_url(),
Expand All @@ -274,3 +277,39 @@ def test_post_creates_event_with_correct_TZ_using_UTC_offset(self):
self.assertEqual(201, response.status_code)
self.assertEqual(
response.json()['start'], u'2013-01-01T10:00:00+01:00')

@unittest.skipIf(not HAS_PLONE_APP_EVENT_20, 'Valid for p.a.event<2.0 only') # noqa
def test_pavent_20_post_to_folder_creates_event_with_correct_TZ(self):
response = requests.post(
self.portal.folder1.absolute_url(),
headers={'Accept': 'application/json'},
auth=(SITE_OWNER_NAME, SITE_OWNER_PASSWORD),
json={
"@type": "Event",
"id": "myevent2",
"title": "My Event",
"start": pytz.timezone('Asia/Saigon').localize(datetime(2018, 1, 1, 10, 0)).isoformat(), # noqa
"end": pytz.timezone('Asia/Saigon').localize(datetime(2018, 1, 1, 12, 0)).isoformat(), # noqa
},
)
self.assertEqual(201, response.status_code)
self.assertEqual(
response.json()['start'], u'2018-01-01T03:00:00+00:00')

response = requests.post(
self.portal.folder1.absolute_url(),
headers={'Accept': 'application/json'},
auth=(SITE_OWNER_NAME, SITE_OWNER_PASSWORD),
json={
"@type": "Event",
"id": "myevent",
"title": "My Event",
"start": pytz.timezone('Europe/Berlin').localize(datetime(
2013, 1, 1, 10, 0)).isoformat(),
"end": pytz.timezone('Europe/Berlin').localize(datetime(
2013, 1, 1, 12, 0)).isoformat(),
},
)
self.assertEqual(201, response.status_code)
self.assertEqual(
response.json()['start'], u'2013-01-01T09:00:00+00:00')

0 comments on commit 8ee4b32

Please sign in to comment.