-
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
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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,56 @@ | ||
# -*- coding: utf-8 -*- | ||
from sc.social.like.testing import INTEGRATION_TESTING | ||
from sc.social.like.tests.utils import get_file_b64encoded | ||
from sc.social.like.utils import validate_og_fallback_image | ||
from zope.interface import Invalid | ||
|
||
import unittest | ||
|
||
|
||
class OGFallbackImageValidatorTestCase(unittest.TestCase): | ||
|
||
layer = INTEGRATION_TESTING | ||
|
||
def test_validate_og_fallback_image_no_image(self): | ||
self.assertTrue(validate_og_fallback_image(None)) | ||
|
||
def test_validate_og_fallback_image_valid(self): | ||
image = get_file_b64encoded('imgtest_1024x768.png') | ||
self.assertTrue(validate_og_fallback_image(image)) | ||
|
||
def test_validate_og_fallback_image_invalid_mime_type(self): | ||
image = get_file_b64encoded('julia_set_ice.tiff') | ||
with self.assertRaises(Invalid): | ||
validate_og_fallback_image(image) | ||
|
||
# FIXME: we need to find out how to easily resize the image | ||
@unittest.expectedFailure | ||
def test_validate_og_fallback_image_invalid_size(self): | ||
image = get_file_b64encoded('imgtest_1024x768.png') | ||
with self.assertRaises(Invalid): | ||
validate_og_fallback_image(image) | ||
|
||
def test_validate_og_fallback_image_invalid_dimensions(self): | ||
image = get_file_b64encoded('julia_set_ice.png') | ||
with self.assertRaises(Invalid): | ||
validate_og_fallback_image(image) | ||
|
||
def test_validate_og_fallback_image_invalid_aspect_ratio(self): | ||
image = get_file_b64encoded('imgtest_768x768.jpg') | ||
with self.assertRaises(Invalid): | ||
validate_og_fallback_image(image) | ||
|
||
|
||
def load_tests(loader, tests, pattern): | ||
from sc.social.like.testing import HAS_DEXTERITY | ||
|
||
test_cases = [] | ||
if HAS_DEXTERITY: | ||
# load validation tests on Dexterity-based content types only | ||
test_cases.append(OGFallbackImageValidatorTestCase) | ||
|
||
suite = unittest.TestSuite() | ||
for test_class in test_cases: | ||
tests = loader.loadTestsFromTestCase(test_class) | ||
suite.addTests(tests) | ||
return suite |