Skip to content

Commit

Permalink
add test for FrontendMedia
Browse files Browse the repository at this point in the history
  • Loading branch information
vdboor committed Dec 15, 2016
1 parent 15b7668 commit 42b08d7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
15 changes: 14 additions & 1 deletion fluent_contents/tests/test_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from fluent_contents.extensions import PluginContext
from fluent_contents.models import Placeholder, DEFAULT_TIMEOUT
from fluent_contents.rendering import utils as rendering_utils
from fluent_contents.tests.testapp.models import TestPage, RawHtmlTestItem, TimeoutTestItem, OverrideBase
from fluent_contents.tests import factories
from fluent_contents.tests.testapp.models import TestPage, RawHtmlTestItem, TimeoutTestItem, OverrideBase, MediaTestItem
from fluent_contents.tests.utils import AppTestCase


Expand Down Expand Up @@ -39,6 +40,18 @@ def test_render_timeout(self):
self.assertEqual(output.html, '<b>Item1!</b><b>Item2!</b>')
self.assertEqual(output.cache_timeout, 60) # this is that timeout that should be used for the placeholder cache item.

def test_render_media(self):
"""
Test that 'class FrontendMedia' works.
"""
placeholder = factories.create_placeholder()
factories.create_content_item(MediaTestItem, placeholder=placeholder, html='MEDIA_TEST')

output = rendering.render_placeholder(self.dummy_request, placeholder)
self.assertEqual(output.html.strip(), 'MEDIA_TEST')
self.assertEqual(output.media._js, ['testapp/media_item.js'])
self.assertEqual(output.media._css, {'screen': ['testapp/media_item.css']})

def test_debug_is_method_overwritten(self):
"""
Test the "is method overwritten" logic to detect template changes
Expand Down
19 changes: 18 additions & 1 deletion fluent_contents/tests/testapp/content_plugins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.utils.safestring import mark_safe
from fluent_contents.extensions import ContentPlugin, plugin_pool
from fluent_contents.tests.testapp.models import RawHtmlTestItem, TimeoutTestItem
from fluent_contents.tests.testapp.models import RawHtmlTestItem, TimeoutTestItem, MediaTestItem


@plugin_pool.register
Expand Down Expand Up @@ -28,3 +28,20 @@ def render(self, request, instance, **kwargs):
def get_render_template(self, request, instance, **kwargs):
# This is for test_debug_is_method_overwritten()
return super(TimeoutTestPlugin, self).get_render_template(request, instance, **kwargs)


@plugin_pool.register
class MediaTestPlugin(ContentPlugin):
"""
Testing a plugin timeout.
"""
model = MediaTestItem
render_template = "testapp/media_item.html"

class FrontendMedia:
css = {
'screen': ('testapp/media_item.css',),
}
js = (
'testapp/media_item.js',
)
13 changes: 13 additions & 0 deletions fluent_contents/tests/testapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ class Migration(migrations.Migration):
},
bases=('fluent_contents.contentitem',),
),
migrations.CreateModel(
name='MediaTestItem',
fields=[
('contentitem_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='fluent_contents.ContentItem')),
('html', models.TextField(verbose_name=b'HTML code')),
],
options={
'db_table': 'contentitem_testapp_mediatestitem',
'verbose_name': 'Timeout test',
'verbose_name_plural': 'Timeout test',
},
bases=('fluent_contents.contentitem',),
),
migrations.CreateModel(
name='TestPage',
fields=[
Expand Down
16 changes: 16 additions & 0 deletions fluent_contents/tests/testapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,19 @@ class Meta:

def __str__(self):
return self.html


@python_2_unicode_compatible
class MediaTestItem(ContentItem):
"""
The most basic "media HTML" content item, for testing.
"""
html = models.TextField("HTML code")

class Meta:
app_label = 'testapp'
verbose_name = 'Media test'
verbose_name_plural = 'Media test'

def __str__(self):
return self.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ instance.html|safe }}

0 comments on commit 42b08d7

Please sign in to comment.