forked from django-cms/djangocms-link
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase test coverage (django-cms#178)
* added more tests * further adaptions * fix tests * replace with helper files * further adaptions * fix tests * fix tests * simplify code
- Loading branch information
1 parent
88b6c28
commit 2712ce4
Showing
17 changed files
with
471 additions
and
329 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*.log | ||
*.pot | ||
.DS_Store | ||
.coverage | ||
.coverage/ | ||
.eggs/ | ||
.idea/ | ||
|
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 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
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,123 @@ | ||
import os | ||
from tempfile import mkdtemp | ||
|
||
from django.core.files import File | ||
|
||
from filer.models.filemodels import File as FilerFile | ||
from filer.models.foldermodels import Folder as FilerFolder | ||
from filer.models.imagemodels import Image as FilerImage | ||
from filer.utils.compatibility import PILImage, PILImageDraw | ||
|
||
|
||
# from https://github.com/divio/django-filer/blob/develop/tests/helpers.py#L46-L52 | ||
def create_image(mode="RGB", size=(800, 600)): | ||
""" | ||
Creates a usable image file using PIL | ||
:returns: PIL Image instance | ||
""" | ||
image = PILImage.new(mode, size) | ||
draw = PILImageDraw.Draw(image) | ||
x_bit, y_bit = size[0] // 10, size[1] // 10 | ||
draw.rectangle((x_bit, y_bit * 2, x_bit * 7, y_bit * 3), "red") | ||
draw.rectangle((x_bit * 2, y_bit, x_bit * 3, y_bit * 8), "red") | ||
|
||
return image | ||
|
||
|
||
def get_image(image_name="test_file.jpg"): | ||
""" | ||
Creates and stores an image to the file system using PILImage | ||
:param image_name: the name for the file (default "test_file.jpg") | ||
:returns: dict {name, image, path} | ||
""" | ||
image = create_image() | ||
image_path = os.path.join( | ||
mkdtemp(), | ||
image_name, | ||
) | ||
image.save(image_path, "JPEG") | ||
|
||
return { | ||
"name": image_name, | ||
"image": image, | ||
"path": image_path, | ||
} | ||
|
||
|
||
def get_file(file_name="test_file.pdf"): | ||
""" | ||
Creates and stores an arbitrary file into a temporary dir | ||
:param file_name: the name for the file (default "test_file.pdf") | ||
:returns: dict {name, image, path} | ||
""" | ||
file_path = os.path.join( | ||
mkdtemp(), | ||
file_name, | ||
) | ||
data = open(file_path, "a") | ||
|
||
return { | ||
"name": file_name, | ||
"file": data, | ||
"path": file_path, | ||
} | ||
|
||
|
||
def get_filer_image(image_name="test_file.jpg"): | ||
""" | ||
Creates and stores an image to filer and returns it | ||
:param image_name: the name for the file (default "test_file.jpg") | ||
:returns: filer image instance | ||
""" | ||
image = get_image(image_name) | ||
filer_file = File( | ||
open(image.get("path"), "rb"), | ||
name=image.get("name"), | ||
) | ||
filer_object = FilerImage.objects.create( | ||
original_filename=image.get("name"), | ||
file=filer_file, | ||
) | ||
|
||
return filer_object | ||
|
||
|
||
def get_filer_file(file_name="test_file.pdf", folder=None): | ||
""" | ||
Creates and stores a file to filer and returns it | ||
:param file_name: the name for the file (default "test_file.pdf") | ||
:param folder: optionally provide a folder instance | ||
:returns: filer file instance | ||
""" | ||
data = get_file(file_name) | ||
filer_file = File( | ||
open(data.get("path"), "rb"), | ||
name=data.get("name"), | ||
) | ||
filer_object = FilerFile.objects.create( | ||
original_filename=data.get("name"), | ||
file=filer_file, | ||
folder=folder, | ||
) | ||
|
||
return filer_object | ||
|
||
|
||
def get_filer_folder(folder_name="test_folder", parent=None): | ||
""" | ||
Creates and returns a filer folder | ||
:param folder_name: the name of the folder to be used (default "folder_name") | ||
:param parent: optionally provide a parent folder | ||
:returns: filer folder instance | ||
""" | ||
filer_object = FilerFolder.objects.create( | ||
parent=parent, | ||
name=folder_name, | ||
) | ||
|
||
return filer_object |
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,9 +1,11 @@ | ||
# requirements from setup.py | ||
django-select2>=5.11,<7 # 7 works in Django 2+ | ||
django-filer>=1.3.0 | ||
django-filer>=1.5.0 | ||
djangocms-text-ckeditor | ||
html5lib<0.99999999 | ||
# other requirements | ||
djangocms-helper | ||
tox | ||
coverage | ||
isort | ||
flake8 | ||
# override "pyflakes<2.1" from djangocms-helper | ||
pyflakes>=2.1.0 |
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,16 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.conf import settings | ||
from django.test import TestCase | ||
|
||
from djangocms_link.fields import is_select2_enabled, PageSearchField | ||
from djangocms_link.fields_select2 import Select2PageSearchField | ||
|
||
|
||
class LinkFieldTestCase(TestCase): | ||
|
||
def test_field_with_django_select2_extension(self): | ||
self.assertTrue('django_select2' in settings.INSTALLED_APPS) | ||
self.assertTrue(is_select2_enabled()) | ||
settings.INSTALLED_APPS.remove("django_select2") | ||
self.assertFalse(is_select2_enabled()) | ||
self.assertEqual(PageSearchField, Select2PageSearchField) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.