-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
285 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone import api | ||
from plone.formwidget.namedfile.converter import b64decode_file | ||
from plone.namedfile.browser import Download | ||
from plone.namedfile.file import NamedImage | ||
from sc.social.like.interfaces import ISocialLikeSettings | ||
|
||
|
||
class FallBackImage(Download): | ||
"""Helper view to return the fallback image.""" | ||
|
||
def __init__(self, context, request): | ||
super(FallBackImage, self).__init__(context, request) | ||
|
||
record = ISocialLikeSettings.__identifier__ + '.fallback_image' | ||
fallback_image = api.portal.get_registry_record(record, default=None) | ||
|
||
if fallback_image is not None: | ||
# set fallback image data for download | ||
filename, data = b64decode_file(fallback_image) | ||
data = NamedImage(data=data, filename=filename) | ||
self.filename, self.data = filename, data | ||
# enable image caching for 2 minutes | ||
self.request.RESPONSE.setHeader('Cache-Control', 'max-age=120, public') | ||
else: | ||
# resource no longer available | ||
self.data = NamedImage(data='') | ||
self.request.RESPONSE.setStatus(410) # Gone | ||
|
||
def _getFile(self): | ||
return self.data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0"?> | ||
<metadata> | ||
<version>3047</version> | ||
<version>3048</version> | ||
</metadata> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone import api | ||
from plone.app.testing import setRoles | ||
from plone.app.testing import TEST_USER_ID | ||
from sc.social.like.browser.socialikes import SocialLikes | ||
from sc.social.like.testing import INTEGRATION_TESTING | ||
|
||
import unittest | ||
|
||
|
||
class BrowserViewTestCase(unittest.TestCase): | ||
|
||
layer = INTEGRATION_TESTING | ||
|
||
def setUp(self): | ||
self.portal = self.layer['portal'] | ||
self.request = self.layer['request'] | ||
setRoles(self.portal, TEST_USER_ID, ['Manager']) | ||
self.portal.invokeFactory('Document', 'my-document') | ||
self.document = self.portal['my-document'] | ||
|
||
def view(self, context=None): | ||
context = context or self.portal | ||
view = SocialLikes(context, self.request) | ||
return view | ||
|
||
def test_disabled_on_portal(self): | ||
view = self.view(self.portal) | ||
self.assertFalse(view.enabled) | ||
|
||
def test_enabled_on_document(self): | ||
view = self.view(self.document) | ||
self.assertTrue(view.enabled) | ||
|
||
|
||
class FallBackImageViewTestCase(unittest.TestCase): | ||
|
||
layer = INTEGRATION_TESTING | ||
|
||
def setUp(self): | ||
self.portal = self.layer['portal'] | ||
self.request = self.layer['request'] | ||
|
||
def set_fallback_image(self, filename): | ||
from sc.social.like.interfaces import ISocialLikeSettings | ||
from sc.social.like.tests.utils import get_file_b64encoded | ||
record = ISocialLikeSettings.__identifier__ + '.fallback_image' | ||
logo = get_file_b64encoded(filename) | ||
api.portal.set_registry_record(record, logo) | ||
|
||
def test_no_fall_back_image(self): | ||
view = api.content.get_view( | ||
'sociallike-fallback-image', self.portal, self.request) | ||
self.assertEqual(len(view()), 0) | ||
self.assertEqual(self.request.RESPONSE.getStatus(), 410) | ||
|
||
def test_fall_back_image(self): | ||
self.set_fallback_image('imgtest_1920x1080.png') | ||
view = api.content.get_view( | ||
'sociallike-fallback-image', self.portal, self.request) | ||
self.assertEqual(len(view()), 42901) | ||
self.assertEqual(self.request.RESPONSE.getStatus(), 200) | ||
self.assertEqual( | ||
self.request.RESPONSE.getHeader('Cache-Control'), | ||
'max-age=120, public', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding:utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding:utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="3047" | ||
destination="3048" | ||
profile="sc.social.like:default"> | ||
|
||
<genericsetup:upgradeDepends | ||
title="Add fallback image in configlet" | ||
description="Adds new field to the control panel configlet." | ||
import_steps="plone.app.registry" | ||
/> | ||
|
||
</genericsetup:upgradeSteps> | ||
|
||
</configure> |
Oops, something went wrong.