Mark Lavin avatar Mark Lavin committed 12c2460

Test cases for new template tags.

Comments (0)

Files changed (2)

selectable/tests/__init__.py

 from selectable.tests.fields import *
 from selectable.tests.functests import *
 from selectable.tests.forms import *
+from selectable.tests.templatetags import *
 from selectable.tests.views import *
 from selectable.tests.widgets import *

selectable/tests/templatetags.py

+from django.template import Template, Context
+
+from selectable.tests.base import BaseSelectableTestCase
+
+__all__ = (
+    'JqueryTagTestCase',
+    'ThemeTagTestCase',
+)
+
+
+class JqueryTagTestCase(BaseSelectableTestCase):
+
+    def assertJQueryVersion(self, result, version):
+        expected = "//ajax.googleapis.com/ajax/libs/jquery/%s/jquery.min.js" % version
+        self.assertTrue(expected in result)
+
+    def assertUIVersion(self, result, version):
+        expected = "//ajax.googleapis.com/ajax/libs/jqueryui/%s/jquery-ui.js" % version
+        self.assertTrue(expected in result)
+
+    def test_render(self):
+        "Render template tag with default versions."
+        template = Template("{% load selectable_tags %}{% include_jquery_libs %}")
+        context = Context({})
+        result = template.render(context)
+        self.assertJQueryVersion(result, '1.7.2')
+        self.assertUIVersion(result, '1.8.18')
+
+    def test_render_jquery_version(self):
+        "Render template tag with specified jQuery version."
+        template = Template("{% load selectable_tags %}{% include_jquery_libs '1.4.3' %}")
+        context = Context({})
+        result = template.render(context)
+        self.assertJQueryVersion(result, '1.4.3')
+
+    def test_render_variable_jquery_version(self):
+        "Render using jQuery version from the template context."
+        version = '1.4.3'
+        template = Template("{% load selectable_tags %}{% include_jquery_libs version %}")
+        context = Context({'version': version})
+        result = template.render(context)
+        self.assertJQueryVersion(result, '1.4.3')
+
+    def test_render_jquery_ui_version(self):
+        "Render template tag with specified jQuery UI version."
+        template = Template("{% load selectable_tags %}{% include_jquery_libs '1.4.3' '1.8.13' %}")
+        context = Context({})
+        result = template.render(context)
+        self.assertUIVersion(result, '1.8.13')
+
+    def test_render_variable_jquery_ui_version(self):
+        "Render using jQuery UI version from the template context."
+        version = '1.8.13'
+        template = Template("{% load selectable_tags %}{% include_jquery_libs '1.4.3' version %}")
+        context = Context({'version': version})
+        result = template.render(context)
+        self.assertUIVersion(result, '1.8.13')
+
+    def test_render_no_jquery(self):
+        "Render template tag without jQuery."
+        template = Template("{% load selectable_tags %}{% include_jquery_libs '' %}")
+        context = Context({})
+        result = template.render(context)
+        self.assertTrue('jquery.min.js' not in result)
+
+    def test_render_no_jquery_ui(self):
+        "Render template tag without jQuery UI."
+        template = Template("{% load selectable_tags %}{% include_jquery_libs '1.7.2' '' %}")
+        context = Context({})
+        result = template.render(context)
+        self.assertTrue('jquery-ui.js' not in result)
+
+
+class ThemeTagTestCase(BaseSelectableTestCase):
+
+    def assertUICSS(self, result, theme, version):
+        expected = "//ajax.googleapis.com/ajax/libs/jqueryui/%s/themes/%s/jquery-ui.css" % (version, theme)
+        self.assertTrue(expected in result)
+
+    def test_render(self):
+        "Render template tag with default settings."
+        template = Template("{% load selectable_tags %}{% include_ui_theme %}")
+        context = Context({})
+        result = template.render(context)
+        self.assertUICSS(result, 'base', '1.8.18')
+
+    def test_render_version(self):
+        "Render template tag with alternate version."
+        template = Template("{% load selectable_tags %}{% include_ui_theme 'base' '1.8.13' %}")
+        context = Context({})
+        result = template.render(context)
+        self.assertUICSS(result, 'base', '1.8.13')
+        
+    def test_variable_version(self):
+        "Render using version from content variable."
+        version = '1.8.13'
+        template = Template("{% load selectable_tags %}{% include_ui_theme 'base' version %}")
+        context = Context({'version': version})
+        result = template.render(context)
+        self.assertUICSS(result, 'base', version)
+
+    def test_render_theme(self):
+        "Render template tag with alternate theme."
+        template = Template("{% load selectable_tags %}{% include_ui_theme 'ui-lightness' %}")
+        context = Context({})
+        result = template.render(context)
+        self.assertUICSS(result, 'ui-lightness', '1.8.18')
+        
+    def test_variable_theme(self):
+        "Render using theme from content variable."
+        theme = 'ui-lightness'
+        template = Template("{% load selectable_tags %}{% include_ui_theme theme %}")
+        context = Context({'theme': theme})
+        result = template.render(context)
+        self.assertUICSS(result, theme, '1.8.18')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.