-
Notifications
You must be signed in to change notification settings - Fork 23
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 Canonical URL updater form #118
Changes from all commits
3b3a838
4dcbf73
d3f6963
78bc1e1
7a8770b
b15e2dc
8c04dff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0"?> | ||
<metadata> | ||
<version>3045</version> | ||
<version>3046</version> | ||
</metadata> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"""Test for the canonical URL updater form.""" | ||
from DateTime import DateTime | ||
from plone import api | ||
from sc.social.like.interfaces import ISocialLikeSettings | ||
from sc.social.like.testing import HAS_DEXTERITY | ||
from sc.social.like.testing import INTEGRATION_TESTING | ||
from sc.social.like.tests.utils import enable_social_media_behavior | ||
|
@@ -23,21 +24,31 @@ def setUp(self): | |
self.portal = self.layer['portal'] | ||
self.request = self.layer['request'] | ||
enable_social_media_behavior() | ||
self.setup_content() | ||
api.portal.set_registry_record( | ||
name='canonical_domain', value='https://example.org', interface=ISocialLikeSettings) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only in the form. |
||
|
||
def setup_content(self): | ||
with api.env.adopt_roles(['Manager']): | ||
api.content.create(self.portal, type='News Item', id='foo') | ||
api.content.create(self.portal, type='News Item', id='bar') | ||
api.content.create(self.portal, type='News Item', id='baz') | ||
obj = api.content.create(self.portal, type='News Item', id='foo') | ||
api.content.transition(obj, 'publish') | ||
obj = api.content.create(self.portal, type='News Item', id='bar') | ||
api.content.transition(obj, 'publish') | ||
obj = api.content.create(self.portal, type='News Item', id='baz') | ||
api.content.transition(obj, 'publish') | ||
|
||
# simulate objects were create way long in the past | ||
self.portal['foo'].creation_date = DateTime('2015/01/01') | ||
self.portal['bar'].creation_date = DateTime('2016/01/01') | ||
self.portal['foo'].effective_date = DateTime('2015/01/01') | ||
self.portal['foo'].reindexObject() | ||
self.portal['bar'].effective_date = DateTime('2016/01/01') | ||
self.portal['bar'].reindexObject() | ||
# XXX: publishing an object does not sets its effective date | ||
# https://github.com/plone/plone.api/issues/343 | ||
self.portal['baz'].effective_date = DateTime() | ||
self.portal['baz'].reindexObject() | ||
|
||
@unittest.expectedFailure # FIXME: https://github.com/collective/sc.social.like/issues/119 | ||
def test_update_canonical_url(self): | ||
self.setup_content() | ||
# canonical URL is None as we did not set up a canonical domain | ||
self.assertIsNone(self.portal['foo'].canonical_url) | ||
self.assertIsNone(self.portal['bar'].canonical_url) | ||
|
@@ -47,16 +58,17 @@ def test_update_canonical_url(self): | |
view = api.content.get_view(name, self.portal, self.request) | ||
# simulate data comming from form | ||
data = dict( | ||
canonical_domain='https://example.org', | ||
created_before=DateTime('2017/01/01').asdatetime(), | ||
old_canonical_domain='http://example.org', | ||
published_before=DateTime('2017/01/01').asdatetime(), | ||
) | ||
view.update_canonical_url(data) | ||
# objects created before the specified date will have their | ||
# canonical URL updated | ||
self.assertEqual( | ||
self.portal['foo'].canonical_url, 'https://example.org/plone/foo') | ||
self.portal['foo'].canonical_url, 'http://example.org/plone/foo') | ||
self.assertEqual( | ||
self.portal['bar'].canonical_url, 'https://example.org/plone/bar') | ||
self.portal['bar'].canonical_url, 'http://example.org/plone/bar') | ||
# objects created after the specified date will have their | ||
# canonical URL unchaged | ||
self.assertIsNone(self.portal['baz'].canonical_url) | ||
self.assertEqual( | ||
self.portal['baz'].canonical_url, 'https://example.org/plone/baz') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
from plone import api | ||
from sc.social.like.config import IS_PLONE_5 | ||
from sc.social.like.interfaces import ISocialLikeSettings | ||
from sc.social.like.testing import HAS_DEXTERITY | ||
from sc.social.like.testing import INTEGRATION_TESTING | ||
from zope.component import getUtility | ||
|
||
|
@@ -14,6 +15,7 @@ class UpgradeTestCaseBase(unittest.TestCase): | |
|
||
def setUp(self, from_version, to_version): | ||
self.portal = self.layer['portal'] | ||
self.request = self.layer['request'] | ||
self.setup = self.portal['portal_setup'] | ||
self.profile_id = u'sc.social.like:default' | ||
self.from_version = from_version | ||
|
@@ -285,3 +287,40 @@ def test_enable_social_media_behavior(self): | |
continue # not a Dexterity-based content type | ||
behaviors = list(fti.behaviors) | ||
self.assertIn(ISocialMedia.__identifier__, behaviors) | ||
|
||
|
||
class To3046TestCase(UpgradeTestCaseBase): | ||
|
||
def setUp(self): | ||
UpgradeTestCaseBase.setUp(self, u'3045', u'3046') | ||
|
||
def test_upgrade_to_3046_registrations(self): | ||
version = self.setup.getLastVersionForProfile(self.profile_id)[0] | ||
self.assertGreaterEqual(int(version), int(self.to_version)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tcurvelo I have no idea why this is failing, I think is something from another test; do you mind to dig on it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already found the issue and fixed it: 78bc1e1 |
||
self.assertEqual(self.total_steps, 1) | ||
|
||
@unittest.skipUnless(HAS_DEXTERITY, 'plone.app.contenttypes must be installed') | ||
def test_reindex_catalog(self): | ||
# check if the upgrade step is registered | ||
title = u'Reindex catalog' | ||
step = self.get_upgrade_step(title) | ||
self.assertIsNotNone(step) | ||
|
||
from sc.social.like.behaviors import ISocialMedia | ||
from sc.social.like.tests.utils import enable_social_media_behavior | ||
with api.env.adopt_roles(['Manager']): | ||
for i in xrange(0, 10): | ||
api.content.create(self.portal, 'News Item', str(i)) | ||
|
||
# break the catalog by deleting an object without notifying | ||
self.portal._delObject('0', suppress_events=True) | ||
self.assertNotIn('0', self.portal) | ||
enable_social_media_behavior() | ||
results = api.content.find(object_provides=ISocialMedia.__identifier__) | ||
self.assertEqual(len(results), 0) | ||
|
||
# run the upgrade step to validate it | ||
self.request.set('test', True) # avoid transaction commits on tests | ||
self.execute_upgrade_step(step) | ||
results = api.content.find(object_provides=ISocialMedia.__identifier__) | ||
self.assertEqual(len(results), 9) # no failure and catalog updated |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding:utf-8 -*- | ||
from plone import api | ||
from sc.social.like.logger import logger | ||
from sc.social.like.utils import get_valid_objects | ||
|
||
import transaction | ||
|
||
|
||
def reindex_catalog(setup_tool): | ||
"""Reindex objects to fix interfaces on the catalog.""" | ||
test = 'test' in setup_tool.REQUEST # used to ignore transactions on tests | ||
logger.info( | ||
u'Reindexing the catalog. ' | ||
u'This process could take a long time on large sites. Be patient.' | ||
) | ||
catalog = api.portal.get_tool('portal_catalog') | ||
results = catalog() | ||
logger.info(u'Found {0} objects'.format(len(results))) | ||
n = 0 | ||
for obj in get_valid_objects(results): | ||
catalog.catalog_object(obj, idxs=['object_provides'], update_metadata=False) | ||
n += 1 | ||
# XXX: https://github.com/gforcada/flake8-pep3101/issues/16 | ||
if n % 1000 == 0 and not test: # noqa: S001 | ||
transaction.commit() | ||
logger.info('{0} items processed.'.format(n)) | ||
|
||
if not test: | ||
transaction.commit() | ||
logger.info('Done.') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"> | ||
|
||
<genericsetup:upgradeSteps | ||
source="3045" | ||
destination="3046" | ||
profile="sc.social.like:default"> | ||
|
||
<genericsetup:upgradeStep | ||
title="Reindex catalog" | ||
description="Reindex objects to fix interfaces on the catalog." | ||
handler=".reindex_catalog" | ||
/> | ||
|
||
</genericsetup:upgradeSteps> | ||
|
||
</configure> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I miss the 'date' name in this attribute, how about to change it to 'published_before_date'?