diff --git a/fluent_contents/tests/test_rendering.py b/fluent_contents/tests/test_rendering.py
index e2ea7a9c..16daf2ea 100644
--- a/fluent_contents/tests/test_rendering.py
+++ b/fluent_contents/tests/test_rendering.py
@@ -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
@@ -39,6 +40,18 @@ def test_render_timeout(self):
self.assertEqual(output.html, 'Item1!Item2!')
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
diff --git a/fluent_contents/tests/testapp/content_plugins.py b/fluent_contents/tests/testapp/content_plugins.py
index 4b959d74..016ebf48 100644
--- a/fluent_contents/tests/testapp/content_plugins.py
+++ b/fluent_contents/tests/testapp/content_plugins.py
@@ -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
@@ -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',
+ )
diff --git a/fluent_contents/tests/testapp/migrations/0001_initial.py b/fluent_contents/tests/testapp/migrations/0001_initial.py
index cf82447c..3a2efdd0 100644
--- a/fluent_contents/tests/testapp/migrations/0001_initial.py
+++ b/fluent_contents/tests/testapp/migrations/0001_initial.py
@@ -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=[
diff --git a/fluent_contents/tests/testapp/models.py b/fluent_contents/tests/testapp/models.py
index 28547907..5ceb5f3d 100644
--- a/fluent_contents/tests/testapp/models.py
+++ b/fluent_contents/tests/testapp/models.py
@@ -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
diff --git a/fluent_contents/tests/testapp/templates/testapp/media_item.html b/fluent_contents/tests/testapp/templates/testapp/media_item.html
new file mode 100644
index 00000000..a75ff31c
--- /dev/null
+++ b/fluent_contents/tests/testapp/templates/testapp/media_item.html
@@ -0,0 +1 @@
+{{ instance.html|safe }}